library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ 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("Class Playlist Clean DS4 - Sheet1.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
as.factor("Class Playlist Clean DS4 - Sheet1.csv")
## [1] Class Playlist Clean DS4 - Sheet1.csv
## Levels: Class Playlist Clean DS4 - Sheet1.csv
df$Genre <- as.factor(df$Genre)
df %>% count (Genre)
## # A tibble: 6 × 2
## Genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 58
## 2 Genre 2 - pop/kpop/Latin 25
## 3 Genre 3 - house/ska 5
## 4 Genre 4 - rnb/soul 14
## 5 Genre 5 - alt/indie/folk 45
## 6 Genre 6 - country/rock 28
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
##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, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 8 0.4
## 2 Genre 2 - pop/kpop/Latin 3 0.15
## 3 Genre 3 - house/ska 1 0.05
## 4 Genre 4 - rnb/soul 2 0.1
## 5 Genre 5 - alt/indie/folk 4 0.2
## 6 Genre 6 - country/rock 2 0.1
##Now I will adjust this table to show me just the genres and their probabilities
sample_n(df, 20) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 10 0.5
## 2 Genre 2 - pop/kpop/Latin 4 0.2
## 3 Genre 4 - rnb/soul 1 0.05
## 4 Genre 5 - alt/indie/folk 3 0.15
## 5 Genre 6 - country/rock 2 0.1
sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 12 0.4
## 2 Genre 2 - pop/kpop/Latin 3 0.1
## 3 Genre 3 - house/ska 1 0.03
## 4 Genre 4 - rnb/soul 1 0.03
## 5 Genre 5 - alt/indie/folk 9 0.3
## 6 Genre 6 - country/rock 4 0.13
sample_n(df, 40) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 6 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 13 0.32
## 2 Genre 2 - pop/kpop/Latin 8 0.2
## 3 Genre 3 - house/ska 2 0.05
## 4 Genre 4 - rnb/soul 4 0.1
## 5 Genre 5 - alt/indie/folk 8 0.2
## 6 Genre 6 - country/rock 5 0.12
##These song genres are somewhat repersenative of the genres in my playlist. It does have all my song genres on it, but there are also lots of other songs. Experimental was used to find the overall chance of certain genres being played and theoretical probability to find the likleyhood out of a set number of songs. They are differnt because our genres vary and some are more popular than others.depending on the set number of songs this nukmber can change becaus the number of songs in a certain genre vary.
##Analyze and Synthesize
##unit question: the songs played on shuffle do somewhat repersent the genres chose in class. the probabilities are similar, but our class genres are not evenly distrubuted, so certain genres play more often. We can see in our original spreadsheet that their is a disproportinate number of hiphop/wrap songs so we can determine that out probabiliy is going to be higher for those songs. Additionally when we look at the differnt size playlists we can see that hiphop still tends to be the most likley to be played, which is proportional to our class genre selection.
## Experiemntial + Theoretical Probability
##I learned that we use probabilty to determine the likelyhood of something happening. In our case, we used experimental to find the overall chance of certain genres being played and theoretical probability to find the likleyhood out of a set number of songs.
##Reflection
##the coding simulation helped me in answeing the unit question because i was able to see how the probabailty changed bases on how many songs and genres there were.
## the most challenging for me was the first code of experimential probabailty. but after i figured out this i kinda began to get it, and it got alot easier. I'm also most proud if this pirce of code because it was the most difficult for me to figure out. I would like to learn more about how companies who do programing incorperate personal data into these programs.
##if i were to do this again, i would try and get a better understanding from the start of just how the program worked bevause i was scared to mess up at first and then i realized the program is pretty forgiving