0% found this document useful (0 votes)
41 views

Chapter1 (Classification)

This document discusses supervised learning for classification using k-nearest neighbors (kNN) algorithms in R. It covers choosing the k value for kNN, tasks for classifying driverless car data, measuring similarity with distance functions, and preparing data for kNN through normalization. The instructor Brett Lantz provides examples of applying kNN in R using the knn function and discusses factors that impact choosing k and data preparation.

Uploaded by

110me0313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Chapter1 (Classification)

This document discusses supervised learning for classification using k-nearest neighbors (kNN) algorithms in R. It covers choosing the k value for kNN, tasks for classifying driverless car data, measuring similarity with distance functions, and preparing data for kNN through normalization. The instructor Brett Lantz provides examples of applying kNN in R using the knn function and discusses factors that impact choosing k and data preparation.

Uploaded by

110me0313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

DataCamp Supervised

Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

Classification with
nearest neighbors

Brett Lantz
Instructor
DataCamp Supervised Learning in R: Classification

Classification tasks for driverless cars


DataCamp Supervised Learning in R: Classification

Understanding Nearest Neighbors


DataCamp Supervised Learning in R: Classification

Measuring similarity with distance


DataCamp Supervised Learning in R: Classification

Applying nearest neighbors in R


library(class)
pred <- knn(training_data, testing_data, training_labels)
DataCamp Supervised Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

Let's practice!
DataCamp Supervised Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

What about the 'k' in


kNN?

Brett Lantz
Instructor
DataCamp Supervised Learning in R: Classification

Choosing 'k' neighbors


DataCamp Supervised Learning in R: Classification

Bigger 'k' is not always better


DataCamp Supervised Learning in R: Classification

Choosing 'k'
DataCamp Supervised Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

Let's practice!
DataCamp Supervised Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

Data preparation for


kNN

Brett Lantz
Instructor
DataCamp Supervised Learning in R: Classification

kNN assumes numeric data


DataCamp Supervised Learning in R: Classification

kNN benefits from normalized data


DataCamp Supervised Learning in R: Classification

Normalizing data in R
# define a min-max normalize() function
normalize <- function(x) {
return((x - min(x)) / (max(x) - min(x)))
}

# normalized version of r1
summary(normalize(signs$r1))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000 0.1935 0.3528 0.4046 0.6129 1.0000

# un-normalized version of r1
summary(signs$r1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
3.0 51.0 90.5 103.3 155.0 251.0
DataCamp Supervised Learning in R: Classification

SUPERVISED LEARNING IN R: CLASSIFICATION

Let's practice!

You might also like