<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/analyzing-spotify-song-metrics-to-visualize-popular-songs/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nycdatascience.com/blog/student-works/analyzing-spotify-song-metrics-to-visualize-popular-songs/"> R – NYC Data Science Academy Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>How would you go about describing your favorite new song? What makes it catchy to you? According to the people at Spotify, characteristics like like energy or mood of a song can actually be quantified, and have many algorithms to describe music in <a rel="nofollow" href="https://beta.developer.spotify.com/documentation/web-api/reference/tracks/get-audio-features/" target="_blank">an amazing amount </a><a rel="nofollow" href="https://beta.developer.spotify.com/documentation/web-api/reference/tracks/get-several-tracks/" target="_blank">of ways</a>.</p>
<p>Now, why would you care about what the people at Spotify have to say about a song? With a user base of 159 million active monthly users, determining key factors that affect popularity can actually be a powerful tool for record label producers to find new artists to sign, or for aspiring data scientists to show off some nice visualizations and determine what to put on the ultimate summer playlist. Popularity is well defined in their API notes as a function of the number of times a particular song was streamed, as well as how recent those streams are.</p>
<p><strong>About the App</strong></p>
<p>This app visualizes several key factors and investigates their correlation to popularity visually across a wide spectrum of music.</p>
<p>The first two plots offer a degree of interactivity, allowing the user to visualize the difference amongst the genres. The box plot helps to see a more quantitative take on the separation across a wide musical spectrum. The density plot helps more with visualizing across the 0 – 100 scale of popularity, to see if there are any abnormalities with popularity distribution (for instance, classical music seems to have a pretty well defined bi-modal distribution of popularity!)</p>
<p><a rel="nofollow" href="https://i0.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-4.35.13-PM.png" target="_blank"><img sizes="(max-width: 680px) 100vw, 680px" src="https://i2.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-4.35.13-PM-300x164.png?w=450" alt="" class="wp-image-32251" data-recalc-dims="1"></a></p>
<p>Besides looking at each genre as a whole, I wanted visualize a subset of each genre on a scatter plot to identify clusters to look at other variables like energy or danceability and how they change along with popularity. However, I ran into many issues in trying to separate the genres and effectively display the information. I decided on a 3D scatter plot, adding another user-input variable to look at two separate correlations with a very interactive plot for the user to zoom in and rotate the axes to better display information to their preference.  I have also included a small table to look at the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Pearson_correlation_coefficient" target="_blank">Pearson correlation coefficient</a> of several of the metrics from Spotify with popularity.</p>
<p><a rel="nofollow" href="https://i1.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-5.21.27-PM.png" target="_blank"><img sizes="(max-width: 680px) 100vw, 680px" src="https://i2.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-5.21.27-PM-300x173.png?w=450" alt="" class="wp-image-32261" data-recalc-dims="1"></a></p>
<p>Finally, I took the 50th percentile (in terms of popularity) from each genre in my dataset and displayed them in a datatable in terms of ‘threshold values’ for each genre. For instance, for a successfully popular metal song, the relative would need to be quite high, as the 50th percentile has a value of 0.902. Also interestingly enough, danceability seems to be a much more crucial factor for pop as opposed to indie pop.</p>
<p><a rel="nofollow" href="https://i0.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-5.47.05-PM.png" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i2.wp.com/nycdatascience.com/blog/wp-content/uploads/2018/05/Screen-Shot-2018-05-06-at-5.47.05-PM-300x126.png?w=450" alt="" class="wp-image-32265" data-recalc-dims="1"></a></p>
<p><strong>About the Dataset</strong></p>
<p>The dataset was obtained by using the <a rel="nofollow" href="https://beta.developer.spotify.com/documentation/web-api/" target="_blank">Spotify Web API</a> in combination with the Python 3 library <a rel="nofollow" href="http://spotipy.readthedocs.io/en/latest/" target="_blank">Spotipy</a>. For each genre I chose, I queried 3,000 songs for the Spotify audio analysis and features. The API has a 50 song limit at each time, so I had to create a loop to query the API in 3,000 song chunks, and store them in a relevant pandas dataframe. Afterwards, I wrote the data into a CSV to do the majority of the analysis within R.</p>
<p>The jupyter notebook used to query the server as well as the Shiny application can be found at <a rel="nofollow" href="https://github.com/jvichare/rshiny-music-visualization" target="_blank">this GitHub repo</a>.</p>
<p><strong>Future Work</strong></p>
<p>I would love to continue this analysis of popularity metrics with clustering/regression analysis at a further date, or to be able to develop a predictive model and feed information into it via Spotipy to determine up-and-coming popular artists.</p>
<p>For any comments or questions, please reach me via e-mail at joshvichare@gmail.com.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://nycdatascience.com/blog/student-works/analyzing-spotify-song-metrics-to-visualize-popular-songs/"> R – NYC Data Science Academy Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/sepVpfkh38E" height="1"></a></div>