# Apache Commons Math Linear Regression Question

3 messages
Open this post in threaded view
|

## 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