Java Apache Mathematics 3.6.1中的多项式回归
有人能告诉我如何使用3.6.1进行多项式回归吗 下面是我用于测试的数据点Java Apache Mathematics 3.6.1中的多项式回归,java,apache,regression,non-linear-regression,Java,Apache,Regression,Non Linear Regression,有人能告诉我如何使用3.6.1进行多项式回归吗 下面是我用于测试的数据点 60735214881.391304 1520254800000.000000 60697824142.469570 1520258400000.000000 60651182200.208694 1520262000000.000000 60684367132.939130 1520265600000.000000 60676588613.008700 1520269200000.000000 60641816
60735214881.391304 1520254800000.000000
60697824142.469570 1520258400000.000000
60651182200.208694 1520262000000.000000
60684367132.939130 1520265600000.000000
60676588613.008700 1520269200000.000000
60641816564.869570 1520272800000.000000
60604714824.233510 1520276400000.000000
60580042814.330440 1520280000000.000000
60536134542.469570 1520283600000.000000
60566323732.034780 1520287200000.000000
60578775249.252174 1520290800000.000000
60547382844.104350 1520294400000.000000
60536776546.802160 1520298000000.000000
60474342718.330440 1520301600000.000000
60452725477.286960 1520305200000.000000
60486821569.669560 1520308800000.000000
60247997139.995674 1520312400000.000000
60248432181.426090 1520316000000.000000
60217476247.373920 1520319600000.000000
60170744493.634780 1520323200000.000000
我的代码如下所示
private void polynomialFitter(List<List<Double>> pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List<Double> point : pointlist) {
obs.add(point.get(1), point.get(0));
}
double[] fit = fitter.fit(obs.toList());
System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1], fit[2]);
}
private OLSMultipleLinearRegression getMultipleLinearRegression(List<List<Double>> pointlist) {
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double y[] = new double[pointlist.size()];
double x[][] = new double[pointlist.size()][2];
int c = 0;
for (List<Double> point : pointlist) {
y[c] = point.get(0);
x[c][0] = point.get(1);
x[c][1] = Math.pow(point.get(1), 2);
regression.newSampleData(y, x);
c++;
}
System.out.printf("\tR2 = %f", regression.calculateRSquared());
return regression;
}
但这些似乎并不完全正确。如果我在中使用相同的数据集
和in-两个报告的值与654623237474.68250993904929103762,28.75921919628759991574,-0.000000000 23885199278
有人能告诉我出了什么问题吗?我看到了这一点,但这对我没有帮助 这已在邮件列表中得到答复
多项式回归与曲线拟合不同。做
多项式回归在Commons数学中,使用
OLSMultipleLinearRegression类,使用、X、X^2等作为
自变量(如上面第二个参考资料所示)
示例代码如下所示
private void polynomialFitter(List<List<Double>> pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List<Double> point : pointlist) {
obs.add(point.get(1), point.get(0));
}
double[] fit = fitter.fit(obs.toList());
System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1], fit[2]);
}
private OLSMultipleLinearRegression getMultipleLinearRegression(List<List<Double>> pointlist) {
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double y[] = new double[pointlist.size()];
double x[][] = new double[pointlist.size()][2];
int c = 0;
for (List<Double> point : pointlist) {
y[c] = point.get(0);
x[c][0] = point.get(1);
x[c][1] = Math.pow(point.get(1), 2);
regression.newSampleData(y, x);
c++;
}
System.out.printf("\tR2 = %f", regression.calculateRSquared());
return regression;
}
private OLSMultipleLinearRegression getMultipleLinearRegression(列表点列表){
OLSMultipleLinearRegression回归=新的OLSMultipleLinearRegression();
double y[]=新的double[pointlist.size()];
double x[][]=新的double[pointlist.size()][2];
int c=0;
对于(列表点:点列表){
y[c]=点get(0);
x[c][0]=点获取(1);
x[c][1]=Math.pow(point.get(1),2);
回归:新样本数据(y,x);
C++;
}
System.out.printf(“\tR2=%f”,regression.calculatorsquared());
回归分析;
}
这已在邮件列表中得到答复
多项式回归与曲线拟合不同。做
多项式回归在Commons数学中,使用
OLSMultipleLinearRegression类,使用、X、X^2等作为
自变量(如上面第二个参考资料所示)
示例代码如下所示
private void polynomialFitter(List<List<Double>> pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List<Double> point : pointlist) {
obs.add(point.get(1), point.get(0));
}
double[] fit = fitter.fit(obs.toList());
System.out.printf("\nCoefficient %f, %f, %f", fit[0], fit[1], fit[2]);
}
private OLSMultipleLinearRegression getMultipleLinearRegression(List<List<Double>> pointlist) {
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double y[] = new double[pointlist.size()];
double x[][] = new double[pointlist.size()][2];
int c = 0;
for (List<Double> point : pointlist) {
y[c] = point.get(0);
x[c][0] = point.get(1);
x[c][1] = Math.pow(point.get(1), 2);
regression.newSampleData(y, x);
c++;
}
System.out.printf("\tR2 = %f", regression.calculateRSquared());
return regression;
}
private OLSMultipleLinearRegression getMultipleLinearRegression(列表点列表){
OLSMultipleLinearRegression回归=新的OLSMultipleLinearRegression();
double y[]=新的double[pointlist.size()];
double x[][]=新的double[pointlist.size()][2];
int c=0;
对于(列表点:点列表){
y[c]=点get(0);
x[c][0]=点获取(1);
x[c][1]=Math.pow(point.get(1),2);
回归:新样本数据(y,x);
C++;
}
System.out.printf(“\tR2=%f”,regression.calculatorsquared());
回归分析;
}
使用Commons Math 3.6.1,当使用多项式曲线拟合器和tuk的OLSMultipleLinearRegression
建议将立方体拟合到数据时,我得到了几乎相同的参数
曲线在数据范围内给出了正确的插值,但是你必须小心外推
PolynomialCurveFitter
代码是OLSMultipleLinearRegression
代码行数的一半。使用Commons Math 3.6.1,当使用PolynomialCurveFitter
和tuk的OLSMultipleLinearRegression
建议将立方体拟合到数据时,我得到了几乎相同的参数
曲线在数据范围内给出了正确的插值,但是你必须小心外推
PolynomialCurveFitter
代码是OLSMultipleLinearRegression
代码行数的一半。请注意,X和Y数据都有非常大的偏移和很小的变化,因此,对于数值精度,当对多项式中的值进行平方或立方运算时,我个人会首先减去每列的平均值或最小值。在最终结果中,您可以将这些值加回去。请注意,X和Y数据都有非常大的偏移量和较小的变化,因此,对于多项式中的值进行平方或立方运算时的数值精度,我个人会首先减去每列的平均值或最小值。在最终结果中,您可以将这些值添加回。