100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary DSCI Tutorial 6 - classification 1 (2022) CA$10.87   Add to cart

Summary

Summary DSCI Tutorial 6 - classification 1 (2022)

 40 views  2 purchases

tutorial 6 solutions Classification 1

Preview 2 out of 10  pages

  • April 11, 2022
  • 10
  • 2021/2022
  • Summary
All documents for this subject (5)
avatar-seller
travissmith1
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).

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller travissmith1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for CA$10.87. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75632 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
CA$10.87  2x  sold
  • (0)
  Add to cart