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