How to get the nearest neighbor in weka using java

2019-03-19 19:01发布

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?

1条回答
Evening l夕情丶
2楼-- · 2019-03-19 19:24

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.

查看更多
登录 后发表回答