Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary DSCI Tutorial 6 - classification 1 (2022)

Beoordeling
-
Verkocht
2
Pagina's
10
Geüpload op
11-04-2022
Geschreven in
2021/2022

tutorial 6 solutions Classification 1

Instelling
Vak

Voorbeeld van de inhoud

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).

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
11 april 2022
Aantal pagina's
10
Geschreven in
2021/2022
Type
SAMENVATTING

Onderwerpen

€7,14
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
travissmith1 UBC
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
97
Lid sinds
4 jaar
Aantal volgers
61
Documenten
36
Laatst verkocht
5 maanden geleden

3,6

16 beoordelingen

5
6
4
6
3
0
2
0
1
4

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen