From the course: Data Science for Java Developers

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Finishing your KNN classifier

Finishing your KNN classifier - Java Tutorial

From the course: Data Science for Java Developers

Finishing your KNN classifier

- [Speaker] So what we're going to do now is we're going to remove this print line, and then we're going to say list string, and we're going to get the labels from the closest items here. All right, so we're going to say something like closest labels equals point distances dot sublist, and we're going to get a sublist that contains only this number of items. So that'll get the first X items, right, the first number of neighbors items from our point distances here, and then we're going to say zero, and then we'll say math dot min, either point distances dot size or number of neighbors, depending on which one is the smallest. This will just protect us from going out of bounds if we don't have enough point distances for some reason. So now that we have that sublist, we're going to convert it into a stream. We're going to map each pair to its key, right, which is going to be the classifier here. So we're going to say…

Contents