Importamos la librerias necesarias
library(pacman)
p_load(stringi, tidyverse, readr)
source('../lib/data-access.R')
source('../lib/plot.R')Consultamos los tack featudes del top 10:
top_track_features_collection <- get_collection('track_features_top_10')
top_track_features <- top_track_features_collection$find(fields = '{
"_id": false,
"position": true,
"week_start": true,
"week_end": true,
"reproductions": true,
"name": true,
"artist": true,
"album_id": true,
"album": true,
"number": true,
"disc_number": true,
"album_release_date": true,
"danceability": true,
"energy": true,
"loudness": true,
"speechiness": true,
"acousticness": true,
"instrumentalness": true,
"liveness": true,
"valence": true,
"explicit": true,
"tempo": true,
"time_signature": true,
"duration_ms": true,
"key": true,
"mode": true
}')Convertimos las fecha a tipo date para poder comparar:
top_track_features$week_start <- as.Date(
top_track_features$week_start,
format="%Y-%m-%d"
)
top_track_features$week_end <- as.Date(
top_track_features$week_start,
format="%Y-%m-%d"
)str(top_track_features)## 'data.frame': 1148 obs. of 25 variables:
## $ position : int 10 8 9 3 6 1 9 4 1 10 ...
## $ week_start : Date, format: "2018-12-28" "2019-04-26" ...
## $ week_end : Date, format: "2018-12-28" "2019-04-26" ...
## $ reproductions : int 17560600 20230172 19467987 23468009 22404832 39419339 21577655 32309199 38174455 17215322 ...
## $ name : chr "Calma - Remix" "7 rings" "Soltera - Remix" "All I Want for Christmas Is You" ...
## $ artist : chr "Pedro Capó" "Ariana Grande" "Bad Bunny" "Mariah Carey" ...
## $ album_id : chr "1tFnP9PwIMeMIuj92mfswZ" "2fYhqwDWXjbpjaIJPEfKFw" "2m9Vuc9Q19qhSm6RQmBgsR" "61ulfFSmmxMhc2wCdmdMkN" ...
## $ album : chr "Calma (Remix)" "thank u, next" "Soltera (Remix)" "Merry Christmas" ...
## $ number : int 1 10 1 2 1 9 1 1 10 1 ...
## $ disc_number : int 1 1 1 1 1 2 1 1 1 1 ...
## $ album_release_date: chr "2018-10-05" "2019-02-08" "2019-05-10" "1994-11-01" ...
## $ danceability : num 0.826 0.778 0.795 0.336 0.785 0.835 0.863 0.621 0.778 0.571 ...
## $ energy : num 0.773 0.317 0.783 0.627 0.721 0.626 0.666 0.601 0.317 0.693 ...
## $ loudness : num -4.22 -10.73 -4.27 -7.46 -5.46 ...
## $ speechiness : num 0.0524 0.334 0.0432 0.0384 0.0506 0.125 0.152 0.148 0.334 0.0545 ...
## $ acousticness : num 0.323 0.592 0.361 0.164 0.0149 0.0589 0.212 0.0522 0.592 0.00536 ...
## $ instrumentalness : num 0 0 0 0 0.00432 0.00006 0.000493 0 0 0 ...
## $ liveness : num 0.143 0.0881 0.437 0.0708 0.285 0.396 0.103 0.46 0.0881 0.173 ...
## $ valence : num 0.761 0.327 0.799 0.35 0.894 0.35 0.838 0.457 0.327 0.393 ...
## $ explicit : logi FALSE TRUE FALSE FALSE TRUE TRUE ...
## $ tempo : num 127 140 92 150 122 ...
## $ time_signature : int 4 4 4 4 4 4 4 5 4 4 ...
## $ duration_ms : int 238200 178626 266086 241106 176218 217925 178946 163636 178626 232253 ...
## $ key : chr "B" "C#" "F" "G" ...
## $ mode : chr "minor" "minor" "major" "major" ...
Separamos los features numericos:
track_features.num <- top_track_features %>% select_if(is.numeric)Normalizamos:
track_features.num.scaled <- track_features.num %>% mutate_all(scale)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.
gplot_hist(track_features.num$danceability,name= 'Danceability', binwidth = 0.02)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.
gplot_hist(track_features.num$energy, name= 'Energy', binwidth = 0.02)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.
gplot_hist(track_features.num$loudness, name= 'Loudness', binwidth = 0.7)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.
gplot_hist(track_features.num$speechiness, name= 'Speechiness', binwidth = 0.02)A confidence measure from 0.0 to 1.0 of whether the track is acoustic. 1.0 represents high confidence the track is acoustic.
gplot_hist(track_features.num$acousticness, name= 'Acousticness', binwidth = 0.02)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.
gplot_hist(track_features.num$instrumentalness, name= 'Instrumentalness', binwidth = 0.1)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.
gplot_hist(track_features.num$liveness, name= 'Liveness', binwidth = 0.03)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).
gplot_hist(track_features.num$valence, name= 'Valence', binwidth = 0.03)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.
gplot_hist(track_features.num$tempo, name= 'Tempo', binwidth = 4)The duration of the track in milliseconds.
gplot_hist(track_features.num$duration_ms / 1000, name= 'Duracion en Milisegundos', binwidth = 20)Numero de reproducciones de los tracks
gplot_hist(track_features.num$reproductions, name= 'Reproductions', binwidth = 1000000)p <- track_features.num.scaled %>%
pivot_longer(
.,
cols = names(track_features.num.scaled),
names_to = "Variables",
values_to = "Frecuencia"
) %>%
ggplot(aes(x = Variables, y = Frecuencia, fill = Variables)) +
geom_boxplot(width=0.2)
ggplotly(p)num_features.cov <- cov(track_features.num.scaled)
# num_features.covnum_features.cov[lower.tri(num_features.cov)] <- NA
plot_heatmap(num_features.cov)plot(track_features.num.scaled)p <- ggplot(track_features.num.scaled, aes(x = loudness, y = energy)) +
geom_point() +
geom_smooth(method = 'loess', formula = 'y ~ x')
ggplotly(p)p <- ggplot(track_features.num.scaled, aes(x = position, y = reproductions)) +
geom_point() +
geom_smooth(method = 'loess', formula = 'y ~ x')
ggplotly(p)