`Distance`

— Distance metric`'cityblock'`

| `'euclidean'`

| `'mahalanobis'`

| `'minkowski'`

| `'seuclidean'`

| custom distance function | ...

Distance metric used to find nearest neighbors of query points,
specified as a string or function handle.

This table describes the supported distance metrics specified
by strings.

Value | Description |

`'chebychev'` | Chebychev distance (maximum coordinate difference) |

`'cityblock'` | City block distance |

`'correlation'` | One minus the sample linear correlation between observations
(treated as sequences of values) |

`'cosine'` | One minus the cosine of the included angle between observations
(row vectors) |

`'euclidean'` | Euclidean distance |

`'hamming'` | Hamming distance, which is the percentage of coordinates that
differ |

`'jaccard'` | One minus the Jaccard coefficient, which is the percentage
of nonzero coordinates that differ |

`'minkowski'` | Minkowski distance |

`'mahalanobis'` | Mahalanobis distance |

`'seuclidean'` | Standardized Euclidean distance |

`'spearman'` | One minus the sample Spearman's rank correlation between observations
(treated as sequences of values) |

For more details, see Distance Metrics.

You can specify a function handle for a custom distance metric
using `@`

(for example, `@distfun`

).
A custom distance function must:

Have the form `function D2 = distfun(ZI, ZJ)`

Take as arguments:

Return an *m*-by-1 vector of distances `D2`

,
whose *j*th element is the distance between the observations `ZI`

and `ZJ`

(*j*`,:)`

The software does not use the distance metric for training the
exhaustive searcher algorithm. Therefore, you can alter it after training
by specifying a supported string or function handle for a custom function
using dot notation. For example, to specify the Mahalanobis distance,
enter `Mdl.Distance = 'mahalanobis'`

.

**Data Types: **`char`

| `function_handle`

Distance metric parameter values, specified as empty (`[]`

)
or as a positive scalar.

This table describes the distance parameters of the supported
distance metrics.

Distance Metric | Parameter
Description |

`'mahalanobis'` | A positive definite matrix representing the covariance matrix
used for computing the Mahalanobis distances. By default, the software
sets the covariance using `nancov(Mdl.X)` . You can
alter the scale parameter using dot notation, e.g., ```
Mdl.DistParameter
= CovNew
``` , where `CovNew` is a *K*-by-*K* positive
definite numeric matrix. |

`'minkowski'` | A positive scalar indicating the exponent of the Minkowski
distances. By default, the exponent is `2` . |

`'seuclidean'` | A positive, numeric vector indicating the values that the software
uses to scale the predictors when computing the standardized Euclidean
distances. By default, the software: Estimates the standard deviation of each predictor
(column) of `X` using `scale = nanstd(Mdl.X)` . Scales each coordinate difference between the rows
in `X` and the query matrix by dividing by the corresponding
element of `scale` . You can alter the scale parameter using dot notation,
e.g., `Mdl.DistParameter = sNew` , where `sNew` is
a *K*-dimensional positive numeric vector. |

If `Mdl.Distance`

is not one of the parameters
listed in this table, then `Mdl.DistParameter`

is `[]`

,
which means that the specified distance metric formula has no parameters.

**Data Types: **`single`

| `double`

This property is read only.

Training data that prepares the exhaustive searcher algorithm,
specified as a numeric matrix. `X`

has *n* rows,
each corresponding to an observation (i.e., instance or example),
and *K* columns, each corresponding to a predictor
or feature.

**Data Types: **`single`

| `double`