1

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

2
  • You can try to add: obs.add(0, 0); and change PolynomialCurveFitter.create(4); Commented Jul 8, 2015 at 16:23
  • I thought of adding obs.add(0, 0); but still it would not be as accurate as forcing it intercept (0,0). But why PolynomialCurveFitter.create(4);? Commented Jul 8, 2015 at 16:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.