MahalanobisDistance#
- class skfda.misc.metrics.MahalanobisDistance(n_components=10, centering=True, regularization=None, weights=None, components_basis=None, alpha=0.001, eigenvalues=None, eigenvectors=None)[source]#
Functional Mahalanobis distance.
Class that implements functional Mahalanobis distance for both basis and grid representations of the data [1].
- Parameters:
n_components (int) – Number of eigenvectors to keep from functional principal component analysis. Defaults to 10.
centering (bool) – If
True
then calculate the mean of the functional data object and center the data first. Defaults toTrue
.regularization (Optional[TikhonovRegularization[FData]]) – Regularization object to be applied.
weights (Optional[Union[ArrayLike, WeightsCallable]]) – The weights vector used for discrete integration. If none then Simpson’s rule is used for computing the weights. If a callable object is passed, then the weight vector will be obtained by evaluating the object at the sample points of the passed FDataGrid object in the fit method. This parameter is only used when fitting a FDataGrid.
components_basis (Optional[Basis]) – The basis in which we want the eigenvectors. We can use a different basis than the basis contained in the passed FDataBasis object. This parameter is only used when fitting a FDataBasis.
alpha (float) – Hyperparameter that controls the smoothness of the aproximation.
eigenvectors (Optional[FData]) – Eigenvectors of the covariance operator.
eigenvalues (Optional[NDArrayFloat]) – Eigenvalues of the covariance operator.
Examples
>>> from skfda.misc.metrics import MahalanobisDistance >>> import numpy as np >>> from skfda.representation.grid import FDataGrid >>> data_matrix = np.array([[1.0, 0.0], [0.0, 2.0]]) >>> grid_points = [0, 1] >>> fd = FDataGrid(data_matrix, grid_points) >>> mahalanobis = MahalanobisDistance(2) >>> mahalanobis.fit(fd) MahalanobisDistance(n_components=2) >>> mahalanobis(fd[0], fd[1]) array([ 1.99680384])
References
Methods
fit
(X[, y])Fit the functional Mahalanobis distance to X.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
set_params
(**params)Set the parameters of this estimator.
- fit(X, y=None)[source]#
Fit the functional Mahalanobis distance to X.
We extract the eigenvectors and corresponding eigenvalues of the covariance operator by using FPCA.
- Parameters:
X (FData) – Stochastic process.
y (None) – Ignored.
- Returns:
self
- Return type:
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequest
encapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)#
Get parameters for this estimator.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
Examples using skfda.misc.metrics.MahalanobisDistance
#
Voice signals: smoothing, registration, and classification