Class playlist probabilities
Joseph
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.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
We uploaded the class playlist. we saved the results as genre
counts.
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.
We checked the first 6 rows.
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
We changed the column genre to a factor type.
df$Genre <- as.factor(df$Genre)
head(df)
## # A tibble: 6 × 3
## Genre Artist Song
## <fct> <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
We counted the songs in each genre.
genre_counts<-df %>%count(df$Genre)
genre_counts
## # A tibble: 6 × 2
## `df$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
We changed the number of songs to a probability.
genre_counts<-genre_counts%>%mutate(prob = n/sum(n))
genre_counts
## # A tibble: 6 × 3
## `df$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
We rounded it to 2 decimal points.
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.
playlist<-sample_n(df,10)
playlist
## # A tibble: 10 × 3
## Genre Artist Song
## <fct> <chr> <chr>
## 1 Genre 5 - alt/indie/folk Skullcrusher Two Weeks in December
## 2 Genre 1 - hiphop/rap $uicideboy$ Diemonds
## 3 Genre 2 - pop/kpop/Latin d.ear Try Again
## 4 Genre 1 - hiphop/rap khalid 8teen
## 5 Genre 2 - pop/kpop/Latin Phantogram Fall In Love
## 6 Genre 1 - hiphop/rap Kanye West Carnival
## 7 Genre 1 - hiphop/rap DeJ Loaf Me u and Hennessy
## 8 Genre 1 - hiphop/rap Fetty Wap My way
## 9 Genre 3 - house/ska Gregory Isaacs Objection Overruled
## 10 Genre 5 - alt/indie/folk T e l e p a t h バウンス家の中でセックス
Now I will adjust this table to show me just the genres and their
probabilities.
playlist<-playlist %>% count(playlist$Genre)
playlist <- playlist %>% mutate(eprob=n/sum(n))
playlist
## # A tibble: 4 × 3
## `playlist$Genre` n eprob
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 5 0.5
## 2 Genre 2 - pop/kpop/Latin 2 0.2
## 3 Genre 3 - house/ska 1 0.1
## 4 Genre 5 - alt/indie/folk 2 0.2
The song genres are not represetitive of the songs in the playlist
becasue on the shuffle playlist is two times the amount as the other one
and has a bigger chance to get hiphop/rap.
the theoretical probability is less than the experimentle
probability. we could possibly make them similar by making my sample
bigger.
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 2 0.1
## 2 Genre 2 - pop/kpop/Latin 3 0.15
## 3 Genre 4 - rnb/soul 3 0.15
## 4 Genre 5 - alt/indie/folk 6 0.3
## 5 Genre 6 - country/rock 6 0.3
sample_n(df, 30) %>% count(Genre) %>% mutate(probability = round(n/sum(n), 2))
## # A tibble: 5 × 3
## Genre n probability
## <fct> <int> <dbl>
## 1 Genre 1 - hiphop/rap 9 0.3
## 2 Genre 2 - pop/kpop/Latin 4 0.13
## 3 Genre 4 - rnb/soul 4 0.13
## 4 Genre 5 - alt/indie/folk 11 0.37
## 5 Genre 6 - country/rock 2 0.07
sample_n(df, 30) %>% 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.43
## 2 Genre 2 - pop/kpop/Latin 6 0.2
## 3 Genre 4 - rnb/soul 1 0.03
## 4 Genre 5 - alt/indie/folk 6 0.2
## 5 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 15 0.38
## 2 Genre 2 - pop/kpop/Latin 3 0.07
## 3 Genre 3 - house/ska 1 0.03
## 4 Genre 4 - rnb/soul 3 0.07
## 5 Genre 5 - alt/indie/folk 9 0.22
## 6 Genre 6 - country/rock 9 0.22
Anylyze and synthisize
No the genres you hear played on shuffle do not represent the genres
of the songs in our class playlist becasue hipop rap is 0.40% while the
other is different.
experimentle discribes how frequent an event in an experiment
actually occurs. Theoretical describes how likely an event is to
occur.
It helped me anwser it by giving me a simulation to awnser it for.
and you could also use simulations for things like seeing how cars
work.
The piece that was the hardest was all of them, I was pretty lost
the entire time.
I feel proud after each assignment so same awsner, all of them.
College programming classes and what material comes with them.
I would not procrastinate the last assignment for so long next
time.
Why is coding so damn confusing.