#In this project, the class was asked to submit 10 songs each that we liked and put them into a class playlist. We are looking at the probibility of a song playing when we shuffle the playlist and the probibility of the genre that it will be. The quation we are trying to answer is what is the likelihood of a song of each genre being played. The steps that you need to take for this programing is farly simpal. First you pick the number of songs you want to have it could be 5 or even 60. then you sourt the songs that were selected into their genres, and then lastly you couculate the probibility of the genre being played.
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.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ 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 - data_clean.csv")
## Rows: 144 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): genre, artist, title
##
## ℹ 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.
#Right above this we installed our class playlist which shows the genre, artist, and title. We put it in this thing called tidyverse whcih is a set of packages that make R easier to undrrstand for beginners.
df$genre <- as.factor(df$genre)
df2 <- df %>% count(genre)
df2
## # A tibble: 6 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 26
## 2 Genre 2 - pop/kpop/Latin 22
## 3 Genre 3 - house/ska 5
## 4 Genre 4 - rnb/soul 43
## 5 Genre 5 - alt/indie/folk 34
## 6 Genre 6 - country/rock 14
sum(df2$n)
## [1] 144
df3 <- df2 %>% mutate(prob=n/144)
df3
## # A tibble: 6 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 26 0.181
## 2 Genre 2 - pop/kpop/Latin 22 0.153
## 3 Genre 3 - house/ska 5 0.0347
## 4 Genre 4 - rnb/soul 43 0.299
## 5 Genre 5 - alt/indie/folk 34 0.236
## 6 Genre 6 - country/rock 14 0.0972
#I found out that the total number of songs is 144 and the main genre is rnb/soul. the probability of a rnb/soul song being played is 0.2986. The genre with the least amount of songs in our playlist is house/ska which has 5 songs. The probability of the genre being played is 0.0347. I wonder how much of a difference me choosing how many songs to shuffle will change the probibility of them being played.
shuffle <- sample_n(df,10)
shuffle
## # A tibble: 10 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Leon Bridges River
## 2 Genre 4 - rnb/soul Mariah the Scientist From A Woman
## 3 Genre 4 - rnb/soul Frank ocean pyramids
## 4 Genre 1 - hiphop/rap Alesso When I'm Gone
## 5 Genre 5 - alt/indie/folk Nirvana About A Girl
## 6 Genre 4 - rnb/soul Ciara Like a boy
## 7 Genre 4 - rnb/soul Thee sacred souls Future lover
## 8 Genre 6 - country/rock Dolly Parton 9 to 5
## 9 Genre 2 - pop/kpop/Latin J-Hope Safety Zone
## 10 Genre 2 - pop/kpop/Latin Taylor Swift The Man
shuffle <- shuffle %>% count(genre)
shuffle
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 1
## 2 Genre 2 - pop/kpop/Latin 2
## 3 Genre 4 - rnb/soul 5
## 4 Genre 5 - alt/indie/folk 1
## 5 Genre 6 - country/rock 1
shuffle <- shuffle %>% mutate(prob=n/10)
shuffle
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 1 0.1
## 2 Genre 2 - pop/kpop/Latin 2 0.2
## 3 Genre 4 - rnb/soul 5 0.5
## 4 Genre 5 - alt/indie/folk 1 0.1
## 5 Genre 6 - country/rock 1 0.1
shuffle <- sample_n(df,15)
shuffle
## # A tibble: 15 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Thee sacred souls For now
## 2 Genre 5 - alt/indie/folk Aidan Bissett Tripping Over Air
## 3 Genre 2 - pop/kpop/Latin J-Hope Safety Zone
## 4 Genre 5 - alt/indie/folk Lana Del Rey Million Dollar Man
## 5 Genre 1 - hiphop/rap Jcole Crooked smile
## 6 Genre 1 - hiphop/rap Kanye West Everything I Am
## 7 Genre 4 - rnb/soul Ella Mai Trip
## 8 Genre 3 - house/ska KAYTRANADA Vex Oh
## 9 Genre 1 - hiphop/rap Big Sean Beware
## 10 Genre 1 - hiphop/rap Mac Miller Surf
## 11 Genre 1 - hiphop/rap Kanye West Devil In A New Dress
## 12 Genre 2 - pop/kpop/Latin Post Malone Goodbyes
## 13 Genre 1 - hiphop/rap Isaiah Rashad Headshots
## 14 Genre 2 - pop/kpop/Latin Taylor Swift The Man
## 15 Genre 5 - alt/indie/folk Jeff Buckley Love you should have come over
shuffle <- shuffle %>% count(genre)
shuffle
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 6
## 2 Genre 2 - pop/kpop/Latin 3
## 3 Genre 3 - house/ska 1
## 4 Genre 4 - rnb/soul 2
## 5 Genre 5 - alt/indie/folk 3
shuffle <- shuffle %>% mutate(prob=n/15)
shuffle
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 6 0.4
## 2 Genre 2 - pop/kpop/Latin 3 0.2
## 3 Genre 3 - house/ska 1 0.0667
## 4 Genre 4 - rnb/soul 2 0.133
## 5 Genre 5 - alt/indie/folk 3 0.2
shuffle <- sample_n(df,7)
shuffle
## # A tibble: 7 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Frank ocean pyramids
## 2 Genre 2 - pop/kpop/Latin Taylor Swift The Man
## 3 Genre 1 - hiphop/rap Mac Miller ROS
## 4 Genre 4 - rnb/soul Leon Bridges River
## 5 Genre 5 - alt/indie/folk Crumb Plants
## 6 Genre 2 - pop/kpop/Latin J-Hope Safety Zone
## 7 Genre 1 - hiphop/rap Rod Wave Get Ready
shuffle <- shuffle %>% count(genre)
shuffle
## # A tibble: 4 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 2
## 2 Genre 2 - pop/kpop/Latin 2
## 3 Genre 4 - rnb/soul 2
## 4 Genre 5 - alt/indie/folk 1
shuffle <- shuffle %>% mutate(prob=n/7)
shuffle
## # A tibble: 4 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 2 0.286
## 2 Genre 2 - pop/kpop/Latin 2 0.286
## 3 Genre 4 - rnb/soul 2 0.286
## 4 Genre 5 - alt/indie/folk 1 0.143
shuffle <- sample_n(df,8)
shuffle
## # A tibble: 8 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Thee sacred souls Future lover
## 2 Genre 2 - pop/kpop/Latin Lauv I like me better
## 3 Genre 4 - rnb/soul Childish Gambino Redbone
## 4 Genre 1 - hiphop/rap Alesso When I'm Gone
## 5 Genre 6 - country/rock Dolly Parton 9 to 5
## 6 Genre 5 - alt/indie/folk Mat Kerekes Shoes
## 7 Genre 5 - alt/indie/folk Crumb Plants
## 8 Genre 4 - rnb/soul Sade Keep Looking
shuffle <- shuffle %>% count(genre)
shuffle
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 1
## 2 Genre 2 - pop/kpop/Latin 1
## 3 Genre 4 - rnb/soul 3
## 4 Genre 5 - alt/indie/folk 2
## 5 Genre 6 - country/rock 1
shuffle <- shuffle %>% mutate(prob=n/8)
shuffle
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 1 0.125
## 2 Genre 2 - pop/kpop/Latin 1 0.125
## 3 Genre 4 - rnb/soul 3 0.375
## 4 Genre 5 - alt/indie/folk 2 0.25
## 5 Genre 6 - country/rock 1 0.125
#After doing three different shuffles we can see that the probibility for each table actally very simalar. One of the things that is different out of the three tables is that not every genre is shown in each table. country/rock is only in the seconded table while all the other ones are in all three. This means that this doesn’t represent our palylist better because not all the genres are being used. I think nothing would change if we ran it 100 or 1000 times other then the fact tht we would be changing the amount of songs we pick.
#From the probiblity that we found for the total class playlist to the three tables that I picked the probiblitiy of a rnb/soul song being played is still the highest through out all the table we used. The lowest one was country/rock because it was only in one of the tables. For each table the likelihood of hiphop/rap being played is probably around 2.7 which is the highest, where the lowest is country/rock.
#reflection: The hardest part of the code to write was the probibility one because it just had a lot of parts in it that we hadn’t used before. the one I feel the best about would also be the probibility one since after the seconded one I understood it a lot more.This project has really made me like programing and I am interested in it but I don’t know what I would want to learn more about. aybe just programing in general. I wouldn’t do anything differently and I don’t have any questions about it.