Inverting Ill-conditioned Matrix In Numpy
Solution 1:
The rank of the covariant matrix is <= n-1, so the covariant matrix of a square matrix will always be singular. This is part of the nature of covariant matrices (see https://stats.stackexchange.com/questions/60622/why-is-a-sample-covariance-matrix-singular-when-sample-size-is-less-than-number)
So although in the example given numpy has given a non-zero value for the determinant, this is due to rounding errors in the use of floats.
So, what you are trying to do is not mathematically sensible. If you have two variables and two observations you have a scatter graph with only two points, and it is certain that the covariance is zero. If we are then trying to calculate Mahalanobis-distance we hit a problem. If a point is not on the line of best fit, it is certainly not part of the distribution (since the covariance is zero) making the Mahalanobis distance infinite...
This is the problem you are finding. So you either need to start with more observations than variables (a non square matrix) or rethink what you are trying to do.
Post a Comment for "Inverting Ill-conditioned Matrix In Numpy"