mahalanobis


Mahalanobis distance of each pair of observations

馋奶兔 提交于 2019-12-06 04:31:58
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 there any better way to compute this in R ? To generate some data to test the function: generateData <- function(nObs, nVar){ library(MASS) mvrnorm(n=nObs, rep(0,nVar), diag(nVar)) } This is the function I have written so far. They both work and for my data (800 obs and 90 variables), it takes approximatively 30 and 33 seconds for the method =

How to use mahalanobis distance in sklearn DistanceMetrics?

ぐ巨炮叔叔 提交于 2019-11-30 14:22:01
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 error: TypeError: 0-dimensional array given. Array must be at least two-dimensional . But, I can't even seem to get it to take an array: DistanceMetric.get_metric('mahalanobis', [[0.5],[0.7]]) throws: TypeError: get_metric() takes exactly 1 positional argument (2 given) I checked out the docs here and here . But, I don't see what types of arguments it is

How to use mahalanobis distance in sklearn DistanceMetrics?

我与影子孤独终老i 提交于 2019-11-29 19:46:01
问题 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 error: TypeError: 0-dimensional array given. Array must be at least two-dimensional . But, I can't even seem to get it to take an array: DistanceMetric.get_metric('mahalanobis', [[0.5],[0.7]]) throws: TypeError: get_metric() takes exactly 1 positional

Mahalonobis distance in R, error: system is computationally singular

爷,独闯天下 提交于 2019-11-27 23:04:55
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 a way to work around it? If you download the coordinate data and the associated environmental data , you can run the following code. require(maptools) occ <- readShapeSpatial('occurrences.shp') load('envDat.Rdata') #standardize the data to scale the variables dat <- as.matrix(scale(dat)) centroid <- dat[1547,] #let's assume this is the centroid in

Mahalonobis distance in R, error: system is computationally singular

↘锁芯ラ 提交于 2019-11-27 03:20:42
问题 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 a way to work around it? If you download the coordinate data and the associated environmental data, you can run the following code. require(maptools) occ <- readShapeSpatial('occurrences.shp') load('envDat.Rdata') #standardize the data to scale the

工具导航Map