1

I am trying to use the org.apache.commons.math3 OLSMultipleLinearRegression.java:

OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();

The data format of my x and y are different in every iteration like the following:

first iteration:

double[] y = {0.2342342};
double[][]x = { {0.234234234, 0.234165745, 0.234165745}};

Second iteration

double[] y = {0.2342342, 0.23423423};
double[][]x = {
    {0.234234234, 0.234165745, 0.234165745},
    {0.234165745, 0.234165745, 0.234165745}
};

Third iteration

double[] y = {0.2342342, 0.23423423, 0.234234234};
double[][]x = { 
    {0.234234234, 0.234165745, 0.234165745},
    {0.234234234, 0.234165745, 0.234165745},
    {0.234234234, 0.234165745, 0.234165745}
    };

Fourth iteration

double[] y = {0.2342342, 0.23423423, 0.234234234, 0.242312312};
double[][]x = { 
    {0.234234234, 0.234165745, 0.234165745},
    {0.234234234, 0.234165745, 0.234165745},
    {0.234234234, 0.234165745, 0.234165745},
    {0.234234234, 0.234165745, 0.234165745} 
    };

Here is my code:

try {
     regression.newSampleData(y, x);
} catch (IllegalArgumentException e) {
     return getFallbackVmAllocationPolicy().isHostOverUtilized(host);
}

double[] estimates = regression.estimateRegressionParameters();

double predictedUtilization = 0.0;

for (int i = 0; i < utilizationHistory.length; i++) {
      predictedUtilization = estimates[0] + (estimates[1] * utilizationHistory[i])
                            + (estimates[2] * ramUtilizationHistory[i]) + (estimates[3] * bwUtilizationHistory[i]);
}

//predictedUtilization *= getSafetyParameter();

addHistoryEntry(host, predictedUtilization);
return predictedUtilization >= 1;

While performing this, I am getting an exception as shown below :

org.apache.commons.math3.linear.SingularMatrixException: matrix is singular
at org.apache.commons.math3.linear.QRDecomposition$Solver.solve(QRDecomposition.java:347)
at org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression.calculateBeta(OLSMultipleLinearRegression.java:228)

How can I solve this exception?

Ali Mosavi
  • 23
  • 5

0 Answers0