Quantcast
Channel: Pentaho Community Forums
Viewing all articles
Browse latest Browse all 16689

IBK gives a wrong result in my code

$
0
0
I have two data set, one for Training data set and another for Test data set.
I want to find the first nearest neighbor of the first instance in Test data set among Training data set, I wrote the following code:


trainData.setClassIndex(trainData.numAttributes() - 1);
testData.setClassIndex(testData.numAttributes() - 1);
IBk knn = new IBk();
String[] options = new String[2];
options[0]= "-E";
options[1]= "-I";
knn.setOptions(options);
knn.setKNN(1);
knn.setCrossValidate(true);
knn.buildClassifier(trainData);
int d = knn.getKNN();
Double c = knn.classifyInstance(testData.instance(0));
System.out.println(d);
System.out.println(c);
I don't know why I get the wrong result. Because the instance that I am looking for the nearest neighbor for, is in Training set as well and the result should have the same value as the Test instance in Training data set , but it's not!




Viewing all articles
Browse latest Browse all 16689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>