Using Apache library for OLS regression: matrix is ​​an exceptional exception

I am using the Apache Math Library for Java to find OLS regression for a dataset. However, sometimes I get the following error: "org.apache.commons.math3.linear.SingularMatrixException: the matrix is ​​singular"

The data to which regression is applied are not always the same. This is a set created after going through the decision tree. Here is one example of a dataset that throws this exception:

    [1.41385, 0.0, 19.58, 1.0, 0.871, 6.129, 96.0, 1.7494, 5.0, 403.0, 14.7, 321.02, 15.12, 17.0, 
     0.59005, 0.0, 21.89, 0.0, 0.624, 6.372, 97.9, 2.3274, 4.0, 437.0, 21.2, 385.76, 11.12, 23.0, 
     8.24809, 0.0, 18.1, 0.0, 0.713, 7.393, 99.3, 2.4527, 24.0, 666.0, 20.2, 375.87, 16.74, 17.8, 
     2.44953, 0.0, 19.58, 0.0, 0.605, 6.402, 95.2, 2.2625, 5.0, 403.0, 14.7, 330.04, 11.32, 22.3, 
     2.14918, 0.0, 19.58, 0.0, 0.871, 5.709, 98.5, 1.6232, 5.0, 403.0, 14.7, 261.95, 15.79, 19.4, 
     2.3139, 0.0, 19.58, 0.0, 0.605, 5.88, 97.3, 2.3887, 5.0, 403.0, 14.7, 348.13, 12.03, 19.1, 
     2.3139, 0.0, 19.58, 0.0, 0.605, 5.88, 97.3, 2.3887, 5.0, 403.0, 14.7, 348.13, 12.03, 19.1, 
     2.44953, 0.0, 19.58, 0.0, 0.605, 6.402, 95.2, 2.2625, 5.0, 403.0, 14.7, 330.04, 11.32, 22.3, 
     8.24809, 0.0, 18.1, 0.0, 0.713, 7.393, 99.3, 2.4527, 24.0, 666.0, 20.2, 375.87, 16.74, 17.8, 
     2.3139, 0.0, 19.58, 0.0, 0.605, 5.88, 97.3, 2.3887, 5.0, 403.0, 14.7, 348.13, 12.03, 19.1, 
     2.3004, 0.0, 19.58, 0.0, 0.605, 6.319, 96.1, 2.1, 5.0, 403.0, 14.7, 297.09, 11.1, 23.8, 
     5.66637, 0.0, 18.1, 0.0, 0.74, 6.219, 100.0, 2.0048, 24.0, 666.0, 20.2, 395.69, 16.59, 18.4, 
     5.66637, 0.0, 18.1, 0.0, 0.74, 6.219, 100.0, 2.0048, 24.0, 666.0, 20.2, 395.69, 16.59, 18.4, 
     2.3139, 0.0, 19.58, 0.0, 0.605, 5.88, 97.3, 2.3887, 5.0, 403.0, 14.7, 348.13, 12.03, 19.1, 
     2.3139, 0.0, 19.58, 0.0, 0.605, 5.88, 97.3, 2.3887, 5.0, 403.0, 14.7, 348.13, 12.03, 19.1, 
     14.0507, 0.0, 18.1, 0.0, 0.597, 6.657, 100.0, 1.5275, 24.0, 666.0, 20.2, 35.05, 21.22, 17.2]
    nobs: 16 nvars: 13

How can I avoid getting this error? Is there a python-like Java solution written here .

+4
source share
2 answers

OLS Apocal commons-math. , , . , , , , OLS .

.

+4

, , , 0, . , ( ). 0 . . , https://en.wikipedia.org/wiki/Ordinary_least_squares , OLS. , , SingularMatrixException.

, , . b 0, b 1,..., b n
y = b 0 + b 1 x 1 +... + b n x n
, b i. x 1 0, , b 1, . , 1= 2x 2 + x 3, b 1, b 2 b 3, , .

+1

Source: https://habr.com/ru/post/1525178/


All Articles