Skip to content

Mahalanobis distance in covariance.EmpiricalCovariance is wrong #4168

Closed
@otakar-smrz

Description

@otakar-smrz

The Mahalanobis distance is correctly defined in https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/neighbors/dist_metrics.pyx#L623. However, the mahalanobis method of covariance.EmpiricalCovariance https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/covariance/empirical_covariance_.py#L258 is wrong for two reasons:

  1. The current implementation returns the square of the distance. The np.sqrt function must be applied on the current result in order to get the true distance.
  2. The docs say "the provided observations are assumed to be centered". Yet, the opposite is true, since the observations are being centered inside the method, and the user should not be centering the observations.

Thanks for fixing these and making the relevant changes to the dependent examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions