code: public static KNN<double[]> learn(double[][] x, int[] y, int k) {
          if (x.length != y.length) {
              throw new IllegalArgumentException(String.format("The sizes of X and Y don't match: %d != %d", x.length, y.length));
          }
  
          if (k < 1) {
              throw new IllegalArgumentException("Illegal k = " + k);
          }
  
          KNNSearch<double[], double[]> knn = null;
          if (x[0].length < 10) {
              knn = new KDTree<>(x, x);
          } else {
              knn = new CoverTree<>(x, new EuclideanDistance());
          }
          
          return new KNN<>(knn, y, k);
      }
docs: Learn the K-NN classifier from data of type double[].
  @param k the number of neighbors for classification.
  @param x training samples.
  @param y training labels in [0, c), where c is the number of classes.