O'Reilly logo

R Machine Learning Essentials by Michele Usuelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tuning the parameters

This section shows you how to improve the performance of KNN by tuning its parameters. We are dealing with the k parameter that defines the number of neighbors. Use these steps to identify the k parameter performing best:

  1. Define which values of k we will test. The KNN works locally, in the sense that given a new country flag it identifies just a few similar flags. How many of them should we use at most? Since there are less than 200 flags in total, we don't want to use more than 50 flags. Then, we should test each k between 1 and 50 and we can define arrayK containing the options:
    # define the k to test
    arrayK <- 1:50
  2. Define the number of iterations. For each k in arrayK, we need to build and validate the KNN a sufficiently ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required