Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the nearest neighbor in weka using java

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?

like image 335
kamikaze_pilot Avatar asked Jul 02 '11 02:07

kamikaze_pilot


People also ask

How can we use KNN in Weka?

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.

Which is the nearest Neighbour algorithm?

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.

What is nearest Neighbour clustering?

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.


1 Answers

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.

like image 125
iinception Avatar answered Sep 18 '22 07:09

iinception