Skip to content

Instantly share code, notes, and snippets.

@rofr
Created November 19, 2012 11:16
Show Gist options
  • Save rofr/4110189 to your computer and use it in GitHub Desktop.
Save rofr/4110189 to your computer and use it in GitHub Desktop.
Nearest Neighbor test driver
public static void main(String[] args) {
int[] sizes = new int[] { 5000, 10000, 50000, 100000,
1000000, 5000000, 10000000 };
for (int numInstances : sizes) {
List<LoanApplication> data = getRandomData(numInstances);
List<LoanApplication> testData = extractTestData(data, 100);
NearestNeighborClassifier<LoanApplication> classifier;
System.out.println("Size: " + numInstances);
classifier = new NearestNeighborClassifier<LoanApplication>(
data,
new LoanDistanceFunction(),
new LoanApplicationModeAverage(), 4);
long millis = measureTestRun(classifier, testData);
System.out.println("single threaded:" + millis);
classifier = new ParallelNearestNeighborClassifier<LoanApplication>(
data,
new LoanDistanceFunction(),
new LoanApplicationModeAverage(), 4);
millis = measureTestRun(classifier, testData);
System.out.println("multi threaded:" + millis);
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment