({{, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[{(Subscript[example, 1]),(Subscript[example, 2]),…}]
generates a (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])[…] trained from the examples given.}, {, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,extractor]
uses the specified feature extractor method.}, {, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,{(Subscript[extractor, 1]),(Subscript[extractor, 2]),…}]
applies the (Subscript[extractor, i]) in sequence to generate a feature extractor.}, {, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,spec->ext]
uses the extractor methods specified by ext on parts of examples specified by spec. }, {, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,{(Subscript[spec, 1])->(Subscript[ext, 1]),(Subscript[spec, 2])->(Subscript[ext, 2]),…}]
uses the extractor methods (Subscript[ext, i]) on parts of examples specified by the (Subscript[spec, i]).}, {, (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,extractor,props]
gives the feature extraction properties specified by props.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction]) can be used on many types of data, including numerical, textual, sounds, and images, as well as combinations of these.

Each (Subscript[example, i]) can be a single data element, a list of data elements, an association of data elements, or a (RefLink[Dataset, paclet:ref/Dataset]) object.

(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples] returns a (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])[…] that can be applied to specific data.

Possible feature extractor methods include:

Additional feature extractor methods can also be used for each data type.

Numeric data:

Nominal data:

Text:

Images:

Audio objects:

Feature extractor methods are applied to data elements with whose types they are compatible. Other data elements are returned unchanged.

(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples] is equivalent to (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,(RefLink[Automatic, paclet:ref/Automatic])], which is typically equivalent to (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,"NumericVector"].

The "NumericVector" method will typically convert examples to numeric vectors, impute missing data, and reduce the dimension using (RefLink[DimensionReduction, paclet:ref/DimensionReduction]).

In (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,extractors,props], props can be a single property or a list of properties. Possible properties include:

In (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,spec->ext] or (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,{(Subscript[spec, 1])->(Subscript[ext, 1]),…}], possible forms for spec and the (Subscript[spec, i]) include:

Parts not mentioned in spec or the (Subscript[spec, i]) are dropped for the purpose of extracting features.

In (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,{(Subscript[spec, 1])->(Subscript[ext, 1]),…}], the (Subscript[ext, i]) are all applied separately to examples.

The following options can be given:

Possible settings for (RefLink[RandomSeeding, paclet:ref/RandomSeeding]) include:

(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[…,"ExtractedFeatures"] is equivalent to (RefLink[FeatureExtract, paclet:ref/FeatureExtract])[…].

(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[…,"FeatureDistance"] is equivalent to (RefLink[FeatureDistance, paclet:ref/FeatureDistance])[FeatureExtraction[…]].

OpenersPrimaryExamplesSection(Spacer1)Examples  (21)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Train a (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction]) on a simple dataset:

fe=FeatureExtraction[{{1.4,"A"},{1.5,"A"},{2.3,"B"},{5.4,"B"}}]

Extract features from a new example:

fe[{2.4,"A"}]

Extract features from a list of examples:

fe[{{2.4,"A"},{3.7, "B"}}]

Train a feature extractor on a dataset of images:

fe=FeatureExtraction[{,, ,,,}]

Use the feature extractor on the training set:

fe[{,, ,,,}]

Construct a feature extractor from a numerical dataset using the "StandardizedVector" extractor method:

fe=FeatureExtraction[{{1.4,30.1},{1.5,46.3},{2.3,27.4},{5.4,51.2}},"StandardizedVector"]

Use the feature extractor on the training set:

fe[{{1.4,30.1},{1.5,46.3},{2.3,27.4},{5.4,51.2}}]

The property "ExtractedFeatures" can be used to perform this operation in one step:

FeatureExtraction[{{1.4,30.1},{1.5,46.3},{2.3,27.4},{5.4,51.2}},"StandardizedVector","ExtractedFeatures"]

Multiple properties can be queried:

FeatureExtraction[{{1.4,30.1},{1.5,46.3},{2.3,27.4},{5.4,51.2}},"StandardizedVector",{"ExtractorFunction", "ExtractedFeatures"}]

OpenersExampleSection1(Spacer1)Scope  (12)

Train a feature extractor on textual data:

fe=FeatureExtraction[{"the cat is grey","my cat is fast","this dog is scary","the big dog"}]

Use the feature extractor on new examples:

fe[{"it is not a cat", "what a nice dog","here is a dog again"}]

Train a feature extractor on a list of (RefLink[DateObject, paclet:ref/DateObject]):

fe=FeatureExtraction[{(DateObject["Mon 5 May 2014 09:53:06""GMT"-6.`, DateObject[{2014,5,5,9,53,6.301579`},"Instant","Gregorian",-6.`]]),(DateObject["Sat 1 Jan 2000 00:00:00""GMT"-6.`, DateObject[{2000,1,1,0,0,0.`},"Instant","Gregorian",-6.`]]),(DateObject["Month: ""Dec 2006", DateObject[{2006,12},"Month","Gregorian",-6.`]]),(DateObject["Day: ""Thu 23 Aug 2007", DateObject[{2007,8,23},"Day","Gregorian",-6.`]]),(DateObject["Mon 4 Apr 2016 15:59:18""GMT"-4.`, DateObject[{2016,4,4,15,59,18.273754`},"Instant","Gregorian",-4.`]])}]

Extract features from a new (RefLink[DateObject, paclet:ref/DateObject]):

fe[(DateObject["Day: ""Thu 2 Jan 2003", DateObject[{2003,1,2},"Day","Gregorian",-6.`]])]

A string date can also be given:

fe["2nd of January 2003"]

Train a feature extractor to compute term frequency-inverse document frequency vectors from texts:

fe=FeatureExtraction[{"the cat is grey","my cat is fast","this dog is scary","the big dog"},"TFIDF"]

The term frequency-inverse document frequency matrix of the training set can be computed in a (RefLink[SparseArray, paclet:ref/SparseArray]):

matrix=fe[{"the cat is grey","my cat is fast","this dog is scary","the big dog"}]

Visualize the matrix:

MatrixForm[matrix]

The "TFIDF" method can also be used on tokenized data (nominal bags):

FeatureExtraction[{{"the","cat" ,"is", "grey"},{"my" ,"cat","is","fast"},{"this", "dog","is","scary"},{"the","big","dog"}},"TFIDF","ExtractedFeatures"]

Train a feature extractor on text using the "TFIDF" method followed by the "DimensionReduced" method:

fe=FeatureExtraction[{"the cat is grey","my cat is fast","this dog is scary","the big dog"},{"TFIDF","DimensionReducedVector"}]

Extract features on the training set:

fe[{"the cat is grey","my cat is fast","this dog is scary","the big dog"}]

Generate a feature extractor using a custom function:

data={(DateObject["Mon 5 May 2014 09:53:06""GMT"-5.`, DateObject[{2014,5,5},TimeObject[{9,53,6.301579`},TimeZone->-5.`],TimeZone->-5.`]]),(DateObject["Sat 1 Jan 2000 00:00:00""GMT"-5.`, DateObject[{2000,1,1},TimeObject[{0,0,0.`},TimeZone->-5.`],TimeZone->-5.`]]),(DateObject["Dec 2006", DateObject[{2006,12}]]),(DateObject["Thu 23 Aug 2007", DateObject[{2007,8,23}]]),(DateObject["Mon 4 Apr 2016 15:59:18""GMT"-4.`, DateObject[{2016,4,4},TimeObject[{15,59,18.273754`},TimeZone->-4.`],TimeZone->-4.`]])};

fe=FeatureExtraction[data,{AbsoluteTime[#],#["Year"]}&]

Apply the extractor on the training set:

fe[data]

Chain the custom extractor with the "StandardizedVector" method:

fe2=FeatureExtraction[data,{{AbsoluteTime[#],#["Year"]}&, "StandardizedVector"}]

fe2[data]

Train a feature extractor with the "IndicatorVector" method on nominal variables:

fe=FeatureExtraction[{{"Yes","A"},{"No","A"},{"No","B"},{"Maybe","B"},{"No", "C"}},"IndicatorVector"]

Extract features from a new example:

Normal@fe[{"Yes","A"}]

Train a feature extractor with the "IndicatorVector" method on only the second nominal variable:

fe=FeatureExtraction[{{"Yes","A"},{"No","A"},{"No","B"},{"Maybe","B"},{"No", "C"}},2->"IndicatorVector"]

The first nominal variable is dropped:

Normal@fe[{"Yes","A"}]

Use the (RefLink[Identity, paclet:ref/Identity]) extractor method to copy the first variable:

fe=FeatureExtraction[{{"Yes","A"},{"No","A"},{"No","B"},{"Maybe","B"},{"No", "C"}},{2->"IndicatorVector",1->Identity}]

The first variable is copied:

fe[{"Yes","A"}]

A variable can be copied multiple times:

fe=FeatureExtraction[{{"Yes","A"},{"No","A"},{"No","B"},{"Maybe","B"},{"No", "C"}},{2->"IndicatorVector",1->Identity,1->Identity}]

fe[{"Yes","A"}]

Train a feature extractor on a mixed-type dataset:

fe=FeatureExtraction[{{"the cat is grey",},{"my cat is fast",},{"this dog is scary",},{"the big dog",}}]

Extract features from a new example:

fe[{"the nice cat",}]

Train a feature extractor on texts and images using the "TFIDF" method:

fe=FeatureExtraction[{{"the cat is grey",},{"my cat is fast",},{"this dog is scary",},{"the big dog",}},"TFIDF"]

Features will only be extracted from the text part:

fe[{"the nice cat",}]

Train a feature extractor from a dataset that contains missing values:

fe=FeatureExtraction[{{1.4,Missing[],"A"},{1.5,50.2,"A"},{Missing[],42.3,"B"},{5.4,61.7,"B"}}]

This feature extractor can extract features even when values are missing:

fe[{3.4,Missing[],"B"}]

Train a feature extractor using the "StandardizedVector" method:

fe=FeatureExtraction[{{1.4,42.1},{1.5,50.2},{4.2,42.3},{5.4,61.7}},"StandardizedVector"]

Extract features from a new example:

features=fe[{6.4,32.1}]

Since this feature extractor is invertible, the (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction]) property "OriginalData" can be used to perform the inverse extraction:

fe[features,"OriginalData"]

Some feature extractors can only perform an approximation of the inverse extraction:

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}},"DimensionReducedVector"]

features = fe[{1.1,1.2,5.1,5.7}]

fe[features,"OriginalData"]

The (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction]) property "ReconstructedData" can be used to obtain the data after extraction and reconstruction:

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"]

Some feature extractors cannot be inverted:

FeatureExtraction[{, ,,},"ImageFeatures","ReconstructedData"]

Train a feature extractor from a list of associations:

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"|>}]

Extract features from a new example:

fe[<|"age"->19,"height"->176, "gender"-> "male"|>]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)FeatureNames  (2)

Train a feature extractor and give a name to each feature:

fe=FeatureExtraction[{{2.3,"male"},{4.8,Missing[]},{Missing[],"female"},{5.2,"female"}},FeatureNames->{"age","gender"}]

Use the association format to extract features from a new example:

fe[<|"age"->3.3,"gender"->"male"|>]

The list format can still be used:

fe[{3.3,"male"}]

Use (RefLink[FeatureNames, paclet:ref/FeatureNames]) to set up names and refer to them in (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])[examples,{(Subscript[spec, 1])->(Subscript[ext, 1]),…}]:

fe=FeatureExtraction[{{"A","female"},{"B","female"},{"C","male"},{"B","male"}},{"class"->Identity,"gender"->"IndicatorVector"},"ExtractedFeatures",FeatureNames->{"class","gender"}]

OpenersExampleSubsection1(Spacer1)FeatureTypes  (1)

Train a feature extractor with the "IndicatorVector" method on a simple dataset:

fe=FeatureExtraction[{{1,"A"},{2,"A"},{2,"B"},{1,"B"}},"IndicatorVector"]

The first feature has been interpreted as numerical. Since the "IndicatorVector" method only acts on nominal features, the first feature is unchanged:

fe[{{1,"A"},{2,"A"},{2,"B"},{1,"B"}}]

Use (RefLink[FeatureTypes, paclet:ref/FeatureTypes]) to enforce the interpretation of the first feature as nominal:

fe=FeatureExtraction[{{1,"A"},{2,"A"},{2,"B"},{1,"B"}},"IndicatorVector",FeatureTypes-><|1->"Nominal"|>]

fe[{{1,"A"},{2,"A"},{2,"B"},{1,"B"}}] // MatrixForm

OpenersExampleSection3(Spacer1)Applications  (3)

OpenersExampleSubsection2(Spacer1)Image Search  (1)

Construct a dataset of dog images:

dataset={,,,,,,,,,,,,,,,,,,,,};

Train an extractor function from this dataset:

fe=FeatureExtraction[dataset]

Generate a (RefLink[NearestFunction, paclet:ref/NearestFunction]) on the extracted features of the dataset:

nf=Nearest[fe[dataset]->Automatic]

Using the (RefLink[NearestFunction, paclet:ref/NearestFunction]), construct a function that displays the nearest image of the dataset:

nearestdog=dataset[[First@nf[fe[#]]]]&

Use this function on images that are not in the dataset:

nearestdog[]

nearestdog[]

nearestdog[]

This feature extractor function can also be used to delete image pairs that are too similar:

features=#->fe[#]&/@dataset;

First/@DeleteDuplicates[features,CosineDistance[#1[[2]],#2[[2]]]<1 &]

OpenersExampleSubsection3(Spacer1)Text Search  (1)

Load the text of Alice in Wonderland:

alice=ExampleData[{"Text","AliceInWonderland"}];

Split the text into sentences:

sentences= TextSentences[alice];

Train a feature extractor on these sentences:

fe=FeatureExtraction[sentences]

Generate a (RefLink[NearestFunction, paclet:ref/NearestFunction]) with the sentences' features:

nf=Nearest[fe[sentences]->Automatic]

Using the (RefLink[NearestFunction, paclet:ref/NearestFunction]), construct a function that displays the nearest sentence in Alice in Wonderland:

nearestalice=sentences[[First@nf[fe[#]]]]&

Use this function with a few queries:

nearestalice["Alice and the Rabbit"]

nearestalice["Alice and the Queen"]

nearestalice["Off her head"]

OpenersExampleSubsection4(Spacer1)Imputation  (1)

Load the "MNIST" dataset from (RefLink[ExampleData, paclet:ref/ExampleData]) and keep the images:

digits=First/@ExampleData[{"MachineLearning","MNIST"}, "TestData"];

RandomSample[digits,10]

Convert images to numerical data and separate the dataset into a training set and a test set:

digits=Flatten[ImageData[#]]&/@RandomSample[digits];

trainingset=digits[[;;9000]];
testset=digits[[9001;;]];

The dimension of the dataset is 784:

Dimensions[trainingset]

Create a feature extractor using the "MissingImputed" method:

fe=FeatureExtraction[trainingset, "MissingImputed"]

Replace some values of a test-set vector by (RefLink[Missing, paclet:ref/Missing])[] and visualize it:

vector=RandomChoice[testset];

toimage=Image[Partition[#,28], ImageSize->Tiny] &;

vectormissing=vector;
vectormissing[[309;;364]]=Missing[];
imagemissing = toimage[Replace[vectormissing, _Missing-> .5,{1}]]

Impute missing values using the (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])[…]:

imputedimage=toimage[fe[vectormissing]]

Visualize the original image, the image with missing values, and the imputed image:

{toimage[vector],imagemissing,imputedimage}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[FeatureExtract, paclet:ref/FeatureExtract])  ▪  (RefLink[FeatureExtractor, paclet:ref/FeatureExtractor])  ▪  (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])  ▪  (RefLink[DimensionReduction, paclet:ref/DimensionReduction])  ▪  (RefLink[FeatureNearest, paclet:ref/FeatureNearest])  ▪  (RefLink[FeatureDistance, paclet:ref/FeatureDistance])  ▪  (RefLink[Classify, paclet:ref/Classify])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})