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 10 - tutorial_clustering_solution (2022)

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

DSCI 100 - tutorial 10 clustering solutions

Instelling
Vak

Voorbeeld van de inhoud

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

Describe a case where clustering would be an appropriate tool, and what insight it would bring from the data.
Explain the k-means clustering algorithm.
Interpret the output of a k-means cluster analysis.
Perform k-means clustering in R using k-means
Visualize the output of k-means clustering in R using a coloured scatter plot
Identify when it is necessary to scale variables before clustering and do this using R
Use the elbow method to choose the number of clusters for k-means
Describe advantages, limitations and assumptions of the kmeans clustering algorithm.


In [ ]:

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



1. Pokemon
We will be working with the Pokemon dataset from Kaggle, which can be found here. (https://www.kaggle.com/abcsds/pokemon) This dataset compiles
the statistics on 721 Pokemon. The information in this dataset includes Pokemon name, type, health points, attack strength, defensive strength, speed
points etc. These are values that apply to a Pokemon's abilities (higher values are better). We are interested in seeing if there are any sub-groups/clusters
of pokemon based on these statistics. And if so, how many sub-groups/clusters there are.




Source: https://media.giphy.com/media/3oEduV4SOS9mmmIOkw/giphy.gif (https://media.giphy.com/media/3oEduV4SOS9mmmIOkw/giphy.gif)


Question 1.0
{points: 1}

Use read_csv to load pokemon.csv from the data/ folder.

Assign your answer to an object called pm_data .


In [ ]:

### BEGIN SOLUTION
pm_data <- read_csv("data/pokemon.csv")
### END SOLUTION
pm_data


In [ ]:

test_1.0()

, Question 1.1
{points: 1}

Create a matrix of plots using ggpairs , choosing columns 5 to 11 (or equivalently, columns Total to Speed ) from pm_data . First use the
select function to extract columns "Total":"Speed" , and then pass the resulting dataframe to ggpairs to plot.

Assign your answer to an object called pm_pairs .


In [ ]:

### BEGIN SOLUTION
options(repr.plot.height = 10, repr.plot.width = 20)
pm_pairs <- pm_data %>% select("Total":"Speed") %>%
ggpairs(aes(alpha = 0.05)) +
theme(text = element_text(size = 20))

### END SOLUTION
pm_pairs

In [ ]:

test_1.1()


Question 1.2
{points: 1}

Select the columns Speed and Defense , creating a new dataframe with only those columns.

Assign your answer to an object named km_data .


In [ ]:

### BEGIN SOLUTION
km_data <- pm_data %>%
select(Speed, Defense)
### END SOLUTION
km_data

In [ ]:

test_1.2()


Question 1.3
{points: 1}

Make a scatterplot to visualize the relationship between Speed and Defense of the Pokemon. Put the Speed variable on the x-axis, and the
Defense variable on the y-axis.

Assign your plot to an object called pm_scatter . Don't forget to do everything needed to make an effective visualization.


In [ ]:

### BEGIN SOLUTION
options(repr.plot.height = 6, repr.plot.width = 6)
pm_scatter <- ggplot(km_data, aes(x = Speed, y = Defense)) +
geom_point(alpha = 0.4, size = 2) +
labs(x = "Speed Points",
y = "Defense Points") +
theme(text = element_text(size = 20))
### END SOLUTION
pm_scatter


In [ ]:

test_1.3()


Question 1.4.1
{points: 3}

We are going to cluster the Pokemon based on their Speed and Defense . Will it matter much for our clustering if we scale our variables? Is there any
argument against scaling here?

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