KNearestNeighbours knn = new KNearestNeighbours(5, 2);
List<DoubleVector> features = new ArrayList<>();
List<DoubleVector> outcome = new ArrayList<>();
for (int i = 0; i < 10; i++) {
features.add(new SingleEntryDoubleVector(i));
double[] arr = new double[5];
arr[i % 5] = 1d;
outcome.add(new DenseDoubleVector(arr));
}
knn.train(features, outcome);
DoubleVector prediction = knn.predict(new SingleEntryDoubleVector(5));
assertArrayEquals(new double[] { 1d, 0, 0, 0, 1d }, prediction.toArray());
prediction = knn.predictProbability(new SingleEntryDoubleVector(5));
assertArrayEquals(new double[] { 0.5, 0, 0, 0, 0.5 }, prediction.toArray());
}