I've been trying to use the Ibk nearest neighbor algorithm that goes together with the weka machine learning library.
I know how to classify instances, but I want to implement the collaborative filtering feature so I need to actually get the list of actual objects that are nearest to the object of interest.
How would I actually do so in weka using its java API?
k might be 3 or 5, and you look for the 3 or the 5 nearest neighbors and choose the majority class amongst those when classifying an unknown point. That's the k-nearest-neighbor method. In Weka, it's called IBk (instance-based learning with parameter k), and it's in the lazy class.
The k-nearest neighbors algorithm, also known as KNN or k-NN, is a non-parametric, supervised learning classifier, which uses proximity to make classifications or predictions about the grouping of an individual data point.
The nearest-neighbor chain algorithm constructs a clustering in time proportional to the square of the number of points to be clustered. This is also proportional to the size of its input, when the input is provided in the form of an explicit distance matrix.
How about this one
weka.core.neighboursearch.LinearNNSearch knn = new LinearNNSearch(
trainingInstances);
//do other stuff
Instances nearestInstances= knn.kNearestNeighbours(target, 3)
Here is the API documentation that you can refer to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With