On 3/12/18 10:15 AM, Debraj Manna wrote:
> Crossposting from stackoverflow
> <https://stackoverflow.com/questions/49238446/polynomial-regression-with-apache-maths-3-6-1>
> as I did not get any reply there
>
> Can someone let me know how I can do Polynomial Regression with Apache Maths
> <https://mvnrepository.com/artifact/org.apache.commons/commons-math3> 3.6.1
> ?
>
> Below are the data points I used for my testing
>
> 60735214881.391304  1520254800000.00000060697824142.469570
> 1520258400000.00000060651182200.208694
> 1520262000000.00000060684367132.939130
> 1520265600000.00000060676588613.008700
> 1520269200000.00000060641816564.869570
> 1520272800000.00000060604714824.233510
> 1520276400000.00000060580042814.330440
> 1520280000000.00000060536134542.469570
> 1520283600000.00000060566323732.034780
> 1520287200000.00000060578775249.252174
> 1520290800000.00000060547382844.104350
> 1520294400000.00000060536776546.802160
> 1520298000000.00000060474342718.330440
> 1520301600000.00000060452725477.286960
> 1520305200000.00000060486821569.669560
> 1520308800000.00000060247997139.995674
> 1520312400000.00000060248432181.426090
> 1520316000000.00000060217476247.373920
> 1520319600000.00000060170744493.634780  1520323200000.000000
>
> My code looks like below
>
> 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]);
>     }
>
> The coefficients are reported as
>
> Coefficient 12.910025, 0.000000, 0.000000
>
> But these does not seem to be quite correct. If I use the same dataset
> in Online
> Polynimal Regression <http://polynomialregression.drque.net/online.php> and
> in archanoid online regression <https://arachnoid.com/polysolve/> - both
> reports same value as 654623237474.68250993904929103762,
> 28.75921919628759991574, -0.00000000023885199278
>
> Can someone let me know what is going wrong? I have seen this question
> <https://stackoverflow.com/questions/28563361/polynomial-regression-with-apache-maths-java>
>  but that is not helping me?

Polynomial regression is not the same as curve fitting.  To do
polynomial regression in Commons Math, use the
OLSMultipleLinearRegression class, using, X, X^2 etc as the
independent variables (as your second reference above shows).

Phil




>
> Thanks,
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to