Java - Matrix is singular

653 Views Asked by At

I have this code:

OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double[] consumptions = new double[vec.size()];  
double[][] x = new double[(int) (trainPart * vec.size())][3];

 while (it_vec.hasNext() ) {
   Vector<Double> tmp = new Vector<Double>();
   tmp = it_vec.next();

   if (count < trainPart * (vec.size())) {
     consumptions[count] = tmp.get(0);
     x[count] = new double []{tmp.get(1), tmp.get(4), season(tmp.get(5))};
    } else {
       //do something else  
       }        
    count++;
 }

regression.newSampleData(consumptions, x);
double[] coeff = regression.estimateRegressionParameters(); 

I save electricity consumptions (double) into array consumptions in while cycle. Array xkeeps three doubles, this: x[count] = new double []{tmp.get(1), tmp.get(4), season(tmp.get(5))};. tmp.get(1) is hour of the day, tmp.get(4) is 1.0 or 0.0 (1.0 if is weekend), season(tmp.get(5)) return 1.0 or 0.0 (1.0 if there are winter months). Error I get at the last line: matrix is singular.

I know matrix is singular if determinant is zero but I have a lot of observations. Does anyone know where the problem may be? Thank you, Daniel

0

There are 0 best solutions below