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.4.4 ✔ 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
For this project, each student submitted ten songs - all with different genres - into a class playlist. We will be trying to figure out whether the genres that we hear played on shuffle represent the genres of the songs in our class playlist.
playlist <- read_csv("/cloud/project/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.
playlist$genre<-as.factor(playlist$genre)
playlist %>% count(genre)
## # 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
genre_counts<- playlist %>% count(genre)
Before we started collecting the data from our classmates we had to simplify the genres we had because we had a lot of different genres and those were not easy to work with so we combined them- which was easy because there were a lot of subgenres. Combining the genres made the data easier to work with. Then we collected the classroom data and imported the data into Google Sheets where we cleaned up the data. We did this by simplifying the column names, erasing any songs that were repeating, and making it so the genres go from 1 to 6. After we were done with this, we finally imported the data into our rmarkdown.
genre_counts %>% mutate(prob=n/sum(n))
## # 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
prob <- genre_counts %>% mutate(prob=n/sum(n))
We started this section by creating the first table which has all the six genres and the amount of songs in that genre. We then wanted to see the probability of a particular genre playing. In order to do this, we added the second table table with another column - “prob”- that has the probability of a particular genre playing.
sample_n(playlist, 10)
## # A tibble: 10 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 2 - pop/kpop/Latin SOMA Monster Hunter
## 2 Genre 1 - hiphop/rap Mac Miller Surf
## 3 Genre 4 - rnb/soul sza snooze
## 4 Genre 1 - hiphop/rap Russ Handsomer
## 5 Genre 1 - hiphop/rap Ken carson Murda musik
## 6 Genre 5 - alt/indie/folk alkaline trio Scars
## 7 Genre 2 - pop/kpop/Latin Post Malone Goodbyes
## 8 Genre 5 - alt/indie/folk Lake Street Dive Hypotheticals
## 9 Genre 4 - rnb/soul Childish Gambino Redbone
## 10 Genre 1 - hiphop/rap Kanye west Missed call
sample1<- sample_n(playlist, 10)
genre_counts<- sample1 %>% count(genre)
genre_counts
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 3
## 2 Genre 2 - pop/kpop/Latin 1
## 3 Genre 4 - rnb/soul 1
## 4 Genre 5 - alt/indie/folk 4
## 5 Genre 6 - country/rock 1
genre_counts %>% mutate(prob=n/sum(n))
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 3 0.3
## 2 Genre 2 - pop/kpop/Latin 1 0.1
## 3 Genre 4 - rnb/soul 1 0.1
## 4 Genre 5 - alt/indie/folk 4 0.4
## 5 Genre 6 - country/rock 1 0.1
The song genres from the ten samples are not representative of the songs in the class playlist because it doesn’t have all the genres, it had three of them. But the sample does include the genres rnb/soul and alt/indie/folk which makes sense because those are the top genres. With the theoretical possibilities, that is when we found the probability of each genre playing with the whole class playlist. The probability numbers are smaller than the experimental probabilities - the probabilities from the ten-song sample. This is because with the theoretical possibility, we have more genres, six, and the numbers of songs in those genres are a lot bigger compared to the experimental probability we only have three genres and ten songs. To make them more similar we would like another sample, with more songs, this may also increase the number of genres as well. This relates to the analyze and synthesis step of the data science process because we are looking at the experimental and theoretical probability and connecting them.
sample_n(playlist, 15)
## # A tibble: 15 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Jcole In the morning
## 2 Genre 2 - pop/kpop/Latin Lana Del Rey Cinnamon Girl
## 3 Genre 5 - alt/indie/folk Mat Kerekes Shoes
## 4 Genre 5 - alt/indie/folk Cherry Glazerr Soft like a flower
## 5 Genre 4 - rnb/soul Brent Faiyaz Missin Out
## 6 Genre 5 - alt/indie/folk The Weather Machine Back O'er Oregon
## 7 Genre 5 - alt/indie/folk Cherry Glazerr Soft Drink
## 8 Genre 6 - country/rock Citizen Jet
## 9 Genre 1 - hiphop/rap Kendrick Lamar Money Trees
## 10 Genre 6 - country/rock Citizen World
## 11 Genre 5 - alt/indie/folk The Internet Under Control
## 12 Genre 5 - alt/indie/folk Jeff Buckley Love you should have come over
## 13 Genre 6 - country/rock Kacey Musgraves Die Fun
## 14 Genre 4 - rnb/soul Nico Segal Sunday Candy
## 15 Genre 5 - alt/indie/folk Sorry Showgirl
sample2<- sample_n(playlist, 15)
genre_counts<- sample2 %>% count(genre)
genre_counts
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 2
## 2 Genre 2 - pop/kpop/Latin 2
## 3 Genre 4 - rnb/soul 4
## 4 Genre 5 - alt/indie/folk 6
## 5 Genre 6 - country/rock 1
genre_counts %>% mutate(prob=n/sum(n))
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 2 0.133
## 2 Genre 2 - pop/kpop/Latin 2 0.133
## 3 Genre 4 - rnb/soul 4 0.267
## 4 Genre 5 - alt/indie/folk 6 0.4
## 5 Genre 6 - country/rock 1 0.0667
sample_n(playlist, 20)
## # A tibble: 20 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 4 - rnb/soul Brent faiyaz Rehab
## 2 Genre 4 - rnb/soul Tayc Le Miel
## 3 Genre 5 - alt/indie/folk Crumb Plants
## 4 Genre 1 - hiphop/rap Russ Handsomer
## 5 Genre 1 - hiphop/rap Mac Miller ROS
## 6 Genre 2 - pop/kpop/Latin ariana grande everytime
## 7 Genre 5 - alt/indie/folk wilco heavy metal drummer
## 8 Genre 5 - alt/indie/folk Cherry Glazerr Soft like a flower
## 9 Genre 1 - hiphop/rap Lakeyah Worst thing
## 10 Genre 4 - rnb/soul Solange Don't Touch My Hair
## 11 Genre 1 - hiphop/rap Rod Wave Get Ready
## 12 Genre 5 - alt/indie/folk Death Cab for Cutie No Sunlight
## 13 Genre 5 - alt/indie/folk The Weather Machine Back O'er Oregon
## 14 Genre 2 - pop/kpop/Latin Alec Benjamin Devil Doesn't Bargain
## 15 Genre 1 - hiphop/rap Clipse Ma, I don't love her
## 16 Genre 6 - country/rock Dolly parton Jolene
## 17 Genre 4 - rnb/soul Drake Look what You’ve done
## 18 Genre 2 - pop/kpop/Latin Franglish Trop Parler
## 19 Genre 2 - pop/kpop/Latin Taylor Swift The Man
## 20 Genre 2 - pop/kpop/Latin SOMA Monster Hunter
sample3<-sample_n(playlist, 20)
genre_counts<- sample3 %>% count(genre)
genre_counts
## # A tibble: 5 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 4
## 2 Genre 2 - pop/kpop/Latin 3
## 3 Genre 4 - rnb/soul 6
## 4 Genre 5 - alt/indie/folk 4
## 5 Genre 6 - country/rock 3
genre_counts %>% mutate(prob=n/sum(n))
## # A tibble: 5 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 4 0.2
## 2 Genre 2 - pop/kpop/Latin 3 0.15
## 3 Genre 4 - rnb/soul 6 0.3
## 4 Genre 5 - alt/indie/folk 4 0.2
## 5 Genre 6 - country/rock 3 0.15
sample_n(playlist, 25)
## # A tibble: 25 × 3
## genre artist title
## <fct> <chr> <chr>
## 1 Genre 5 - alt/indie/folk Aidan Bissett Tripping Over Air
## 2 Genre 4 - rnb/soul Ciara Like a boy
## 3 Genre 2 - pop/kpop/Latin Lana Del Rey Cinnamon Girl
## 4 Genre 4 - rnb/soul Leon Bridges River
## 5 Genre 2 - pop/kpop/Latin SOMA Monster Hunter
## 6 Genre 5 - alt/indie/folk Nirvana About A Girl
## 7 Genre 4 - rnb/soul Destinys child Say my name
## 8 Genre 4 - rnb/soul Kieth Sweat Get up on it
## 9 Genre 4 - rnb/soul Solange Don't Touch My Hair
## 10 Genre 2 - pop/kpop/Latin J-Hope Safety Zone
## # ℹ 15 more rows
sample4<-sample_n(playlist, 25)
genre_counts<- sample4 %>% count(genre)
genre_counts
## # A tibble: 6 × 2
## genre n
## <fct> <int>
## 1 Genre 1 - hiphop/rap 3
## 2 Genre 2 - pop/kpop/Latin 3
## 3 Genre 3 - house/ska 1
## 4 Genre 4 - rnb/soul 8
## 5 Genre 5 - alt/indie/folk 6
## 6 Genre 6 - country/rock 4
genre_counts %>% mutate(prob=n/sum(n))
## # A tibble: 6 × 3
## genre n prob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 3 0.12
## 2 Genre 2 - pop/kpop/Latin 3 0.12
## 3 Genre 3 - house/ska 1 0.04
## 4 Genre 4 - rnb/soul 8 0.32
## 5 Genre 5 - alt/indie/folk 6 0.24
## 6 Genre 6 - country/rock 4 0.16
As I increased the number for my experimental probability, the probability number for a specific genre playing increased because we have more songs and more genres to work with, unlike with our first sample.
While listening to the class playlist on Shuffle my tablemates and I heard a lot of RnB/soul, alt/indie/folk, hip hop/rap. This makes sense because those genres have the most songs, as we saw on the first data table we made that contained the numbers of songs in each genre. Hip-hop/Rap has 26 songs, rnb/soul has 43 songs, and alt/indie/folk has 34 songs. Of course, we also heard a lot of other songs from other genres as well but those were less frequent
Theoretical probability is how likely an event is to appear and we used this to determine the probability of a certain genre playing from our class playlist. An experimental probability is when you run several trials to try and figure out the probability of an event, to see if there is a pattern. For this situation, we generated a certain number of songs randomly four times. I randomly generated 10, 15, 20, and 25 songs. We did this to figure out the likelihood of each genre in the class playlist and to see if there is a pattern on what genres are likely to play the most. 3. Consider the difference between the genres in the shuffled playlist and in the class playlist. What do you notice about the variability of genres represented and why do you think this occurs?
As we started calculating the experimental probability, we started with small numbers(10) and because of this not all the genres in the class playlist were represented, there were only three - rnb/soul, alt/indie/folk, and country/rock. But as I started increasing the number of songs being shuffled, more genres started showing up because there were more songs to work with. For example, when I shuffled 25 songs all the genres in the class playlist were represented.
We first started this project by collecting data from various students on the songs they listen to and specifically the different genres. Then the data was put on google sheets and we worked to clean it up so that it was easier to work with. We made the column names simpler, we had multiple genres so we combined them into smaller pieces so it is easier to manage. Then when our data was cleaned up we transferred it to the posit cloud and created a new rmarkdown which we then put our data into. We then made the data into a visual, a data table that showed the genres and the amount of songs in specific genres. From there we were able to calculate the probability and calculate the experimental probability. And from those we were able to draw a conclusion about our data and the relationship between the amount of songs in each genre and the probability of a genre playing.
The coding simulation supported me in answering the nit question because it gave me the probability of each genre playing if it was shuffled. You can also use simulations to make suggestions.
What piece of code was most challenging for you to write? The code for adding a new column was hard. Although I found the code on the R cheat sheet, the last part of the code was hard for me to figure out.
What piece of your code do you feel most proud of? Why?
I feel most proud of just making the tables because those were hard for me to do as well but I was able to do them and I made quite a few of them as well.
What is something in programming that you would like to learn more about? I’d like to learn more specifically how to identify errors and how to fix them.
Is there anything you would do differently if you were to do this again?
I would work harder to try and figure out answers to some of the coding issues myself because I got frustrated easily when they wouldn’t work then I would ask for help without trying further.