Questions tagged [mahalanobis]

A dissimilarity metric to compute distance between a point and a distribution.

Learn more about the Mahalanobis distance on Wikipedia


Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of such metric.
Consider whether the question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

96 questions
2
votes
0 answers

Avoid Lapack routine dges in Mahalanobis distance

I get the following error while running the mahalanobis distance Error in solve.default(cov, ...) : Lapack routine dgesv: system is exactly singular: U[2,2] = 0 This is my code. calibration <- 10 mean <- colMeans(x[1:calibration,]) sx <-…
2
votes
1 answer

Scipy - Nan when calculating Mahalanobis distance

When I try to calculate the Mahalanobis distance with the following python code I get some Nan entries in the result. Do you have any insight about why this happens? My data.shape = (181, 1500) from scipy.spatial.distance import pdist,…
Gioelelm
  • 2,645
  • 5
  • 30
  • 49
1
vote
1 answer

Vectorizing Mahalanobis distance - numpy

I have been looking at the answer from @Danita's answer (Vectorizing code to calculate (squared) Mahalanobis Distiance), which uses np.einsum to calculate the squared Mahalanobis distance. In that case, the vectors are: X of shape (m, n), U of shape…
1
vote
1 answer

calculate Mahalanabois distances when have missing values

In R, I am trying to calculate Mahalanobis distances to check if there are outliers in my data set, to test one of the assumptions for a MANOVA. I have missing values in my data set. I originally had tried the mahalanabois function, but that didn't…
Lyn
  • 21
  • 1
1
vote
0 answers

Mahalanobis distance with 0 variance

I'm developing a clustering algorithm, I'm using the Mahalanobis distance to decide if a point must be included in a cluster or not. A cluster is represented by the statistics of the points that are included in it, the statistics are: the sum of…
1
vote
1 answer

Plot Mahalanobis distance as ellipse for PCA is missing part of circle edge

I am working creating a PCA combined with a Mahalanobis distance function to remove any outliers detected from the PCA transformation. I have come across this article which uses R: Mahalanobis output in R. However, how do I implement the Mahalanobis…
1
vote
0 answers

R: How to solve Lapack routine dgesv: system is exactly singular in Mahalanobis distance

I am trying to run an Explanatory Factor Analysis on my questionnaire data. I have data for 201 participants and 30 questions. The head of my data looks somehow like this (I am showing only the first 5 questions to give an idea of the dataset…
1
vote
1 answer

Mahalanobis distance not equal to Euclidean distance after PCA

I am trying to compute the Mahalanobis distance as the Euclidean distance after transformation with PCA, however, I do not get the same results. The following code: import numpy as np from scipy.spatial.distance import mahalanobis from…
Lara
  • 81
  • 9
1
vote
1 answer

Handling singular matrix with Mahalanobis

I have a data frame of groups for which I would like to calculate the Mahalanobis distance for each group. I am trying to apply the Mahalanobis function to hundreds of groups and one particular group is causing an issue due to the small sample size…
TheGoat
  • 2,587
  • 3
  • 25
  • 58
1
vote
1 answer

how to calculate mahalanobis distance in pytorch?

What is the most efficient way to calculate the mahalanobis distance: in pytorch?
john price
  • 13
  • 1
  • 3
1
vote
0 answers

Mahalanobis Distance with Null Values

My input dataframe is; Default1 Default2 Default3 ... Default10 10 4 5 4 6 10 5 7 3 15 3 3 2 7 10 4 8 - 6 …
Salih
  • 719
  • 1
  • 6
  • 12
1
vote
2 answers

Nearest-neighbor matching with the Mahalanobis distance in R

I would like to use the MatchIt package in R to perform nearest neighbor matching using the Mahalanobis distance withing some caliper. Which of the following two parameters of the matchit function that are related to the Mahalanobis distance should…
dzeltzer
  • 990
  • 8
  • 28
1
vote
1 answer

How to use mahalanobis distance in cross_validate() python sklearn? error - size of V does not match

How to use mahalanobis distance in cross_validate() python sklearn? i got error because error - size of V does not match. here is my code model=neighbors.KNeighborsClassifier(n_neighbors=5,metric="mahalanobis",metric_params={'V': np.cov(X)}) results…
Sabri Sangjaya
  • 83
  • 1
  • 2
  • 8
1
vote
2 answers

KNN Mahalanobis error - size of V does not match - Python

I am trying to implement a KNN model, using Mahalanobis as the distance metric, however when I execute the code I am getting an error: Value Error: "size of V does not match where V is the covariance matrix of features. Relevant parts of my code…
Aqace
  • 45
  • 6
1
vote
0 answers

How do I calculate the covariance matrix for a specific centroid (k-means clustering) in Python 3?

I am implementing an algorithm for k-means clustering. So far it works using Euclidean distances. Switching out Euclidean distances for Mahalanobis distances fails to cluster correctly. For some reason, the Mahalanobis distance is negative at times.…