Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary DSCI Tutorial 10 - tutorial_clustering_solution (2022)

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

DSCI 100 - tutorial 10 clustering solutions

Institution
Module

Content preview

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?

Written for

Institution
Study
Module

Document information

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

Subjects

£6.22
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


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
5 months ago

3.6

16 reviews

5
6
4
6
3
0
2
0
1
4

Trending documents

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 exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions