First example – the k-nearest neighbors algorithm

The k-nearest neighbors algorithm is a simple machine-learning algorithm used for supervised classification. The main components of this algorithm are:

  • A train dataset: This dataset is formed by instances with one or more attributes that define every instance and a special attribute that determines the example or label of the instance
  • A distance metric: This metric is used to determine the distance (or similarity) between the instances of the train dataset and the new instances you want to classify
  • A test dataset: This dataset is used to measure the behavior of the algorithm

When it has to classify an instance, it calculates the distance against this instance and all the instances of the train dataset. ...

Get Mastering Concurrency Programming with Java 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.