FeatureExtraction[examples]
生成用给定样例训练的 FeatureExtractorFunction[…].
FeatureExtraction[examples,spec]
使用指定的特征提取方法 spec.
FeatureExtraction[examples,spec,props]
给出由 props 指定的特征提取属性.
FeatureExtraction
FeatureExtraction[examples]
生成用给定样例训练的 FeatureExtractorFunction[…].
FeatureExtraction[examples,spec]
使用指定的特征提取方法 spec.
FeatureExtraction[examples,spec,props]
给出由 props 指定的特征提取属性.
更多信息和选项
- FeatureExtraction 通常用于定义将原始数据处理为可用特征的函数(例如,用于训练机器学习算法).
- FeatureExtraction 可用于许多类型的数据,包括数字、文本、音频、图像、图和时间序列,以及这些类型的组合.
- examples 的可能值有:
-
{example1,…} 训练样例的列表 Dataset[…] Dataset 对象 Tabular[…] Tabular 对象 None 无训练样例 - 各 examplei 可以是单一数据元素、数据元素列表或者数据元素关联.
- spec 的可能值有:
-
extractor 使用指定的提取器方法 partextractor 对特定样例部分应用提取器 {part1extractor1,…} 为特定部分指定提取器 - 可能的特征提取器方法 extractor 包括:
-
Automatic 自动提取 Identity 给出无变化的数据 "ConformedData" 一致化的图像、颜色、日期等 "NumericVector" 来自任意数据的数值向量 "name" 命名提取器方法 f 对各个样例应用函数 f {extractor1,extractor2,…} 依次使用一系列提取器 - 可能的 part 形式有:
-
All 每个样例的所有部分 i 每个样例的第 i
个部分{i1,i2,…} 每个样例的第 i1、i2、… 个部分 "key" 每个样例中具有指定键的部分 {"key1","key2",…} 每个样例中名称为 "keyi" 的部分 - 当明确指定部分时,提取特征时将删除任何未提及的部分.
- FeatureExtraction[examples] 等价于 FeatureExtraction[examples,Automatic],而这通常又等价于 FeatureExtraction[examples,"NumericVector"].
- "NumericVector" 方法通常会将样例转换为数值向量,填补缺失数据,并使用 DimensionReduction 降低维度.
- 针对单一数据类型的特征提取器方法仅适用于与其类型兼容的数据元素. 其他数据元素将保持不变而返回.
- 当 examples 为 None 时,并非所有特定的特征提取器都可用.
- 具体的提取器是:
- 数值数据:
-
"DiscretizedVector" 离散化的数值数据 "DimensionReducedVector" 降维的数值向量 "MissingImputed" 缺失值被估算的数据 "StandardizedVector" 用 Standardize 处理过的数值数据 - 标称数据:
-
"IndicatorVector" 用指示向量“独热编码”的名义数据 "IntegerVector" 用整数编码的名义数据 - 文本:
-
"LowerCasedText" 每个字符均为小写的文本 "SegmentedCharacters" 分割成字符的文本 "SegmentedWords" 分割成单词的文本 "SentenceVector" 文字的语义向量 "TFIDF" 词频逆向文件频率向量 "WordVectors" 文字的语义向量序列(仅限英文) - 图像:
-
"FaceFeatures" 来自人脸图像的语义向量 "ImageFeatures" 图像的语义向量 "PixelVector" 图像像素值向量 - 音频对象:
-
"AudioFeatures" 音频对象的语义向量序列 "AudioFeatureVector" 音频对象的语义向量 "LPC" 音频线性预测系数 "MelSpectrogram" 用对数频次分组的音频频谱图 "MFCC" 音频梅尔频率倒谱系数向量序列 "SpeakerFeatures" 讲话者的语义向量序列 "SpeakerFeatureVector" 讲话者的语义向量 "Spectrogram" 音频频谱图 - 视频对象:
-
"VideoFeatures" 来自视频对象的语义向量序列 "VideoFeatureVector" 来自视频对象的语义向量 - 图:
-
"GraphFeatures" 总结图的属性的数值向量 - 分子:
-
"AtomPairs" 来自原子对的布尔向量以及它们之间的路径长度 "MoleculeExtendedConnectivity" 来自枚举的分子子图的布尔向量 "MoleculeFeatures" 概括分子属性的数值向量 "MoleculeTopologicalFeatures" 来自圆形原子邻域的布尔向量 - 在 FeatureExtraction[examples,extractors,props] 中,props 可以是单一属性或属性列表. 可能的属性包括:
-
"ExtractorFunction" FeatureExtractorFunction[…](默认) "ExtractedFeatures" 特征提取之后的 examples "ReconstructedData" 提取和逆提取之后的 examples "FeatureDistance" 从提取程序生成的 FeatureDistance[…] - 当样例为 None 时,"ExtractedFeatures" 和 "ReconstructedData" 属性不可用.
- 仅当每个指定的 extractor 都可逆时,才能计算 "ReconstructedData" 属性.
- 可以给出以下选项:
-
FeatureNames Automatic 赋给 examplei 的元素的名称 FeatureTypes Automatic 对 examplei 的元素要假定的特征类型 RandomSeeding 1234 应该在内部对伪随机数生成器进行什么样的初始化 - RandomSeeding 的可能设置包括:
-
Automatic 每次函数调用时自动重新播种 Inherited 使用外部播种的随机数字 seed 用明确给定的整数或字符串作为种子
提取器
属性
选项
范例
打开所有单元 关闭所有单元基本范例 (3)
在简单的数据集上训练 FeatureExtractorFunction:
fe = FeatureExtraction[{{1.4, "A"}, {1.5, "A"}, {2.3, "B"}, {5.4, "B"}}]fe[{2.4, "A"}]fe[{{2.4, "A"}, {3.7, "B"}}]fe = FeatureExtraction[{[image], [image], [image], [image], [image], [image]}]fe[{[image], [image], [image], [image], [image], [image]}]fe = FeatureExtraction[{[image], [image], [image], [image], [image], [image]}, "ImageFeatures"]范围 (32)
输入形状 (9)
fe = FeatureExtraction[{"It was the best of times.", "A journey of a thousand miles begins with a single step.", "To be or not to be, that is the question."}]fe["A rose by any other name"]fe[{"A rose by any other name", "It was the worst of times"}]fe = FeatureExtraction[{{"It was the best of times.", "Charles Dickens"}, {"A journey of a thousand miles begins with a single step.", "Laozi (attrib.)"}, {"To be or not to be, that is the question.", "William Shakespere"}}]fe[{{"All the world’s a stage, and all the men and women merely players", "William Shakespere"}, {"Knowing others is intelligence; knowing yourself is true wisdom", "Laozi (attrib.)"}}]fe = FeatureExtraction[{{"the cat is grey", [image]}, {"my cat is fast", [image]}, {"this dog is scary", [image]}, {"the big dog", [image]}}]fe[{"the nice cat", [image]}]fe = FeatureExtraction[{<|"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"|>}]fe[<|"age" -> 19, "height" -> 176, "gender" -> "male"|>]fe[{<|"age" -> 19, "height" -> 176, "gender" -> "male"|>, <|"age" -> 45, "height" -> 164, "gender" -> "female"|>}]FeatureExtraction[<|"age" -> {32, 41, 30, 21, 11, 52}, "height" -> {160, 183, 123, 175, 150, 164}, "gender" -> {"female", "female", "female", "male", "male", "female"}|>]从 Tabular 提取特征:
FeatureExtraction[Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["age" -> Association["ElementType" -> "Integer64"],
"height" -> Association["ElementType" -> "Integer64"],
"gender" -> Association["ElementType" -> "String"]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{32, 41, 30, 21, 11, 52}, {}, None},
"ElementType" -> "Integer64"]], TabularColumn[Association[
"Data" -> {{160, 183, 123, 175, 150, 164}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{3, {0, 6, 12, 18, 22, 26, 32},
"femalefemalefemalemalemalefemale"}, {}, None}, "ElementType" -> "String"]]}}]]]]]从 Dataset 提取特征:
FeatureExtraction[Dataset[{Association["age" -> 32, "height" -> 160, "gender" -> "female"],
Association["age" -> 41, "height" -> 183, "gender" -> "female"],
Association["age" -> 30, "height" -> 123, "gender" -> "female"],
Association["age" -> 21, "height" -> 175, "gender" -> "male"],
Association["age" -> 11, "height" -> 150, "gender" -> "male"],
Association["age" -> 52, "height" -> 164, "gender" -> "female"]}]]FeatureExtraction[{{1.4, Missing[], "A"}, {1.5, 50.2, "A"}, {Missing[], 42.3, "B"}, {5.4, 61.7, "B"}}]fe = FeatureExtraction[None, "WordVectors"]fe["hi there"]//Shallow提取器规范 (10)
在单个文本特征上指定特征提取器 "SentenceVector":
fe = FeatureExtraction[{"the lizard is green"}, "SentenceVector"]fe[{"there is a large cat"}]//Short使用 "StandardizedVector" 方法训练特征提取器:
fe = FeatureExtraction[{{1.4, 42.1}, {1.5, 50.2}, {4.2, 42.3}, {5.4, 61.7}}, "StandardizedVector"]features = fe[{6.4, 32.1}]由于此特征提取器是可逆的,因此可以使用 FeatureExtractorFunction 属性 "OriginalData" 来执行逆提取:
fe[features, "OriginalData"]使用 "TFIDF" 方法和 "DimensionReducedVector" 方法在文本上训练特征提取器:
fe = FeatureExtraction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}, {"TFIDF", "DimensionReducedVector"}]fe[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}]使用纯文本 "TFIDF" 方法在文本和图像上训练特征提取器:
fe = FeatureExtraction[{{"the cat is grey", [image]}, {"my cat is fast", [image]}, {"this dog is scary", [image]}, {"the big dog", [image]}}, "TFIDF"]fe[{"the nice cat", [image]}]fe = FeatureExtraction[{{"Glucose", Molecule["Glucose"]}, {"Water", Molecule["Water"]}, {"Acetic Acid", Molecule["Acetic Acid"]}}, {1 -> { "SentenceVector", "DimensionReducedVector"}, 2 -> "MoleculeFeatures"}]fe[{{"Sucrose", Molecule["Sucrose"]}}]fe[{"Hydrochloric Acid", Molecule["Hydrochloric Acid"]}]仅对第二个名义变量使用 "IndicatorVector" 方法训练特征提取器:
fe = FeatureExtraction[{{"Yes", "A"}, {"No", "A"}, {"No", "B"}, {"Maybe", "B"}, {"No", "C"}}, 2 -> "IndicatorVector"]Normal@fe[{"Yes", "A"}]使用 Identity 提取器方法复制第一个变量:
fe = FeatureExtraction[{{"Yes", "A"}, {"No", "A"}, {"No", "B"}, {"Maybe", "B"}, {"No", "C"}}, {2 -> "IndicatorVector", 1 -> Identity}]fe[{"Yes", "A"}]fe = FeatureExtraction[{{"Yes", "A"}, {"No", "A"}, {"No", "B"}, {"Maybe", "B"}, {"No", "C"}}, {2 -> "IndicatorVector", 1 -> "IndicatorVector", 1 -> Identity}]fe[{"Yes", "A"}]fe = FeatureExtraction[Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["Name" -> Association["ElementType" -> "String"],
"Molecule" -> Association["ElementType" -> "InertExpression"]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{3, {0, 7, 12, 23}, "GlucoseWaterAcetic Acid"}, {},
None}, "ElementType" -> "String"]], TabularColumn[
Association["Data" -> {{Molecule[{"O", "C", "C", "O", "C", "O", "C", "O", "C", "O", "C",
"O", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"},
{Bond[{1, 2}, "Double"], Bond[{2, 3}, "Single"], Bond[{3, 4}, "Single"], Bond[{3, 5},
"Single"], Bond[{5, 6}, "Single"], Bond[{5, 7}, "Single"], Bond[{7, 8}, "Single"],
Bond[{7, 9}, "Single"], Bond[{9, 10}, "Single"], Bond[{9, 11}, "Single"], Bond[
{11, 12}, "Single"], Bond[{2, 13}, "Single"], Bond[{3, 14}, "Single"], Bond[
{4, 15}, "Single"], Bond[{5, 16}, "Single"], Bond[{6, 17}, "Single"], Bond[{7, 18},
"Single"], Bond[{8, 19}, "Single"], Bond[{9, 20}, "Single"], Bond[{10, 21},
"Single"], Bond[{11, 22}, "Single"], Bond[{11, 23}, "Single"], Bond[{12, 24},
"Single"]}, {StereochemistryElements -> {Association["StereoType" -> "Tetrahedral",
"ChiralCenter" -> 3, "Direction" -> "Counterclockwise"], Association[
"StereoType" -> "Tetrahedral", "ChiralCenter" -> 5, "Direction" -> "Clockwise"],
Association["StereoType" -> "Tetrahedral", "ChiralCenter" -> 7, "Direction" ->
"Counterclockwise"], Association["StereoType" -> "Tetrahedral",
"ChiralCenter" -> 9, "Direction" -> "Counterclockwise"]}}],
Molecule[{"O", "H", "H"}, {Bond[{1, 2}, "Single"], Bond[{1, 3}, "Single"]}, {}],
Molecule[{"C", "C", "O", "O", "H", "H", "H", "H"}, {Bond[{1, 2}, "Single"], Bond[
{2, 3}, "Double"], Bond[{2, 4}, "Single"], Bond[{1, 5}, "Single"], Bond[{1, 6},
"Single"], Bond[{1, 7}, "Single"], Bond[{4, 8}, "Single"]}, {}]}, {}, None},
"ElementType" -> "InertExpression", "CachedOriginalExpression" ->
{Molecule[{"O", "C", "C", "O", "C", "O", "C", "O", "C", "O", "C", "O", "H", "H", "H",
"H", "H", "H", "H", "H", "H", "H", "H", "H"}, {Bond[{1, 2}, "Double"],
Bond[{2, 3}, "Single"], Bond[{3, 4}, "Single"], Bond[{3, 5}, "Single"],
Bond[{5, 6}, "Single"], Bond[{5, 7}, "Single"], Bond[{7, 8}, "Single"],
Bond[{7, 9}, "Single"], Bond[{9, 10}, "Single"], Bond[{9, 11}, "Single"],
Bond[{11, 12}, "Single"], Bond[{2, 13}, "Single"], Bond[{3, 14}, "Single"],
Bond[{4, 15}, "Single"], Bond[{5, 16}, "Single"], Bond[{6, 17}, "Single"],
Bond[{7, 18}, "Single"], Bond[{8, 19}, "Single"], Bond[{9, 20}, "Single"],
Bond[{10, 21}, "Single"], Bond[{11, 22}, "Single"], Bond[{11, 23}, "Single"],
Bond[{12, 24}, "Single"]}, {StereochemistryElements -> {Association["StereoType" ->
"Tetrahedral", "ChiralCenter" -> 3, "Direction" -> "Counterclockwise"],
Association["StereoType" -> "Tetrahedral", "ChiralCenter" -> 5, "Direction" ->
"Clockwise"], Association["StereoType" -> "Tetrahedral", "ChiralCenter" -> 7,
"Direction" -> "Counterclockwise"], Association["StereoType" -> "Tetrahedral",
"ChiralCenter" -> 9, "Direction" -> "Counterclockwise"]}}],
Molecule[{"O", "H", "H"}, {Bond[{1, 2}, "Single"], Bond[{1, 3}, "Single"]}, {}],
Molecule[{"C", "C", "O", "O", "H", "H", "H", "H"}, {Bond[{1, 2}, "Single"],
Bond[{2, 3}, "Double"], Bond[{2, 4}, "Single"], Bond[{1, 5}, "Single"],
Bond[{1, 6}, "Single"], Bond[{1, 7}, "Single"], Bond[{4, 8}, "Single"]}, {}]}]]}}]]]], {"Name" -> { "SentenceVector", "DimensionReducedVector"}, "Molecule" -> "MoleculeFeatures"}]fe[<|"Name" -> "Hydrochloric Acid", "Molecule" -> Molecule["Hydrochloric Acid"]|>]在列表上使用特征提取器将假定特征的顺序与最初指定的顺序相同:
fe[{"Hydrochloric Acid", Molecule["Hydrochloric Acid"]}]data = {DateObject[{2014, 5, 5}, TimeObject[{9, 53, 6.30158}, TimeZone -> -5.], TimeZone -> -5.], DateObject[{2000, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -5.], TimeZone -> -5.], DateObject[{2006, 12}], DateObject[{2007, 8, 23}], DateObject[{2016, 4, 4}, TimeObject[{15, 59, 18.2738}, TimeZone -> -4.], TimeZone -> -4.]};fe = FeatureExtraction[data, {AbsoluteTime[#], #["Year"]}&]fe[data]将自定义提取器与 "StandardizedVector" 方法链接起来:
fe2 = FeatureExtraction[data, {{AbsoluteTime[#], #["Year"]}&, "StandardizedVector"}]fe2[data]FeatureExtraction[{[image], [image], [image], [image]}, {"ConformedData", "ImageFeatures"}]FeatureExtraction[{[image], [image], [image], [image]}, {"ImageFeatures", "DimensionReducedVector"}]特征类型 (10)
使用无需训练的 "SentenceVector" 提取器为文本数据创建特征提取器:
fe = FeatureExtraction[None, "SentenceVector"]输入类型是从指定的提取器推断出来的. 使用特征提取器来处理以下样例:
fe[{"it is not a cat", "what a nice dog", "here is a dog again"}]//Shortfe = FeatureExtraction[None, {1 -> "SentenceVector", 2 -> "ImageFeatures"}]fe[{"the nice cat", [image]}]//ShortFeatureExtraction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}]使用 "IndicatorVector" 方法在名义变量上训练特征提取器:
FeatureExtraction[{{"Yes", "A"}, {"No", "A"}, {"No", "B"}, {"Maybe", "B"}, {"No", "C"}}, "IndicatorVector"]fe = FeatureExtraction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}, "TFIDF"]训练集的词频逆向文件频率矩阵可以在 SparseArray 中计算:
matrix = fe[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}]matrix//MatrixPlotFeatureExtraction[{{"the", "cat", "is", "grey"}, {"my" , "cat", "is", "fast"}, {"this", "dog", "is", "scary"}, {"the", "big", "dog"}}, "TFIDF", "ExtractedFeatures"]在 DateObject 实例列表上训练特征提取器:
fe = FeatureExtraction[{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 中提取特征:
fe[DateObject[{2003, 1, 2}, "Day", "Gregorian", -6.]]fe["2nd of January 2003"]在 Graph 实例列表上训练特征提取器:
fe = FeatureExtraction[{[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}]fe[[image]]在 TimeSeries 实例列表上训练特征提取器:
FeatureExtraction[{TemporalData[TimeSeries, {{{0, 1, 0, 3, 0, 0, 0, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
0, 0, 0, 0, 0, 2, 0, 0, 36, 0, 6, 1, 2, 8, 6, 24, 20, 31, 68, 45, 140, 116, 65, 376, 322, 382,
516, 544, 767, 1133, 1788, 1360, 5886, 5412 ... tion[{2020, 1, 23, 0, 0, 0.}, {2020, 10, 5, 0, 0, 0.}, {1, "Day"}]},
1, {"Continuous", 1}, {"Discrete", 1}, 1, {DateFunction -> Automatic,
ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True,
12.2], TemporalData[TimeSeries, {{{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 23, 2, 1, 3, 5, 4, 13, 6, 11, 9, 20, 11, 6,
23, 14, 38, 50, 86, 66, 103, 37, 121, 70, 1 ... {TemporalData`DateSpecification[{2020, 1, 23, 0, 0, 0.}, {2020, 10, 5, 0, 0, 0.}, {1, "Day"}]},
1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True,
12.2], TemporalData[TimeSeries, {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 2, 0, 9, 0, 7, 5, 6, 7, 14, 99, 0, 11, 38,
121, 51, 249, 172, 228, 572, 331, 323, 307, ... TemporalData`DateSpecification[{2020, 1, 23, 0, 0, 0.},
{2020, 10, 5, 0, 0, 0.}, {1, "Day"}]}, 1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True,
12.2], TemporalData[TimeSeries, {{{0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 9, 0, 4, 0, 3, 0, 8, 17, 14, 4, 27,
24, 33, 52, 54, 53, 61, 71, 57, 163, 182, 196 ... {TemporalData`DateSpecification[{2020, 1, 23, 0, 0, 0.}, {2020, 10, 5, 0, 0, 0.}, {1, "Day"}]},
1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True,
12.2], TemporalData[TimeSeries, {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 6, 0, 4, 9, 12, 20, 11,
28, 9, 26, 68, 35, 46, 101, 92, 21, 48, 69 ... {TemporalData`DateSpecification[{2020, 1, 23, 0, 0, 0.}, {2020, 10, 5, 0, 0, 0.}, {1, "Day"}]},
1, {"Continuous", 1}, {"Discrete", 1}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True,
12.2]}]在 Molecule 数据上训练特征提取器:
FeatureExtraction[{Molecule["Sucrose"], Molecule["Pentane"]}]在 Audio 实例列表上训练特征提取器:
FeatureExtraction[{Audio[Sound[Table[SoundNote[i, If[i == 12, 0.5, 0.1], "Violin"], {i, 0, 12}]]], Audio[Sound[Table[SoundNote[i, If[i == 12, 0.5, 0.1], "Trumpet"], {i, 0, 12}]]]}]信息 (3)
从经过训练的 FeatureExtractorFunction 获取 Information:
Information[FeatureExtractorFunction[Association["ExampleNumber" -> 4,
"Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["age" -> Association["Type" -> "Numerical"],
"gender" -> Association["Type" - ... ate" -> DateObject[{2025, 5, 2, 13, 0,
39.042795`8.344115878952366}, "Instant", "Gregorian", 2.], "ProcessorCount" -> 10,
"ProcessorType" -> "ARM64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]]]Information[FeatureExtractorFunction[Association["ExampleNumber" -> 4,
"Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["age" -> Association["Type" -> "Numerical"],
"gender" -> Association["Type" - ... ate" -> DateObject[{2025, 5, 2, 13, 0,
39.042795`8.344115878952366}, "Instant", "Gregorian", 2.], "ProcessorCount" -> 10,
"ProcessorType" -> "ARM64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], "Properties"]Information[FeatureExtractorFunction[Association["ExampleNumber" -> 4,
"Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["age" -> Association["Type" -> "Numerical"],
"gender" -> Association["Type" - ... ate" -> DateObject[{2025, 5, 2, 13, 0,
39.042795`8.344115878952366}, "Instant", "Gregorian", 2.], "ProcessorCount" -> 10,
"ProcessorType" -> "ARM64", "OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64,
"Evaluations" -> {}]]], {"InputTypes", "OutputTypes"}]选项 (4)
FeatureNames (2)
fe = FeatureExtraction[{{2.3, "male"}, {4.8, Missing[]}, {Missing[], "female"}, {5.2, "female"}}, FeatureNames -> {"age", "gender"}]fe[<|"age" -> 3.3, "gender" -> "male"|>]fe[{3.3, "male"}]使用 FeatureNames 设置名称,并在 FeatureExtraction[examples,{spec1ext1,…}] 中引用它们:
fe = FeatureExtraction[{{"A", "female"}, {"B", "female"}, {"C", "male"}, {"B", "male"}}, {"class" -> Identity, "gender" -> "IndicatorVector"}, FeatureNames -> {"class", "gender"}]fe[<|"gender" -> "female", "class" -> "B"|>]FeatureTypes (2)
在简单数据集上通过 "IndicatorVector" 训练特征提取程序:
fe = FeatureExtraction[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}, "IndicatorVector"]第一个特征被解释为数值型. 由于 "IndicatorVector" 方法仅作用于名义特征,第一个特征不变:
使用 FeatureTypes 执行作为名义的第一个特征的诠释:
fe = FeatureExtraction[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}, "IndicatorVector", FeatureTypes -> <|1 -> "Numerical"|>]第一个特征被诠释为数值型,由于 "IndicatorVector" 方法仅作用于名义特征,第一个特征不变化.
fe[{{1, "A"}, {2, "A"}, {2, "B"}, {1, "B"}}]创建无需训练的特征提取器可以从特定的提取器推断出预期的数据类型:
fe = FeatureExtraction[None, "SentenceVector"]fe2 = FeatureExtraction[None, "SentenceVector", FeatureTypes -> {"first" -> "Numerical", "second" -> "Text"}]fe2[<|"first" -> 1, "second" -> "Good morning!"|>]//Short应用 (3)
图像搜索 (1)
dataset = {[image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image], [image]};fe = FeatureExtraction[dataset]生成关于数据集的提取特征的 NearestFunction:
nf = Nearest[fe[dataset] -> Automatic]使用 NearestFunction,构建一个函数,显示数据集的最相近图像:
nearestdog = dataset[[First@nf[fe[#]]]]&nearestdog[[image]]nearestdog[[image]]nearestdog[[image]]features = # -> fe[#]& /@ dataset;First /@ DeleteDuplicates[features, CosineDistance[#1[[2]], #2[[2]]] < 1 &]文本搜索 (1)
alice = ExampleData[{"Text", "AliceInWonderland"}];sentences = TextSentences[alice];fe = FeatureExtraction[sentences]生成带有单句特征的 NearestFunction:
nf = Nearest[fe[sentences] -> Automatic]使用 NearestFunction,构建一个函数,显示 Alice in Wonderland 中最相近的单句:
nearestalice = sentences[[First@nf[fe[#]]]]&nearestalice["Alice and the Rabbit"]nearestalice["The cat and the Queen"]nearestalice["Off her head"]估算 (1)
从 ExampleData 中加载 "MNIST" 数据集,并保留图像:
digits = First /@ ExampleData[{"MachineLearning", "MNIST"}, "TestData"];RandomSample[digits, 10]digits = Flatten[ImageData[#]]& /@ RandomSample[digits];trainingset = digits[[ ;; 9000]];
testset = digits[[9001 ;; ]];Dimensions[trainingset]使用 "MissingImputed" 方法创建特征提取程序:
fe = FeatureExtraction[trainingset, "MissingImputed"]用 Missing[] 替换测试集向量的某些值,并可视化:
vector = RandomChoice[testset];toimage = Image[Partition[#, 28], ImageSize -> Tiny] &;vectormissing = vector;
vectormissing[[309 ;; 364]] = Missing[];
imagemissing = toimage[Replace[vectormissing, _Missing -> .5, {1}]]使用 FeatureExtractorFunction[…] 估算缺失值:
imputedimage = toimage[fe[vectormissing]]{toimage[vector], imagemissing, imputedimage}属性和关系 (4)
fe = FeatureExtraction[<|"age" -> {32, 41, 30, 21, 11, 52}, "height" -> {160, 183, 123, 175, 150, 164}, "gender" -> {"female", "female", "female", "male", "male", "female"}|>]fe[<|"age" -> 19, "height" -> 176, "gender" -> "male"|>]fe[<|"age" -> 19, "height" -> 176, "gender" -> "male", "weight" -> 32|>]FeatureExtraction[…,"ExtractedFeatures"] 等价于 FeatureExtract[…]:
data = {"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"};FeatureExtraction[data, "TFIDF", "ExtractedFeatures"] == FeatureExtract[data, "TFIDF"]"FeatureDistance" 属性相当于在提取器上使用 FeatureDistance:
fd1 = FeatureExtraction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}, "TFIDF", "FeatureDistance"]首先计算 FeatureExtractorFunction:
fe = FeatureExtraction[{"the cat is grey", "my cat is fast", "this dog is scary", "the big dog"}, "TFIDF"]fd2 = FeatureDistance[fe]fd1["the cat is grey", "the big dog"]fd2["the cat is grey", "the big dog"]在一些训练数据上创建 FeatureExtractorFunction 会创建一个表示这些特征的特征空间:
fe = FeatureExtraction[{Molecule["Glucose"], Molecule["Sucrose"]}]molecules = Molecule /@ EntityList[EntityClass["Chemical", "AminoAcids"]];
fe2 = FeatureExtraction[molecules]fe[Molecule["Water"]] === fe2[Molecule["Water"]]在无数据的情况下创建相同的函数,将导致一个未经训练的函数,该函数在相同的特征空间中始终给出相同的结果:
fe3 = FeatureExtraction[None, "MoleculeFeatures"]可能存在的问题 (7)
feAutomatic = FeatureExtraction[{"C", "B", "C", "B", "A", "B", "B", "A", "B", "B", "A", "A"}, "IndicatorVector"]Information[feAutomatic, "FeatureNames"]feAutomatic[<|"Letter" -> "S"|>]feNamed = FeatureExtraction[{"C", "B", "C", "B", "A", "B", "B", "A", "B", "B", "A", "A"}, "IndicatorVector", FeatureNames -> "Letter"]检查 FeatureExtractorFunction 的特征名称:
Information[feNamed, "FeatureNames"]feNamed[<|"Letter" -> "S"|>]FeatureExtraction 属性 "ReconstructedData" 可用于获取提取和重建后的数据:
FeatureExtraction[{{1.4, 1.4, 5.4, 5.2}, {1.5, 1.5, 6.4, 5.2}, {1.2, 1.2, 6.2, 5.2}, {1.6, 1.6, 4.3, 5.2}}, "DimensionReducedVector", "ReconstructedData"]fe = FeatureExtraction[{{1.4, 1.4, 5.4, 5.2}, {1.5, 1.5, 6.4, 5.2}, {1.2, 1.2, 6.2, 5.2}, {1.6, 1.6, 4.3, 5.2}}, "DiscretizedVector", "ReconstructedData"]FeatureExtraction[{[image], [image], [image], [image]}, "ImageFeatures", "ReconstructedData"]如果没有训练数据,则无法使用属性 "ReconstructedData":
FeatureExtraction[None, "DimensionReducedVector", "ReconstructedData"]FeatureExtraction[None, "LowerCasedText"]FeatureExtraction[None, "StandardizedVector"]FeatureExtraction[None, "LowerCasedText", "FeatureDistance"]fe = FeatureExtraction[{"No", "No", "no", "no", "no", "no", "yes", "no", "Yes", "Yes"}, {"LowerCasedText", "IndicatorVector"}]类似地,强制输入 "Text" 将导致 "IndicatorVector" 被忽略:
fe["Yes"] == fe["yes"]输入类型为 "Nominal",因此 "LowerCasedText" 提取器忽略输入类型:
fe = FeatureExtraction[{"No", "No", "no", "no", "no", "no", "yes", "no", "Yes", "Yes"}, {"LowerCasedText", "IndicatorVector"}, FeatureTypes -> "Text"]fe["Yes"]"ConformedData" 提取器需要额外的信息才能在无数据环境中运行:
FeatureExtraction[None, "ConformedData"]明确指定 FeatureTypes:
FeatureExtraction[None, "ConformedData", FeatureTypes -> "Image"]FeatureExtraction[None, {"ConformedData", "ImageFeatures"}]fe = FeatureExtraction[{"rhinos have horns", "deer have antlers", "fish have scales"}]fe = FeatureExtraction[{"rhinos have horns", "deer have antlers", "fish have scales"}, "SentenceVector"]使用 "DimensionReducedVector" 添加降维步骤:
fe = FeatureExtraction[{"rhinos have horns", "deer have antlers", "fish have scales"}, {"SentenceVector", "DimensionReducedVector"}]降维必须针对可用特征进行训练,因此在没有提供数据时无法应用:
fe = FeatureExtraction[None, {"SentenceVector", "DimensionReducedVector"}]用已命名的特征创建一个FeatureExtractorFunction :
fe = FeatureExtraction[None, {"Name" -> "LowerCasedText", "Molecule" -> "MoleculeFeatures"}]fe[{"Name" -> "Amoxicillin", "Molecule" -> Molecule["Amoxicillin"]}]fe[<|"Name" -> "Amoxicillin", "Molecule" -> Molecule["Amoxicillin"]|>]//Shortresponse = {"No", "No", "no", "no", "no", "no", "yes", "no", "Yes", "Yes"};
fe = FeatureExtraction[response, "LowerCasedText"]fe = FeatureExtraction[response, {"LowerCasedText", "IndicatorVector"}]fe1 = FeatureExtraction[response, "LowerCasedText"]
fe2 = FeatureExtraction[fe1[response], "IndicatorVector"]fe2[fe1["No"]]文本
Wolfram Research (2016),FeatureExtraction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/FeatureExtraction.html (更新于 2025 年).
CMS
Wolfram 语言. 2016. "FeatureExtraction." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/FeatureExtraction.html.
APA
Wolfram 语言. (2016). FeatureExtraction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/FeatureExtraction.html 年
BibTeX
@misc{reference.wolfram_2026_featureextraction, author="Wolfram Research", title="{FeatureExtraction}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/FeatureExtraction.html}", note=[Accessed: 22-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_featureextraction, organization={Wolfram Research}, title={FeatureExtraction}, year={2025}, url={https://reference.wolfram.com/language/ref/FeatureExtraction.html}, note=[Accessed: 22-June-2026]}