Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Summary DSCI Tutorial 6 - classification 1 (2022)

Puntuación
-
Vendido
2
Páginas
10
Subido en
11-04-2022
Escrito en
2021/2022

tutorial 6 solutions Classification 1

Institución
Grado

Vista previa del contenido

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

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
11 de abril de 2022
Número de páginas
10
Escrito en
2021/2022
Tipo
RESUMEN

Temas

$7.99
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF


Documento también disponible en un lote

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
travissmith1 UBC
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
97
Miembro desde
4 año
Número de seguidores
61
Documentos
36
Última venta
5 meses hace

3.6

16 reseñas

5
6
4
6
3
0
2
0
1
4

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes