100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary DSCI Tutorial 6 - classification 1 (2022)

Rating
-
Sold
2
Pages
10
Uploaded on
11-04-2022
Written in
2021/2022

tutorial 6 solutions Classification 1

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
April 11, 2022
Number of pages
10
Written in
2021/2022
Type
Summary

Subjects

Content preview

Tutorial 6: Classification
Lecture and Tutorial Learning Goals:
After completing this week's lecture and tutorial work, you will be able to:

Recognize situations where a simple classifier would be appropriate for making predictions.
Explain the k-nearest neighbour classification algorithm.
Interpret the output of a classifier.
Compute, by hand, the distance between points when there are two explanatory variables/predictors.
Describe what a training data set is and how it is used in classification.
In a dataset with two explanatory variables/predictors, perform k-nearest neighbour classification in R using tidymodels to predict the class of a
single new observation.


In [ ]:

### Run this cell before continuing.
library(tidyverse)
library(repr)
library(tidymodels)
options(repr.matrix.max.rows = 6)
source('tests.R')
source("cleanup.R")


Question 0.1 Multiple Choice:
{points: 1}

Before applying k-nearest neighbour to a classification task, we need to scale the data. What is the purpose of this step?

A. To help speed up the knn algorithm.

B. To convert all data observations to numeric values.

C. To ensure all data observations will be on a comparable scale and contribute equal shares to the calculation of the distance between points.

D. None of the above.

Assign your answer to an object called answer0.1 . Make sure the correct answer is an uppercase letter. Surround your answer with quotation marks
(e.g. "F" ).

Note: we typically standardize (i.e., scale and center) the data before doing classification. For the K-nearest neighbour algorithm specifically, centering
has no effect. But it doesn't hurt, and can help with other predictive data analyses, so we will do it below.


In [ ]:

# Replace the fail() with your answer.

### BEGIN SOLUTION
answer0.1 <- "C"
### END SOLUTION


In [ ]:
test_0.1()



1. Fruit Data Example
In the agricultural industry, cleaning, sorting, grading, and packaging food products are all necessary tasks in the post-harvest process. Products are
classified based on appearance, size and shape, attributes which helps determine the quality of the food. Sorting can be done by humans, but it is tedious
and time consuming. Automatic sorting could help save time and money. Images of the food products are captured and analysed to determine visual
characteristics.

The dataset (https://www.kaggle.com/mjamilmoughal/k-nearest-neighbor-classifier-to-predict-fruits/notebook) contains observations of fruit described with
four features 1) mass (in g) 2) width (in cm) 3) height (in cm) and 4) color score (on a scale from 0 - 1).

, Question 1.0
{points: 1}

Load the file, fruit_data.csv , into your notebook.

mutate() the fruit_name column such that it is a factor using the as_factor() function.

Assign your data to an object called fruit_data .


In [ ]:

### BEGIN SOLUTION
fruit_data <- read_csv("data/fruit_data.csv")
fruit_data <- fruit_data %>%
mutate(fruit_name = as_factor(fruit_name))
### END SOLUTION


In [ ]:

test_1.0()


Let's take a look at the first few observations in the fruit dataset. Run the cell below.


In [ ]:

# Run this cell.
fruit_data


Question 1.0.1 Multiple Choice:
{points: 1}

Which of the columns should we treat as categorical variables?

A. Fruit label, width, fruit subtype

B. Fruit name, color score, height

C. Fruit label, fruit subtype, fruit name

D. Color score, mass, width

Assign your answer to an object called answer1.0.1 . Make sure the correct answer is an uppercase letter. Remember to surround your answer with
quotation marks (e.g. "E" ).


In [ ]:

# Replace the fail() with your answer.

### BEGIN SOLUTION
answer1.0.1 <- "C"
### END SOLUTION


In [ ]:

test_1.0.1()


Run the cell below, and find the nearest neighbour based on mass and width to the first observation just by looking at the scatterplot (the first observation
has been circled for you).
$7.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
travissmith1 UBC
Follow You need to be logged in order to follow users or courses
Sold
97
Member since
4 year
Number of followers
61
Documents
36
Last sold
1 month ago

3.6

16 reviews

5
6
4
6
3
0
2
0
1
4

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions