@Test public void testToy() { double[][] A = { {1, 0, 0, 0.5}, {0, 1, 0.2, 0.3}, {1, 0.5, 0.2, 0.3}, {0, 0.1, 0, 0.2}, {0, 0.1, 1, 0.2} }; double[] y = {6, 5.2, 6.2, 5, 6}; DataFrame df = DataFrame.of(A).merge(DoubleVector.of("y", y)); Formula formula = Formula.lhs("y"); LinearModel model = ElasticNet.fit(formula, df, 0.1, 0.001); System.out.println(model); double[] prediction = Validation.test(model, df); double rmse = RMSE.of(y, prediction); System.out.println("RMSE = " + rmse); assertEquals(5.1486, model.intercept(), 1E-4); double[] w = {0.8978, -0.0873, 0.8416, -0.1121}; for (int i = 0; i < w.length; i++) { assertEquals(w[i], model.coefficients()[i], 1E-4); } }
public static LinearModel fit(Formula formula, DataFrame data, Properties prop) { double lambda1 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda1")); double lambda2 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda2")); double tol = Double.valueOf(prop.getProperty("smile.elastic.net.tolerance", "1E-4")); int maxIter = Integer.valueOf(prop.getProperty("smile.elastic.net.max.iterations", "1000")); return fit(formula, data, lambda1, lambda2, tol, maxIter); }
ElasticNet { public static LinearModel fit(Formula formula, DataFrame data, Properties prop) { double lambda1 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda1")); double lambda2 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda2")); double tol = Double.valueOf(prop.getProperty("smile.elastic.net.tolerance", "1E-4")); int maxIter = Integer.valueOf(prop.getProperty("smile.elastic.net.max.iterations", "1000")); return fit(formula, data, lambda1, lambda2, tol, maxIter); } }
ElasticNet { public static LinearModel fit(Formula formula, DataFrame data, Properties prop) { double lambda1 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda1")); double lambda2 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda2")); double tol = Double.valueOf(prop.getProperty("smile.elastic.net.tolerance", "1E-4")); int maxIter = Integer.valueOf(prop.getProperty("smile.elastic.net.max.iterations", "1000")); return fit(formula, data, lambda1, lambda2, tol, maxIter); }  }
ElasticNet { public static LinearModel fit(Formula formula, DataFrame data, Properties prop) { double lambda1 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda1")); double lambda2 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda2")); double tol = Double.valueOf(prop.getProperty("smile.elastic.net.tolerance", "1E-4")); int maxIter = Integer.valueOf(prop.getProperty("smile.elastic.net.max.iterations", "1000")); return fit(formula, data, lambda1, lambda2, tol, maxIter); }  static LinearModel fit(Formula formula, DataFrame data, Properties prop); static LinearModel fit(Formula formula, DataFrame data, double lambda1, double lambda2); static LinearModel fit(Formula formula, DataFrame data, double lambda1, double lambda2, double tol, int maxIter); }
ElasticNet { public static LinearModel fit(Formula formula, DataFrame data, Properties prop) { double lambda1 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda1")); double lambda2 = Double.valueOf(prop.getProperty("smile.elastic.net.lambda2")); double tol = Double.valueOf(prop.getProperty("smile.elastic.net.tolerance", "1E-4")); int maxIter = Integer.valueOf(prop.getProperty("smile.elastic.net.max.iterations", "1000")); return fit(formula, data, lambda1, lambda2, tol, maxIter); }  static LinearModel fit(Formula formula, DataFrame data, Properties prop); static LinearModel fit(Formula formula, DataFrame data, double lambda1, double lambda2); static LinearModel fit(Formula formula, DataFrame data, double lambda1, double lambda2, double tol, int maxIter);  }