How to get the nearest neighbor in weka using java

两盒软妹~` 提交于 2020-05-25 01:14:12

问题


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:


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.



来源:https://stackoverflow.com/questions/6554796/how-to-get-the-nearest-neighbor-in-weka-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!