DS4 Song Simulation

Max Wallace

We need to load tidyverse.

{r} install.packages("tidyverse")

{r} library(tidyverse)

Imported our class playlist data

{r} df <- read_csv("Playlist - Clean.csv")

Named the csv df

{r} head(df)

{r} df$genre <- as.factor(df$Genre)

After my data was loaded in, I counted how many songs were in each genre

{r} df %>% count(genre)

{r} genre_counts <-df %>% count(genre) head(genre_counts)

{r} genre_counts<-genre_counts %>% mutate(tprob=n/sum(n)) genre_counts

Next I calculated the theoretical probablilty by creating a new coulmn named tprob and using the mutate function.

```{r} genre_counts\(tprob <-round(genre_counts\)tprob,2) genre_counts


### Last I rounded my TPROB numbers to two decimal places so they were easier to interperet and read.

### The table shows me that there is a 33% chance of getting a Hip Hop/Rap song, 14% chance of getting a Pop/Kpop/Latin song, 3% of getting a House/Ska song, 8% chance for RnB/Soul song, 26% chance for alt/indie/folk and 16% chance of getting a country/rock song.
# 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
```{r}
playlist<-sample_n(df, 10)
playlist

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

{r} sample_counts<-playlist%>%count(playlist$Genre) sample_counts {r} sample_counts%>%mutate(prob=n/sum(n)) ## Yes my probability matches my playlist pretty well. The probability is .4 for art/indie/folk and there were four songs of this genre on my playlist. There was also a .3 experimental prob of hip hop and there were 3 songs on my playlist. ## When compared to my theoretical probabbility the biggest experimental was art/indie/folk but theoretical was only .1 running the experimental probability more times could maybe make them similar. {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} sample_n(df,40)%>%count(Genre) %>% mutate(probability = round(n/sum(n), 2)) {r} sample_n(df,50)%>%count(Genre) %>% mutate(probability = round(n/sum(n), 2)) {r} sample_n(df,60)%>%count(Genre) %>% mutate(probability = round(n/sum(n), 2)) {r} sample_n(df,70)%>%count(Genre) %>% mutate(probability = round(n/sum(n), 2)) # Analyze & Synthesize ### The genres played on shuffle represent the songs that will be played the most. The evidence I have to support this is my theoretical, experimental probability and the large sample playlists. I learned that experimental probability and theoretical probabilty are calculated differently and I learned how to calculate them. Almost all of the time the chance for generes hip hop and alternate will always be more likely to play. The porbability is mostly greater with theoretical and experimental. # Reflection ### The piece of code that was the most challenging was definitely the piping operator and the mutations. I had to ask Ms. Hood for a lot of help. I feel most proud of the project as a whole but probably the tprob the most. I would like to learn a lot more about everything, it is hard for me to grasp the concept as a whole. I feel like coding and CS is a weakness for me for sure. Not a lot of this makes sense to me at all. I liked learning more and I required a lot of assistance though. I know math and computer science is not my strong suit but I think it is really cool.