Reputation: 11
I am trying to fit a curve with a 2-nd degree polynomial regression using PolynomialCurveFitter in Java with Apache Maths. This is my code:
final WeightedObservedPoints obs = new WeightedObservedPoints();
obs.add(1, 3400);
obs.add(3, 6000);
obs.add(8, 9600);
obs.add(10, 30000);
// Instantiate a third-degree polynomial fitter.
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
// Retrieve fitted parameters (coefficients of the polynomial function).
final double[] coeff = fitter.fit(obs.toList());
//System.out.println(coeff);
System.out.println("coef="+Arrays.toString(coeff));
And it's working fine, but I would like to intercept at (0,0), i.e. my constant term in the equation to be zero: y=ax+bx^2.
Thank you very much for your help, Fred
Upvotes: 1
Views: 540
Reputation: 21
You can add the point(0,0) with a huge weight, such as obs.add(10000, 0, 0). if you use obs.add(0, 0), the default weight is 1.
Upvotes: 2