@Test public void testWeather() { System.out.println("Weather"); int[] prediction = LOOCV.classification(WeatherNominal.onehot, WeatherNominal.y, (x, y) -> KNN.fit(x, y)); int error = Error.of(WeatherNominal.y, prediction); System.out.println("1-NN Error = " + error); assertEquals(7, error); prediction = LOOCV.classification(WeatherNominal.onehot, WeatherNominal.y, (x, y) -> KNN.fit(x, y, 3)); error = Error.of(WeatherNominal.y, prediction); System.out.println("3-NN Error = " + error); assertEquals(5, error); prediction = LOOCV.classification(WeatherNominal.onehot, WeatherNominal.y, (x, y) -> KNN.fit(x, y, 5)); error = Error.of(WeatherNominal.y, prediction); System.out.println("5-NN Error = " + error); assertEquals(4, error); prediction = LOOCV.classification(WeatherNominal.onehot, WeatherNominal.y, (x, y) -> KNN.fit(x, y,7)); error = Error.of(WeatherNominal.y, prediction); System.out.println("7-NN Error = " + error); assertEquals(5, error); }
public static <T> KNN<T> fit(T[] x, int[] y, Distance<T> distance) { return fit(x, y, 1, distance); }
KNN implements SoftClassifier<T> { public static <T> KNN<T> fit(T[] x, int[] y, Distance<T> distance) { return fit(x, y, 1, distance); } }
KNN implements SoftClassifier<T> { public static <T> KNN<T> fit(T[] x, int[] y, Distance<T> distance) { return fit(x, y, 1, distance); } KNN(KNNSearch<T, T> knn, int[] y, int k); }
KNN implements SoftClassifier<T> { public static <T> KNN<T> fit(T[] x, int[] y, Distance<T> distance) { return fit(x, y, 1, distance); } KNN(KNNSearch<T, T> knn, int[] y, int k); static KNN<T> fit(T[] x, int[] y, Distance<T> distance); static KNN<T> fit(T[] x, int[] y, int k, Distance<T> distance); static KNN<double[]> fit(double[][] x, int[] y); static KNN<double[]> fit(double[][] x, int[] y, int k); @Override int predict(T x); @Override int predict(T x, double[] posteriori); }
KNN implements SoftClassifier<T> { public static <T> KNN<T> fit(T[] x, int[] y, Distance<T> distance) { return fit(x, y, 1, distance); } KNN(KNNSearch<T, T> knn, int[] y, int k); static KNN<T> fit(T[] x, int[] y, Distance<T> distance); static KNN<T> fit(T[] x, int[] y, int k, Distance<T> distance); static KNN<double[]> fit(double[][] x, int[] y); static KNN<double[]> fit(double[][] x, int[] y, int k); @Override int predict(T x); @Override int predict(T x, double[] posteriori);  }