({{, (RefLink[FeatureDistance, paclet:ref/FeatureDistance])[(Subscript[example, 1]),(Subscript[example, 2]),extractor] 
gives the distance between (Subscript[example, 1]) and (Subscript[example, 2]) in the feature space defined by extractor.}, {, (RefLink[FeatureDistance, paclet:ref/FeatureDistance])[extractor]
represents an operator form of (RefLink[FeatureDistance, paclet:ref/FeatureDistance]) that can be applied to a pair of examples.}})

OpenersNotesSection(Spacer1)Details and Options

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

The extractor is typically a (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction]) object as generated by (RefLink[FeatureExtraction, paclet:ref/FeatureExtraction]).

(RefLink[FeatureDistance, paclet:ref/FeatureDistance])[extractor][(Subscript[ex, 1]),(Subscript[ex, 2])] is equivalent to (RefLink[FeatureDistance, paclet:ref/FeatureDistance])[(Subscript[ex, 1]),(Subscript[ex, 2]),extractor].

The following options can be given:

The option (RefLink[DistanceFunction, paclet:ref/DistanceFunction]) can be any distance or dissimilarity function or a function f defining a distance between two values.

For numeric feature vectors, the default setting is (RefLink[DistanceFunction, paclet:ref/DistanceFunction])->(RefLink[EuclideanDistance, paclet:ref/EuclideanDistance]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Construct a dataset of dog images:

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

Train an extractor function from this dataset:

fe=FeatureExtraction[dataset]

Compute the distance in the feature space between two images using (RefLink[FeatureDistance, paclet:ref/FeatureDistance]):

FeatureDistance[,,fe]

Generate an operator form of (RefLink[FeatureDistance, paclet:ref/FeatureDistance]):

fd=FeatureDistance[fe]

This operator form can be used to compute distances:

fd[,]

Compute the distance matrix of the dataset using this feature distance:

dm=DistanceMatrix[dataset,DistanceFunction->fd];

dm // MatrixPlot

Find the dog that maximizes its distance from the others in the feature space:

dataset[[Ordering[Mean[dm],-1]]]

OpenersExampleSection1(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)DistanceFunction  (1)

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

Construct a feature distance for this feature extractor:

fd1=FeatureDistance[fe]

fd1["the cat is grey", "the big dog"]

The distance function (RefLink[EuclideanDistance, paclet:ref/EuclideanDistance]) has been chosen. Use the option (RefLink[DistanceFunction, paclet:ref/DistanceFunction]) to chose (RefLink[CosineDistance, paclet:ref/CosineDistance]) instead:

fd2=FeatureDistance[fe,DistanceFunction->CosineDistance]

fd2["the cat is grey", "the big dog"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[FeatureExtraction, paclet:ref/FeatureExtraction])  ▪  (RefLink[FeatureExtractorFunction, paclet:ref/FeatureExtractorFunction])  ▪  (RefLink[FeatureNearest, paclet:ref/FeatureNearest])  ▪  (RefLink[ImageDistance, paclet:ref/ImageDistance])  ▪  (RefLink[DistanceFunction, paclet:ref/DistanceFunction])  ▪  (RefLink[Nearest, paclet:ref/Nearest])  ▪  (RefLink[ClusterClassify, paclet:ref/ClusterClassify])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Distance and Similarity Measures, paclet:guide/DistanceAndSimilarityMeasures])}})}})