@Test public void testCPU() { System.out.println("CPU"); double[] rmse = Bootstrap.regression(100, CPU.formula, CPU.data, (f, x) -> RegressionTree.fit(f, x)); System.out.println("100-fold bootstrap RMSE average = " + MathEx.mean(rmse)); System.out.println("100-fold bootstrap RMSE std.dev = " + MathEx.sd(rmse)); }
public <T> double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer) { double[] rmse = new double[k]; for (int i = 0; i < k; i++) { T[] trainx = MathEx.slice(x, train[i]); double[] trainy = MathEx.slice(y, train[i]); T[] testx = MathEx.slice(x, test[i]); double[] testy = MathEx.slice(y, test[i]); Regression<T> model = trainer.apply(trainx, trainy); double[] prediction = model.predict(testx); rmse[i] = RMSE.of(testy, prediction); } return rmse; }
Bootstrap { public <T> double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer) { double[] rmse = new double[k]; for (int i = 0; i < k; i++) { T[] trainx = MathEx.slice(x, train[i]); double[] trainy = MathEx.slice(y, train[i]); T[] testx = MathEx.slice(x, test[i]); double[] testy = MathEx.slice(y, test[i]); Regression<T> model = trainer.apply(trainx, trainy); double[] prediction = model.predict(testx); rmse[i] = RMSE.of(testy, prediction); } return rmse; } }
Bootstrap { public <T> double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer) { double[] rmse = new double[k]; for (int i = 0; i < k; i++) { T[] trainx = MathEx.slice(x, train[i]); double[] trainy = MathEx.slice(y, train[i]); T[] testx = MathEx.slice(x, test[i]); double[] testy = MathEx.slice(y, test[i]); Regression<T> model = trainer.apply(trainx, trainy); double[] prediction = model.predict(testx); rmse[i] = RMSE.of(testy, prediction); } return rmse; } Bootstrap(int n, int k); }
Bootstrap { public <T> double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer) { double[] rmse = new double[k]; for (int i = 0; i < k; i++) { T[] trainx = MathEx.slice(x, train[i]); double[] trainy = MathEx.slice(y, train[i]); T[] testx = MathEx.slice(x, test[i]); double[] testy = MathEx.slice(y, test[i]); Regression<T> model = trainer.apply(trainx, trainy); double[] prediction = model.predict(testx); rmse[i] = RMSE.of(testy, prediction); } return rmse; } Bootstrap(int n, int k); double[] classification(T[] x, int[] y, BiFunction<T[], int[], Classifier<T>> trainer); double[] classification(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer); double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer); double[] regression(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameRegression> trainer); static double[] classification(int k, T[] x, int[] y, BiFunction<T[], int[], Classifier<T>> trainer); static double[] classification(int k, Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer); static double[] regression(int k, T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer); static double[] regression(int k, Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameRegression> trainer); }
Bootstrap { public <T> double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer) { double[] rmse = new double[k]; for (int i = 0; i < k; i++) { T[] trainx = MathEx.slice(x, train[i]); double[] trainy = MathEx.slice(y, train[i]); T[] testx = MathEx.slice(x, test[i]); double[] testy = MathEx.slice(y, test[i]); Regression<T> model = trainer.apply(trainx, trainy); double[] prediction = model.predict(testx); rmse[i] = RMSE.of(testy, prediction); } return rmse; } Bootstrap(int n, int k); double[] classification(T[] x, int[] y, BiFunction<T[], int[], Classifier<T>> trainer); double[] classification(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer); double[] regression(T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer); double[] regression(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameRegression> trainer); static double[] classification(int k, T[] x, int[] y, BiFunction<T[], int[], Classifier<T>> trainer); static double[] classification(int k, Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer); static double[] regression(int k, T[] x, double[] y, BiFunction<T[], double[], Regression<T>> trainer); static double[] regression(int k, Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameRegression> trainer); final int k; final int[][] train; final int[][] test; }