DS4 Song Simulation

Finn Halligan

load tidyverse

{r} install.packages ("tidyverse")

{r} library("tidyverse")

{r} df <- read_csv("Playlist - Clean.csv")

{r} df <- read_csv("Playlist - Clean.csv")

{r} df$Genre <- as.factor(df$Genre) df %>% count(Genre)

{r} df$Genre<-as.factor(df$Genre)

{r} head(df)

{r} df %>% count(Genre)

{r} genre_counts <- df %>% count(Genre)

{r} genre_counts <- genre_counts %>% mutate(prob = n/sum(n)) genre_counts

{r} genre_counts$prob <- round(genre_counts$prob, 2) genre_counts

Genre 1 - hiphop/rap has a 33% chance, Genre 2 - pop/kpop/Latin has a 14% chance Genre 3 - house/ska has 3% chance, Genre 4 - rnb/soul has a 8% chance, Genre 5 - alt/indie/folk has a 26% chance, Genre 6 - country/rock has a 16% of being the the genre.

4.4

Calculating Experimental Probabilities

{r} library(tidyverse)

import data

{r} df <- read_csv("Playlist - Clean.csv")

#check first few rows of data

{r} head(df)

Our next task is to simulate how shuffle works by pulling a random sample of songs and saving it as a new table.

{r} sample <- sample_n(df, 10) sample

Now I will adjust this table to show me just the genres and their probabilities.

{r} sample_counts <- sample %>% count(Genre) %>% mutate(probability = n/sum(n)) sample_counts

```{r} combined <- tibble(genre = genre_counts$genre, n = c(2, 3, 0, 1, 2, 2), probability = n/sum(n))

combined


```{r}
sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))

{r} sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))

{r echo=TRUE} sample_n(df, 50) %>% count(Genre) %>% mutate(probability = n/sum(n))

{r} sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))

{r} sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))

{r} sample_n(df, 40) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))

Analyze & Synthesize

For the most part they are similar the values in percentage are just a little off, but there deficiently different and its not the exact same.

Even for the the 40 hiphop is still a couple percentages off

I learned that probability doesn’t mean its going to happen exactly that way there still random factors.

Reflection

It helps support it because it give you the data to back it up. We also might use simulation to better understand how something works.

The hardest part was getting started. I felt most proud of the probabilities. I would like to learn more about how people calculate the probabilities for video games.

I would re read the instruction so I wouldn’t get stuck as many times.