Just wrap with Arrays.toString():
System.out.println("The coefficients are: " + Arrays.toString(coeff));
You'll get this:
The coefficients are: [-1568.1599299988338, -3176.4210999976494,
-1606.2399999988156]
> -----Original Message-----
> From: Oscar Bastidas <[email protected]>
> Sent: Wednesday, January 08, 2020 2:12 PM
> To: [email protected]
> Subject: Apache Commons Math Linear Regression Question
>
> Hello,
>
> Would someone please tell me how I am supposed to acquire the actual
> numeric coefficients for a linear regression using the PolynomialCurveFitter
> class?
>
> Below is my code (it's supposed to be a simple example) and when I print out
> the variable that stores the coefficients, ("coeff" in the below
> example) what is printed to the command line is a strange code:
> *[D@1610302.*
>
> This happens regardless of the order of the polynomial I request.
>
> Would someone please help me with this? Thanks.
>
> *********************** CODE BELOW
> ******************************
>
> import java.util.*;
> import org.apache.commons.math3.fitting.PolynomialCurveFitter;
> import org.apache.commons.math3.fitting.*;
>
> public class MathTester
> {
> public static void main(String[] args) {
> // Testing linear regression
> final WeightedObservedPoints obs = new WeightedObservedPoints();
>
> // Acquiring data points
> obs.add(-1.00, 2.021170);
> obs.add(-0.99, 2.221135);
> obs.add(-0.98, 2.099852);
>
> // Instantiate 2nd degree polynomial fitting
> final PolynomialCurveFitter fitter =
> PolynomialCurveFitter.create(2);
>
> // Retrieve fitted coefficients of the fitted data
> final double[] coeff = fitter.fit(obs.toList());
>
> // Printing out coefficients
> System.out.println("The coefficients are: " + coeff);
>
> } // END 'main'
> } // END class
>
> **********************************************************
> **
>
> Oscar
>
> Oscar Bastidas, Ph.D.
> Postdoctoral Research Associate
> University of Minnesota
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]