DimensionReduction[{example1,example2,…}]
生成从 examplei 定义的空间投影到低维近似流形的 DimensionReducerFunction[…].
DimensionReduction[examples,n]
对 n 维近似流形生成 DimensionReducerFunction[…].
DimensionReduction[examples,n,props]
生成维数降低的指定属性.
DimensionReduction
DimensionReduction[{example1,example2,…}]
生成从 examplei 定义的空间投影到低维近似流形的 DimensionReducerFunction[…].
DimensionReduction[examples,n]
对 n 维近似流形生成 DimensionReducerFunction[…].
DimensionReduction[examples,n,props]
生成维数降低的指定属性.
更多信息和选项
- DimensionReduction 可用于许多数据类型,包括数值、文本、声音和图像以及它们的组合.
- DimensionReduction[examples] 生成 DimensionReducerFunction[…] ,可应用于数据以执行降维.
- 每个 examplei 可以是单个数据元素、数据元素列表、数据元素关联或 Dataset 对象.
- DimensionReduction[examples] 自动选择与目标近似流形相应的维度.
- DimensionReduction[examples] 等价于 DimensionReduction[examples,Automatic].
- 在 DimensionReduction[…,props] 中,props 可以是单一属性或者是属性列表. 可能的属性包括:
-
"ReducerFunction" DimensionReducerFunction[…] (默认) "ReducedVectors" 通过把 examplei 降维获得的向量 "ReconstructedData" 降维和反演后重建 examples "ImputedData" 用插补值替换 examples 中的缺失值 - 可以给出以下选项:
-
FeatureExtractor Identity 怎样提取要学习的特征 FeatureNames Automatic 分配给 examplei 的元素的名称 FeatureTypes Automatic 假设 examplei 的元素的特征类型 Method Automatic 要使用哪种降维算法 PerformanceGoal Automatic 优化的性能方面 RandomSeeding 1234 内部应怎样对伪随机数字生成器进行播种 TargetDevice "CPU" 执行培训的目标设备 - PerformanceGoal 的可能设置包括:
-
"Memory" 降维函数的存储要求最小化 "Quality" 降维质量最大化 "Speed" 降维速度最大化 "TrainingSpeed" 生成降维器所用时间最小化 - PerformanceGoal{goal1,goal2,…} 将自动合并 goal1、goal2 等.
- Method 的可能设置包括:
-
Automatic 自动选择方法 "Autoencoder" 使用可训练的自动编码器 "Hadamard" 用 Hadamard 矩阵对数据进行投影 "Isomap" 等距映射 "LatentSemanticAnalysis" 潜在语义分析方法 "Linear" 自动选择最佳的线性方法 "LLE" 局部线性嵌入 "MultidimensionalScaling" 度量多维尺度分析 (metric multidimensional scaling) "PrincipalComponentsAnalysis" 主成分分析方法 "TSNE"
-分布随机领域嵌入算法"UMAP" 统一流形逼近与投影 (uniform manifold approximation and projection) - RandomSeeding 的可能设置包括:
-
Automatic 每次调用函数时都自动重新播种 Inherited 使用外部播种的随机数字 seed 明确指定整数或字符串作为种子 - DimensionReduction[…,FeatureExtractor"Minimal"] 表明内部预处理应尽量简单.
- DimensionReduction[DimensionReducerFunction[…],FeatureExtractorfe] 可用于预置 FeatureExtractorFunction[…] fe 于已存在的特征提取器.
范例
打开所有单元 关闭所有单元基本范例 (3)
dr = DimensionReduction[{{1, 2, 3}, {2, 3, 5}, {3, 5, 8}, {4, 5, 8.5}}]dr[{6, 7, 14}]dr[{{6, 7, 14}, {5, 6, 11}, {1, 3, Missing[]}}]vectors = {{1, 2, 3}, {2, 3, 5}, {3, 5, 8}, {4, Missing[], 8.5}};dr = DimensionReduction[vectors, 1]dr[vectors]DimensionReduction[vectors, 1, {"ReducerFunction", "ReducedVectors"}]dr = DimensionReduction[{{1.4, "A"}, {1.5, "A"}, {2.3, "B"}, {5.4, "B"}}]dr[{2.4, "A"}]范围 (7)
vectors = Join[RandomReal[{0, 3}, {1000, 3}], RandomReal[{2, 5}, {1000, 3}], RandomReal[{4, 7}, {1000, 3}] ];ListPointPlot3D[vectors]dr = DimensionReduction[vectors, 2]dr[{0.3, 0.2, 0.4}]reduced = dr[vectors];ListPlot[reduced]reconstructed = dr[reduced, "OriginalVectors"];ListPointPlot3D[{vectors, reconstructed}]reconstructed = dr[vectors, "ReconstructedVectors"];ListPointPlot3D[{vectors, reconstructed}]dr = DimensionReduction[{{1, 2, 3}, {2, 3, 5}, {3, 5, 8}, {4, 5, 8.5}}]newvectors = {{6, 7, Missing[]}, {5, Missing[], 11}};dr[newvectors, "ImputedVectors"]dr = DimensionReduction[{[image], [image], [image] , [image], [image], [image]}, 5]dr[{[image], [image], [image] , [image], [image], [image]}]dr = DimensionReduction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}]dr[{"it is not a cat", "what a nice dog", "here is a dog again"}]对 DateObject 列表培训降维器:
dr = DimensionReduction[{DateObject[{2014, 5, 5, 9, 53, 6.30158}, "Instant", "Gregorian", -6.], DateObject[{2000, 1, 1, 0, 0, 0.}, "Instant", "Gregorian", -6.], DateObject[{2006, 12}, "Month", "Gregorian", -6.], DateObject[{2007, 8, 23}, "Day", "Gregorian", -6.], DateObject[{2016, 4, 4, 15, 59, 18.2738}, "Instant", "Gregorian", -4.]}]减少新的 DateObject 的维数:
dr[DateObject[{2003, 1, 2}, "Day", "Gregorian", -6.]]dr["2nd of January 2003"]dr = DimensionReduction[{{"the cat is grey", [image]}, {"my cat is fast", [image]}, {"this dog is scary", [image]}, {"the big dog", [image]}}]dr[{"the nice cat", [image]}]dr = DimensionReduction[{<|"age" -> 32, "height" -> 160, "gender" -> "female"|>,
<|"height" -> 183, "age" -> 41, "gender" -> "female"|>,
<|"height" -> 123, "age" -> 30, "gender" -> "female"|>,
<|"height" -> 175, "age" -> 21, "gender" -> "male"|>,
<|"height" -> 150, "age" -> 11, "gender" -> "male"|>,
<|"age" -> 52, "height" -> 164, "gender" -> "female"|>}]dr[<|"age" -> 19, "height" -> 176, "gender" -> "male"|>]选项 (7)
FeatureExtractor (1)
dr = DimensionReduction[{"The cat is grey.", "My cat is fast.", "This dog is scary." , "The big dog."}, FeatureExtractor -> {ToUpperCase, RemoveDiacritics, "SegmentedWords"}]dr[{"Nice CAT", "nice cat", "WhaT A Dög", "what a dog" }]FeatureNames (1)
dr = DimensionReduction[{{2.3, "male"}, {4.8, Missing[]}, {Missing[], "female"}, {5.2, "female"}}, FeatureNames -> {"age", "gender"}]dr[<|"age" -> 3.3, "gender" -> "male"|>]dr[{3.3, "male"}]FeatureTypes (1)
dr = DimensionReduction[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}]第一个特征被解释为数值. 使用 FeatureTypes 加强第一个特征解释为标称值:
dr = DimensionReduction[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}, FeatureTypes -> <|1 -> "Nominal"|>]dr[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}] // MatrixFormMethod (3)
使用 t-SNE 方法对 Fisher 虹膜数据集的特征产生一个降维函数:
iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];diris = DimensionReduction[iris[[All, 1]], 2, Method -> "TSNE"]byspecies = GroupBy[iris, Last -> First];byspecies = diris /@ byspecies;ListPlot[Values[byspecies], PlotLegends -> Keys[byspecies]]diris = DimensionReduction[iris[[All, 1]], 2, Method -> {"TSNE", "Perplexity" -> 100}]byspecies = GroupBy[iris, Last -> First];
byspecies = diris /@ byspecies;
ListPlot[Values[byspecies], PlotLegends -> Keys[byspecies]]fmnist = {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]};
reduced = DimensionReduce[fmnist, 2, Method -> "Autoencoder"];ListPlot[MapThread[Labeled[#1, #2]&, {reduced, fmnist}], ...]用随机噪声生成一个非线性数据流型,称之为 Swiss-roll 数据集:
m = 1000;
noise = 0.1;
aa = 1; bb = 4; t = (π/4) + (1 + 2 * RandomReal[aa, m]);
h = 2 * RandomReal[aa, m];
data = Table[{t[[i]] * Cos[bb * t[[i]]] + noise * RandomReal[aa], h[[i]],
t[[i]] * Sin[bb * t[[i]]] + noise * RandomReal[aa]}, {i, m}];ListPointPlot3D[data, BoxRatios -> {1, 1, 1}, PlotStyle -> Directive[PointSize -> Large] ]drI = DimensionReduction[data, Method -> "Isomap"]pts = drI[data];
ListPlot[pts, PlotStyle -> Directive[PointSize -> Small]]drL = DimensionReduction[data, Method -> "LLE"]pts = drL[data];
ListPlot[pts, AspectRatio -> 1.3, PlotStyle -> Directive[PointSize -> Small]]TargetDevice (1)
使用在系统默认 GPU 上的完全连接的 "AutoEncoder" 培训约简函数并查看 AbsoluteTiming:
AbsoluteTiming[DimensionReduction[RandomReal[1, {10000, 10}], Method -> {"AutoEncoder", "NetworkType" -> "FullyConnected"}, TargetDevice -> "GPU"]]AbsoluteTiming[DimensionReduction[RandomReal[1, {10000, 10}], Method -> {"AutoEncoder", "NetworkType" -> "FullyConnected"}]]应用 (5)
数据集可视化 (1)
从 ExampleData 加载费雪鸢尾花卉数据集:
iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];ExampleData[{"MachineLearning", "FisherIris"}, "LongDescription"]RandomSample[iris, 5]diris = DimensionReduction[iris[[All, 1]], 2]byspecies = GroupBy[iris, Last -> First];byspecies = diris /@ byspecies;ListPlot[Values[byspecies], PlotLegends -> Keys[byspecies]]头部姿势估计 (1)
obj = ExampleData[{"Geometry3D", "Beethoven"}]产生一个带有随机视点的许多头的数据集,因而创建不同的头姿势:
cc = RandomPoint[Circle[{0, 0}, 0.8, {Pi, 2Pi}], 50];
pp = Flatten[Table[{cc[[i, 1]], cc[[i, 2]], j}, {i, 1, Length@cc}, {j, -0.8, 0.8, 0.2}], 1];
vp = RandomSample[pp, 60];
poses = Table[Show[obj, ViewPoint -> vp[[i]]], {i, 1, Length@vp}];
imgs = Table[Rasterize[poses[[i]], ImageResolution -> 10, Background -> None], {i, 1, Length@poses}];RandomSample[imgs, 6]redpts = DimensionReduce[imgs, 2, Method -> {"LLE", "NeighborsNumber" -> 8}];从 50×50 输入空间看可视化图像的二维表示,两条轴表示上下和前端的姿势:
Graphics[MapThread[Inset[#1, #2, {0, 0}, 0.55, Background -> None]&, {imgs, redpts}], ImageSize -> 500, ImagePadding -> 40, Frame -> True, FrameTicks -> None, AspectRatio -> 1]图像插补 (1)
从 ExampleData 加载 MNIST 数据集,并保留图像:
digits = ExampleData[{"MachineLearning", "MNIST"}, "TestData"][[All, 1]];RandomSample[digits, 10]digits = Flatten[ImageData[#]]& /@ RandomSample[digits];trainingset = digits[[ ;; 9000]];
testset = digits[[9001 ;; ]];Dimensions[trainingset]dr = DimensionReduction[trainingset, 50]vector = RandomChoice[testset];dr[vector]toimage = Image[Partition[#, 28], ImageSize -> Tiny] &;toimage /@ {vector, dr[vector, "ReconstructedVectors"]}用 Missing[] 替换向量的某些值,并可视化:
vectormissing = vector;
vectormissing[[309 ;; 364]] = Missing[];
imagemissing = toimage[Replace[vectormissing, _Missing -> .5, {1}]]imputedimage = toimage[dr[vectormissing, "ImputedVectors", PerformanceGoal -> "Quality"]]{toimage[vector], imagemissing, imputedimage}推荐系统 (1)
得到 SparseArray 形式的用户影评:
ratings = SparseArray[Uncompress["1:eJztW9FOwzAMzLpVSPwF/wMvfAJCoL7AQ/l/0XUSGTRJ7fM5zSpeqq3qUse+nM9O9vDy+fz2GkIYT9PlcRi/3u5/fQvnb3fT5WkYx+HjfXFj6KfPy7vH6fN8QUdYsWM4WcbW3xgO54G0vjk/6m0pEi+aW/j2ZZyowJODzzrm2y9zgfB0zOJpNlE6Qrd4txCkJoRr45KZKGppmqfSo1E4MO18+LEVPhSOTQuV1WcZKHUGPF18sDM+jGseJaDoWE6MYPhT1hpMuBrTkTzvpz2c1hrNtUSMN7oGt+d3aT5TLMUrUjHjqQ9MgYRoI0eMC3grLb9iNjMRuMP6p4WKwp/VGWJn9nGrI5ImnhHfh+sF0A6eULYg+qbmNNrhC8S+269tCgm47no0VVbpu8uavaS3qQas4eYg8y8tLdNxk5EVtMIC7rcU0DR73bOv4plr1bOFtQJSj2s0v6oYoej/FnOqxgsS7cHbT5D1a80cE6UhD79p0/em0YSVtLDvLqkhFTJnLayi9ync+edSMMrJzzTitdYxmiAl9lnyQuoqrofsizAd1IUcu2k6WyJM0fhxs72+n3jXAeVm66WAinbWMM5jJklSSzdV1bbCOBZamXDgkf122HtpSz3j9c9VGl7wPDNAo5hCYF33b5rpYa0pPlVYd98fzRNnhdjF6pWX3nagC6RhQ1uSwt9JtYqHMU41r7Cv2mAdXiGfSJkSFQ2b9urUeEfPLMkgZrcPZKjGNIxUo8jmVW3NOp4Pl8o8y37U5cc+2kb6WJSpUo0ARys2wnpk3qZDgsnR8H5eOn2o3g3FvrDN4HKjHb3GOydI0wLGnjX3/wBa32RKUwVr3HaewvmXGzuchwonBts6J7jRWRUeaul+ct7lIJ3VTyf7reqk2j2dbwG5Z0c="], Automatic, Missing[]]数据集由 100 个用户和 10 部影片组成. 评分范围从 1 到 5,并用 Missing[] 表示未知评分:
ratings[[ ;; 10, ;; 5]]//MatrixFormtraining = ratings[[ ;; 80]];
test = ratings[[81 ;; ]];dr = DimensionReduction[training, 3]newuser = RandomChoice[test]dr[newuser, "ImputedVectors"]图像搜索 (1)
dataset = {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]};dr = DimensionReduction[dataset, 10]在降维空间产生一个 NearestFunction:
nf = Nearest[dr[dataset] -> Automatic]使用 NearestFunction,构建显示数据集最近图像的函数:
nearestdog = dataset[[First@nf[dr[#]]]]&nearestdog[[image]]nearestdog[[image]]nearestdog[[image]]reduced = # -> dr[#]& /@ dataset;First /@ DeleteDuplicates[reduced, CosineDistance[#1[[2]], #2[[2]]] < 1 &]文本
Wolfram Research (2015),DimensionReduction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/DimensionReduction.html (更新于 2020 年).
CMS
Wolfram 语言. 2015. "DimensionReduction." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2020. https://reference.wolfram.com/language/ref/DimensionReduction.html.
APA
Wolfram 语言. (2015). DimensionReduction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/DimensionReduction.html 年
BibTeX
@misc{reference.wolfram_2026_dimensionreduction, author="Wolfram Research", title="{DimensionReduction}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/DimensionReduction.html}", note=[Accessed: 08-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_dimensionreduction, organization={Wolfram Research}, title={DimensionReduction}, year={2020}, url={https://reference.wolfram.com/language/ref/DimensionReduction.html}, note=[Accessed: 08-September-2026]}