import weka.core.Instances; import weka.core.converters.ConverterUtils.DataSource; import weka.core.neighboursearch.LinearNNSearch; // Sourced from: // https://stackoverflow.com/questions/31350506/how-to-calculate-the-nearest-neighbors-using-weka-from-the-command-line public class WekaCLFindNN { public static void main(String[] args) throws Exception { //report that the code is running System.out.println("Weka Command Line Find Nearest " + args[0] + " Neighbors for each Instance in " + args[1]); //setup datasources, grab instances, and calculate the nearest neighbors DataSource source = new DataSource(""+args[1]); Instances instances = source.getDataSet(); weka.core.neighboursearch.LinearNNSearch knn = new LinearNNSearch(instances); //cycle through the dataset and get instances for the nearestneighbors for (int j=0; j