From the course: Data Science for Java Developers

Unlock this course with a free trial

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

Calculating the closest data points

Calculating the closest data points - Java Tutorial

From the course: Data Science for Java Developers

Calculating the closest data points

- [Instructor] So the first thing we're going to do here is we're going to have a member variable which is going to be a list of data items and we're going to call that dataItems. And then for the constructor we're going to say public KNNClassifier and we're just going to initialize this list as an empty list. So we're going to say this.dataItems = new ArrayList, okay. And next up, we're going to have a method called addDataItem and that's just going to take a data item, which we'll nickname di, and we'll say this.dataItems.add(di). Okay, so we're just taking that data item and pushing it onto our data items list. So, that's pretty much the boiler plate for our classifier. The next step, which is the most exciting, is where we write a method which is going to return a Map with the generic types, string and integer and that method is going to be called classifyPoint. And this is the method where we're actually going to be able…

Contents