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
14
votes
2 answers

How to use mahalanobis distance in sklearn DistanceMetrics?

Perhaps this is elementary, but I cannot find a good example of using mahalanobis distance in sklearn. I can't even get the metric like this: from sklearn.neighbors import DistanceMetric DistanceMetric.get_metric('mahalanobis') This throws an…
makansij
  • 9,303
  • 37
  • 105
  • 183
14
votes
2 answers

Mahalonobis distance in R, error: system is computationally singular

I'd like to calculate multivariate distance from a set of points to the centroid of those points. Mahalanobis distance seems to be suited for this. However, I get an error (see below). Can anyone tell me why I am getting this error, and if there is…
Pascal
  • 1,590
  • 2
  • 16
  • 35
13
votes
2 answers

Multivariate Outlier Detection using R with probability

I have been searching everywhere for the best method to identify the multivariate outliers using R but I don't think I have found any believable approach yet. We can take the iris data as an example as my data also contains multiple fields…
Duy Bui
  • 1,348
  • 6
  • 17
  • 38
8
votes
2 answers

Is there a Python equivalent to the mahalanobis() function in R? If not, how can I implement it?

I have the following code in R that calculates the mahalanobis distance on the Iris dataset and returns a numeric vector with 150 values, one for every observation in the dataset. x=read.csv("Iris…
jose14
  • 83
  • 1
  • 6
5
votes
3 answers

Multivariate Outlier Removal With Mahalanobis Distance

I have this data which have outlier . How can i find Mahalanobis disantance and use it to remove outlier.
Shubham Tyagi
  • 181
  • 1
  • 3
  • 14
4
votes
1 answer

How to use Mahalanobis distance to find the K Nearest Neighbor in R

I have a time series dataset from 1970 to 2020 as my training dataset, and I have another single observation of 2021, what I have to do right now is to use Mahalanobis distance to identify 10 nearest neighbor of 2021 in training dataset. I tried…
Rua Jing
  • 65
  • 5
4
votes
1 answer

Keras custom loss function with Mahalanobis distance loss how to

I am trying to implement a custom loss function in Keras using Mahalanobis distance loss. however I always run into this annoying ERROR. Mahalanobis distance (or "generalized squared interpoint distance" for its squared value[3]) can also be…
user12204435
  • 59
  • 2
  • 6
3
votes
1 answer

Use Mahalonobis distance and caliper in MatchIt package

First of all: This question might be a duplicate/already solved of/in this stackoverflow post. I want to use the MatchIt package to perform fully-blocked matching in my dataset using the Mahalanobis distance. I have two observed covariates (age and…
Johannes Wiesner
  • 1,006
  • 12
  • 33
3
votes
1 answer

Defining distance parameter (V) in knn crossval grid search (seuclidean/mahalanobis distance metrics)

I am trying to carry out a k-fold cross-validation grid search using the KNN algorithm using python sklearn, with parameters in the search being number of neighbors K and distance metric. I am including mahalanobis and seuclidean as distance…
Aqace
  • 45
  • 6
3
votes
1 answer

Vectorized Rolling/Cumulative Mahalanobis Distance in R

I'm trying to calculate a rolling mahalanobis distance without resorting to for loops and failing miserably. Here is an example dataset: df <- data.frame(label = c(rep("A", 5), rep("B", 5)), date = rep(seq.Date(from =…
Forrest
  • 76
  • 6
3
votes
0 answers

Mahalanobis distance - different results on different machines in R

I am working on finding out outliers using Mahalanobis distance in R. I have a dataset with 30 rows and 24 columns, which I feed into the mahanalobis function from stats package.I want to create find distance of each vector with rest of the rows.…
Varun kadekar
  • 427
  • 6
  • 15
3
votes
2 answers

Nearest neighbors with uncertain points

I have two 2D points sets A and B. I want to find the first nearest neighbor in A for each point in B. However, I am dealing with uncertain points (i.e. a point has a mean (2D vector) and a 2*2 covariance matrix). I thus would like to use the…
floflo29
  • 2,261
  • 2
  • 22
  • 45
2
votes
0 answers

Observation matching between groups

I am dealing with an original dataset has more than 20000 rows. A condensed version of this looks something like this below Row x y z Group Survive 1 0.0680 0.8701 0.0619 1 78.43507 2 0.9984 0.0016…
Science11
  • 788
  • 1
  • 8
  • 24
2
votes
0 answers

How to find Mahalanobis Distance of training and testing data

I need to find Mahalanobis Distance between my training data and testing data for K.NN algorithm. I found some descriptions on the internet, but I could not understand them as there was no practical example. Training data: flower = {s.length,…
2
votes
1 answer

Mahalanobis distance of each pair of observations

I am trying to compute the Mahalanobis distance between each observations of a dataset dat, where each row is an observation and each column is a variable. Such distance is defined as: I wrote a function that does it, but I feel like it is slow. Is…
Oligg
  • 375
  • 3
  • 19
1
2 3 4 5 6 7