Book Image

R Machine Learning Essentials

By : Michele Usuelli
Book Image

R Machine Learning Essentials

By: Michele Usuelli

Overview of this book

Table of Contents (15 chapters)
R Machine Learning Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Validating a machine learning model


Starting from a table describing the countries, flags and their language, the KNN estimates a new country language starting from its flag attributes. In this chapter, we will evaluate the performance of KNN.

Measuring the accuracy of an algorithm

We have already evaluated the algorithm accuracy by cross validating the estimated language. First, we split the data in two parts that are the training set and the test set. Then, we built the KNN algorithm using the training set in order to estimate the test set countries' language. Counting how many times the estimated language was correct, we defined an accuracy index as the percentage of correct guesses. The accuracy depends on which data we put into the test set. Since we randomly defined the training set countries, the accuracy changes every time we repeat the cross validation. Then, the result of this approach is not reliable.

The target of this chapter is to evaluate KNN using a reliable technique in the...