Beyond Genre Labels: Exploring Rock Music Diversity with K-Means Clustering

Giulia Hoorens Van Heyningen
6 min readApr 30, 2024

--

Rock music thrives on variety, encompassing everything from the high-energy riffs of classic rock to the introspective melodies of indie. But how can we categorize and understand these differences objectively?

This post dives into music data analysis using Spotify’s API and K-means clustering. We’ll analyze audio features like danceability and energy to identify distinct clusters within rock music. These clusters might represent different subgenres or moods associated with rock music. Let’s explore what data reveals about the soul of rock.

Using Data for Rock Concerts

Booking the right bands is crucial for concert venues. But how do they ensure the artists resonate with their audience’s diverse rock preferences? Traditionally, genres like classic rock or indie rely on a mix of musical style, cultural context, and even listener perception. This subjectivity creates a challenge for several key stakeholders in the concert venue ecosystem:

  • Concert Promoters & Talent Buyers: Their success hinges on filling seats with fans who dig the music. Data-driven insights into rock subgenres could provide a more objective way to assess bands, complementing traditional genre labels. Imagine finding the perfect alternative rock band for a venue based on data analysis, not just a subjective label.
  • Marketing & Advertising Teams: Targeted marketing campaigns are essential for selling tickets. Understanding the nuances within rock music allows for more precise audience segmentation. Data on audio features like danceability could help target fans who favor high-energy music, maximizing the effectiveness of marketing dollars.
  • Venue Management & Operations: The concert experience goes beyond the music. Data on rock subgenres can inform decisions about merchandise offerings, stage production elements, and even concessions. For instance, a venue hosting a post-metal band might stock more earplugs based on the genre’s typically loud sound, while a venue hosting a pop-rock band might focus on lighter merchandise like phone cases.

Data Collection

I analyzed audio features from Spotify using libraries like spotipy. These features, including danceability, energy, tempo, and instrumentals, offer a quantitative way to measure a song’s musical characteristics. By collecting audio features from playlists like “Classic Rock Hits” and “Indie Rock Anthems,” we can build a data set representing the rock genre’s diversity. Analyzing these features with K-means clustering from SKLearn might reveal distinct groups of songs that correlate with established subgenres or even hidden categories. This data-driven approach, combined with traditional genre labels, could provide valuable insights for concert venues aiming to curate the perfect musical experience for their rock-loving audience.

Selecting a K Value

In K-Means clustering, the measurement of similarity between data points is crucial for forming meaningful clusters. To achieve this, I utilized various audio features obtained from Spotify’s API, such as danceability, energy, tempo, and instrumentalness. These features provide quantitative metrics to assess the musical characteristics of each song.

To identify the optimal number of clusters (k) that represent distinct subgenres within rock music, I employed the elbow method. This technique involves running K-means clustering for a range of k values and evaluating the sum of squared errors (SSE) for each k. The SSE measures the distance between data points and their assigned cluster centers.

Visualizing the SSE across these k values typically results in an elbow-shaped curve. The ideal k value lies at the “elbow” where the SSE starts to diminish rapidly and then levels off. This point signifies a good balance between the number of clusters and the quality of clustering (i.e., how tightly data points are grouped within their assigned clusters).

By applying the elbow method to the audio feature data, we can objectively determine the k value that best captures the inherent structure of rock music subgenres. This data-driven approach ensures a more principled selection of k, avoiding subjectivity and leading to more meaningful interpretations of the resulting clusters.

Analyzing Clusters

We can interpret the distinct clusters potentially representing different rock subgenres or styles:

Cluster 1 (Yellow): This cluster exhibits a wide range of “danceability” values, but none exceeding 0.7 on the scale. However, it’s characterized by relatively low “energy” levels overall. This could represent more laid-back, groove-oriented rock styles like blues rock, stoner rock, or psychedelic rock. Artists that might fall into this mellow yet rhythmic cluster could include groups like The Black Keys, Queens of the Stone Age, or Pink Floyd. For concert promoters, this cluster may suggest a more relaxed, hazy live experience where the focus is on infectious grooves and hypnotic jams rather than frenetic intensity. Venues could consider emphasizing mood lighting, comfortable seating areas, and concessions geared towards creating a chilled, immersive vibe.

Cluster 2 (Blue): Standing out with the highest “danceability” scores, this cluster also exhibits a generally moderate range of “energy” values. This positioning could encompass upbeat, danceable rock genres like pop-rock, new wave, and certain strains of punk-influenced alternative rock. Bands that might populate this energetic yet accessible cluster include acts like The Go-Go’s, Weezer, or Green Day. For stakeholders, this cluster signals the potential for an incredibly high-energy, crowd-pleasing live experience that still maintains mainstream appeal. Venues could consider interactive features like dance floors, coordinated light shows, and plentiful merch options to fully lean into the entertaining spectacle.

Cluster 3 (Purple): Much like the yellow cluster, this group spans a wide “danceability” range but doesn’t exceed 0.7. However, it’s defined by exceedingly high “energy” levels, with most data points showing values above 0.8. This intense, relentless cluster could represent aggressive, adrenaline-fueled rock genres like thrash metal, hardcore punk, and even some strains of industrial rock. Groups like Slayer, Hatebreed, or Ministry might exemplify this confrontational, viscerally charged rock cluster. For venues, this signals the need to prepare for a potentially wild live experience by implementing strict security protocols, adequate ear protection options, and perhaps even separating particularly energetic pits from calmer seated areas. Merchandise could focus on tougher band apparel that aligns with the scene’s aesthetic.

Cleaning up the Data

While utilizing Spotify’s API with Spotipy, common issues may arise, such as missing or incomplete data in the retrieved audio features, which can potentially skew clustering results. To mitigate this, I implemented a filtering step to exclude any tracks that lack complete audio feature information. Additionally, inconsistencies in feature scales across different tracks can impact the effectiveness of clustering. To address this, I employed feature scaling using StandardScaler to standardize the selected features, ensuring uniformity and comparability. Furthermore, the API may occasionally encounter timeouts or rate limit errors, particularly when fetching data for a large number of tracks. To prevent disruptions, I adjusted the requests timeout parameter and used client credentials with increased timeout settings.

Conclusion and Limitations

While this analysis provides valuable insights using danceability and energy features, it has certain limitations that could introduce biases. One potential bias stems from relying solely on Spotify playlists as the data source, as these playlists might favor certain rock subgenres over others, skewing the representation of the genre’s diversity. Additionally, using only audio features from Spotify fails to capture the full essence of rock music, which is heavily influenced by cultural context and personal experiences of listeners. These subjective elements play a crucial role in shaping the perception and categorization of rock subgenres, but are not accounted for in this analysis.

Furthermore, focusing exclusively on danceability and energy limits the ability to fully characterize rock subgenres, as other audio features like tempo, instrumentalness, and loudness could also contribute valuable information. To mitigate these limitations and reduce potential biases, future work should involve incorporating additional data sources, such as user listening data, expert annotations, and a broader range of audio features. By acknowledging these limitations and expanding the analysis to include more comprehensive data and subjective elements, we can gain a richer, less biased understanding of rock’s diversity. This combined data-driven and human-centric approach holds the key to unlocking the true essence of rock music and creating a more fulfilling, culturally-aware musical experience for audiences.

Link to GitHub Repo

--

--