Re: [Math] How to do Polynomial Regression ?

2018-03-13 Thread Debraj Manna
Thanks Phil

On Tue, Mar 13, 2018 at 4:03 AM, Phil Steitz  wrote:

> On 3/12/18 10:15 AM, Debraj Manna wrote:
> > Crossposting from stackoverflow
> >  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
> > 
> 3.6.1
> > ?
> >
> > Below are the data points I used for my testing
> >
> > 60735214881.391304  152025480.0060697824142.469570
> > 152025840.0060651182200.208694
> > 152026200.0060684367132.939130
> > 152026560.0060676588613.008700
> > 152026920.0060641816564.869570
> > 152027280.0060604714824.233510
> > 152027640.0060580042814.330440
> > 152028000.0060536134542.469570
> > 152028360.0060566323732.034780
> > 152028720.0060578775249.252174
> > 152029080.0060547382844.104350
> > 152029440.0060536776546.802160
> > 152029800.0060474342718.330440
> > 152030160.0060452725477.286960
> > 152030520.0060486821569.669560
> > 152030880.0060247997139.995674
> > 152031240.0060248432181.426090
> > 152031600.0060217476247.373920
> > 152031960.0060170744493.634780  152032320.00
> >
> > My code looks like below
> >
> > private void polynomialFitter(List pointlist) {
> > final PolynomialCurveFitter fitter =
> PolynomialCurveFitter.create(2);
> > final WeightedObservedPoints obs = new WeightedObservedPoints();
> > for (List 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.00, 0.00
> >
> > But these does not seem to be quite correct. If I use the same dataset
> > in Online
> > Polynimal Regression 
> and
> > in archanoid online regression  - both
> > reports same value as 654623237474.68250993904929103762,
> > 28.75921919628759991574, -0.023885199278
> >
> > Can someone let me know what is going wrong? I have seen this question
> >  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,
> >
>
>


Re: [Math] How to do Polynomial Regression ?

2018-03-12 Thread Phil Steitz
On 3/12/18 10:15 AM, Debraj Manna wrote:
> Crossposting from stackoverflow
> 
> as I did not get any reply there
>
> Can someone let me know how I can do Polynomial Regression with Apache Maths
>  3.6.1
> ?
>
> Below are the data points I used for my testing
>
> 60735214881.391304  152025480.0060697824142.469570
> 152025840.0060651182200.208694
> 152026200.0060684367132.939130
> 152026560.0060676588613.008700
> 152026920.0060641816564.869570
> 152027280.0060604714824.233510
> 152027640.0060580042814.330440
> 152028000.0060536134542.469570
> 152028360.0060566323732.034780
> 152028720.0060578775249.252174
> 152029080.0060547382844.104350
> 152029440.0060536776546.802160
> 152029800.0060474342718.330440
> 152030160.0060452725477.286960
> 152030520.0060486821569.669560
> 152030880.0060247997139.995674
> 152031240.0060248432181.426090
> 152031600.0060217476247.373920
> 152031960.0060170744493.634780  152032320.00
>
> My code looks like below
>
> private void polynomialFitter(List pointlist) {
> final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
> final WeightedObservedPoints obs = new WeightedObservedPoints();
> for (List 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.00, 0.00
>
> But these does not seem to be quite correct. If I use the same dataset
> in Online
> Polynimal Regression  and
> in archanoid online regression  - both
> reports same value as 654623237474.68250993904929103762,
> 28.75921919628759991574, -0.023885199278
>
> Can someone let me know what is going wrong? I have seen this question
> 
>  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: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



[Math] How to do Polynomial Regression ?

2018-03-12 Thread Debraj Manna
Crossposting from stackoverflow

as I did not get any reply there

Can someone let me know how I can do Polynomial Regression with Apache Maths
 3.6.1
?

Below are the data points I used for my testing

60735214881.391304  152025480.0060697824142.469570
152025840.0060651182200.208694
152026200.0060684367132.939130
152026560.0060676588613.008700
152026920.0060641816564.869570
152027280.0060604714824.233510
152027640.0060580042814.330440
152028000.0060536134542.469570
152028360.0060566323732.034780
152028720.0060578775249.252174
152029080.0060547382844.104350
152029440.0060536776546.802160
152029800.0060474342718.330440
152030160.0060452725477.286960
152030520.0060486821569.669560
152030880.0060247997139.995674
152031240.0060248432181.426090
152031600.0060217476247.373920
152031960.0060170744493.634780  152032320.00

My code looks like below

private void polynomialFitter(List pointlist) {
final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(2);
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (List 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.00, 0.00

But these does not seem to be quite correct. If I use the same dataset
in Online
Polynimal Regression  and
in archanoid online regression  - both
reports same value as 654623237474.68250993904929103762,
28.75921919628759991574, -0.023885199278

Can someone let me know what is going wrong? I have seen this question

 but that is not helping me?

Thanks,