| Information | Note | |-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Name | Mixed assignment 2 | | Type | Type 1 | | Value | 14% | | Due | This untimed submission must be submitted by 4:30 p.m. ET Wednesday, Apr 07 | | Submission link | PDF & RMD: https://q.utoronto.ca/courses/204826/assignments/506350 | | Accommodations and extension policy | If you miss a type 1 assessment due to illness or a serious personal emergency, please complete this form within ONE week of the due date of the assignment (i.e. the end of the timed assessment window). | | | |
Mixed assessment 1 has two components:
Untimed guided analysis (this)
Timed assessment (50 minutes; 24-hour assessment window is 4:30 p.m. ET Tuesday, Apr 07 to 4:30 p.m. ET Wednesday, Apr 07)
Spotify is a streaming music service. It provides an API for accessing its data and spotifyr^[Charlie Thompson, Josiah Parry, Donal Phipps and Tom Wolff (2020).
spotifyr: R Wrapper for the 'Spotify' Web API. R package version 2.1.1.
http://github.com/charlie86/spotifyr] is an R package that helps facilitate this.
Data on a range range of Korean pop ("K-pop") and Jazz artists and their tracks was collected through from the Spotify API. You will have a sample of this data to work with. Sampling occurred at the artist level. All tracks retrieved for selected artists were included.
|variable |class |description | |:---|:---|:-----------| |id | numeric | Unique ID (arbitrary) | |genre | | Whether the song is jazz or k-pop | |artist_name |character | Song artist| |artist_popularity |double | Popularity score (0-100) based on track play and recency. Higher is better | |artist_followers |double | Number of people who 'follow' the artist on Spotify| |album_name |character| Name of the album the song if from | |album_release_date |character | Date when album released | |album_release_year |double | Year of album release| |track_name |character | Song name| |danceability |double | Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable. | |energy |double | Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy. | |loudness |double | The overall loudness of a track in decibels (dB). Loudness values are averaged across the entire track and are useful for comparing relative loudness of tracks. Loudness is the quality of a sound that is the primary psychological correlate of physical strength (amplitude). Values typical range between -60 and 0 db.| |mode |double | Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. Major is represented by 1 and minor is 0.| |speechiness |double | Speechiness detects the presence of spoken words in a track. The more exclusively speech-like the recording (e.g. talk show, audio book, poetry), the closer to 1.0 the attribute value. Values above 0.66 describe tracks that are probably made entirely of spoken words. Values between 0.33 and 0.66 describe tracks that may contain both music and speech, either in sections or layered, including such cases as rap music. Values below 0.33 most likely represent music and other non-speech-like tracks. | |acousticness |double | A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.| |instrumentalness |double | Predicts whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The closer the instrumentalness value is to 1.0, the greater likelihood the track contains no vocal content. Values above 0.5 are intended to represent instrumental tracks, but confidence is higher as the value approaches 1.0. | |liveness |double | Detects the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live. A value above 0.8 provides strong likelihood that the track is live. | |valence |double | A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry). | |tempo |double | The overall estimated tempo of a track in beats per minute (BPM). In musical terminology, tempo is the speed or pace of a given piece and derives directly from the average beat duration. | |key_name |character |Key | |mode_name |character |Mode indicates the modality (major or minor) of a track, the type of scale from which its melodic content is derived. |
yaml at the top of this document to have your name and your student ID. There are TWO places you need to do this for each one, probably on lines 4 and 12. I.e., replace the square brackets and everything inside them with the appropriate details. Your student ID is all numbers (usually 10, sometimes 8 or 9), it is NOT your UTORid. get_my_songs().# You may need to reinstall the package # (if you're working the JupyterHub across multiple sessions) # devtools::install_github("sta303-bolton/sta303mixed2") library(sta303mixed2) library(lme4) library(mgcv)
get_my_songs(1001234567)
is_kpop to your training_data set. This variable should take the value 1 if the track is from the 'k-pop' genre and 0 if it is from the jazz genre.likely_live to your training_data set. This variable should take the value 1 if the track has a liveness score of greater than 0.8.training_data, create a table of genre by mode_name. I.e., have genre on the rows and mode_name on the columns. You can use table or xtabs.training_data, calculate the probability that a song is in a minor mode, given that it is a K-pop song.training_data, calculate the probability that a song chosen at random from your sample is a Jazz song in a major key.training_data, calculate the odds ratio for a song being in a major key given it is K-pop vs Jazz.training_data, calculate the odds ratio for a song being Jazz, given that it is likely live vs not.Note: You do not have to do any further model tweaking other than the instructions provided.
Using the training_data, fit an appropriate GLM to predict whether or not a song is 'K-pop'. Use artist_popularity, danceability, valence as your predictors.
Name your model: model_1.
summary() on your model.Using the training_data, fit an appropriate mixed effects model (use the lme4 package) to predict whether or not a song is K-pop based on artist_popularity, danceability, valence with an appropriate random effect for artist_name. (This make take some time to run)
Name your model: model_2.
nAGQ=0.summary() on your model.# summary(model_2)
Using the training_data, fit an appropriate GAM (use the mgcv package) to predict whether or not a song is K-pop based on artist_popularity, danceability, valence with a random effect for artist_name.
Individually smooth artist_popularity, danceability and valence.
k.model_3.summary() on your model.coef() on your model.# summary(model_3) # coef(model_3)
testing_data. Red red text listing factor levels isn't a problem.# add_my_predictions(testing_data, model_1, model_2, model_3)
Study question: What is the message telling you?
testing_data. The testing data is for 100 tracks by artists not in your training data.# This code will calculate it for your first model. tab_1 <- xtabs(~is_kpop+model_1, data = testing_data) sum(diag(tab_1))/100
# Add your code for all three models below, based on the example code above.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.