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

Summary

Summary DSCI Tutorial 10 - tutorial_clustering_solution (2022)

 31 views  1 purchase

DSCI 100 - tutorial 10 clustering solutions

Preview 2 out of 10  pages

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

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.43. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76449 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.43  1x  sold
  • (0)
  Add to cart