DS4 Song simulation

Max Morales

We need to load tidyverse

install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df <- read_csv("Playlist - Clean.csv")
## Rows: 175 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Genre, Artist, Song
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(df)
## # A tibble: 6 × 3
##   Genre                    Artist         Song                          
##   <chr>                    <chr>          <chr>                         
## 1 Genre 1 - hiphop/rap     8k             When you call                 
## 2 Genre 2 - pop/kpop/Latin Yonaguni       bad bunny                     
## 3 Genre 1 - hiphop/rap     $uicideboy$    Diemonds                      
## 4 Genre 1 - hiphop/rap     $uicideboy$    Not Even Ghosts Are This Empty
## 5 Genre 1 - hiphop/rap     03 Greedo      Trap House                    
## 6 Genre 5 - alt/indie/folk 10,000 Maniacs Trouble Me
df$Genre<-as.factor(df$Genre)
genre_counts <- df %>% count(Genre)
genre_counts <- genre_counts %>% mutate(prob = n/sum(n))
genre_counts
## # A tibble: 6 × 3
##   Genre                        n   prob
##   <fct>                    <int>  <dbl>
## 1 Genre 1 - hiphop/rap        58 0.331 
## 2 Genre 2 - pop/kpop/Latin    25 0.143 
## 3 Genre 3 -  house/ska         5 0.0286
## 4 Genre 4 -  rnb/soul         14 0.08  
## 5 Genre 5 - alt/indie/folk    45 0.257 
## 6 Genre 6 - country/rock      28 0.16
genre_counts$prob <- round(genre_counts$prob, 2)
genre_counts
## # A tibble: 6 × 3
##   Genre                        n  prob
##   <fct>                    <int> <dbl>
## 1 Genre 1 - hiphop/rap        58  0.33
## 2 Genre 2 - pop/kpop/Latin    25  0.14
## 3 Genre 3 -  house/ska         5  0.03
## 4 Genre 4 -  rnb/soul         14  0.08
## 5 Genre 5 - alt/indie/folk    45  0.26
## 6 Genre 6 - country/rock      28  0.16

33% of hiphop 14% Pop 3% house 8% RNB 26% Alt 16% Country/Rock

Calculating Experimental Probabilities

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

sample_n(df, 10)
## # A tibble: 10 × 3
##    Genre                    Artist          Song                     
##    <fct>                    <chr>           <chr>                    
##  1 Genre 1 - hiphop/rap     Drake           teenage fever            
##  2 Genre 2 - pop/kpop/Latin Seori           Running Through the Night
##  3 Genre 6 - country/rock   Life on mars    david bowie              
##  4 Genre 5 - alt/indie/folk Current Joys    New Flesh                
##  5 Genre 1 - hiphop/rap     EBE REEF        Trust                    
##  6 Genre 5 - alt/indie/folk T e l e p a t h バウンス家の中でセックス 
##  7 Genre 6 - country/rock   Ferry           STRIKE 3                 
##  8 Genre 5 - alt/indie/folk Surf Curse      Freaks                   
##  9 Genre 2 - pop/kpop/Latin bad bunny       lo siento bb             
## 10 Genre 5 - alt/indie/folk 10,000 Maniacs  Trouble Me

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

genre_counts %>% count(Genre)
## # A tibble: 6 × 2
##   Genre                        n
##   <fct>                    <int>
## 1 Genre 1 - hiphop/rap         1
## 2 Genre 2 - pop/kpop/Latin     1
## 3 Genre 3 -  house/ska         1
## 4 Genre 4 -  rnb/soul          1
## 5 Genre 5 - alt/indie/folk     1
## 6 Genre 6 - country/rock       1
genre_counts %>% count(Genre) %>% mutate(probability = n/sum(n))
## # A tibble: 6 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap         1       0.167
## 2 Genre 2 - pop/kpop/Latin     1       0.167
## 3 Genre 3 -  house/ska         1       0.167
## 4 Genre 4 -  rnb/soul          1       0.167
## 5 Genre 5 - alt/indie/folk     1       0.167
## 6 Genre 6 - country/rock       1       0.167
genre_counts
## # A tibble: 6 × 3
##   Genre                        n  prob
##   <fct>                    <int> <dbl>
## 1 Genre 1 - hiphop/rap        58  0.33
## 2 Genre 2 - pop/kpop/Latin    25  0.14
## 3 Genre 3 -  house/ska         5  0.03
## 4 Genre 4 -  rnb/soul         14  0.08
## 5 Genre 5 - alt/indie/folk    45  0.26
## 6 Genre 6 - country/rock      28  0.16

These might not reflect my playlists because i don’t listen to a lot of hiphop/rap or pop. I mostly have indie or rock. But i was correct about the fact that they are more popular and show up more often.

sample_n(df, 40) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
##   Genre                        n probability
##   <fct>                    <int>       <dbl>
## 1 Genre 1 - hiphop/rap        13        0.32
## 2 Genre 2 - pop/kpop/Latin     3        0.07
## 3 Genre 4 -  rnb/soul          3        0.07
## 4 Genre 5 - alt/indie/folk    13        0.32
## 5 Genre 6 - country/rock       8        0.2

Analyze and Synthesize

The genres that show up the most on shuffle might represent what most people in our class would listen to. Mostly rap and pop. Every time i simulated shuffle rap and pop were always on the top 2. I learned that if you have a large amount of data there seems to be one group that is larger, you’re most likely going to see it show up more often.

Reflection

it made the shuffling easier because it done automatically. The hardest ones were the longer ones but they were also the most fulfilling ones to get correct. Do people who code memorize all these inputs? like a language?