我正在尝试使用 org.apache.commons.math3 OLSMultipleLinearRegression.java:
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
我的 x 和 y 的数据格式在每次迭代中都不同,如下所示:
第一次迭代:
double[] y = {0.2342342};
double[][]x = { {0.234234234, 0.234165745, 0.234165745}};
第二次迭代
double[] y = {0.2342342, 0.23423423};
double[][]x = {
{0.234234234, 0.234165745, 0.234165745},
{0.234165745, 0.234165745, 0.234165745}
};
第三次迭代
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}
};
第四次迭代
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}
};
这是我的代码:
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;
在执行此操作时,我得到一个异常,如下所示:
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)
我该如何解决这个异常?