Examples of OLSMultipleLinearRegression


Examples of org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression

public class OLSAlgorithm
  extends LJavaAlgorithm<EmptyParams, TrainingData, Double[], Double[], Double> {

  public Double[] train(TrainingData data) {
    OLSMultipleLinearRegression r = new OLSMultipleLinearRegression();
    // Convert Double[][] to double[][]
    double[][] x = new double[data.r][data.c];
    double[] y = new double[data.r];

    for (int i=0; i<data.r; i++) {
      for (int j=0; j<data.c; j++) {
        x[i][j] = data.x[i][j].doubleValue();
      }
      y[i] = data.y[i].doubleValue();
    }

    r.newSampleData(y, x);
    // Fixme. Add intercept
    double[] p = r.estimateRegressionParameters();
    Double[] pp = new Double[data.c];
    for (int j=0; j<data.c; j++) {
      pp[j] = p[j];
    }
    System.out.println("Regression Algo: " + Arrays.toString(pp));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.