The music you consume is a personal statement

Mariana Donabella
4 min readMar 22, 2021

This is an article about how I used machine learning to support a social cause

Image from: Peggy Chou/Hypebeast

We, as consumers, have power. And it’s been a while since I know that. This is why I put attention in what I buy, what I read, what I recommend: who am I listening to? Who am I giving visibility to?

If you take a look at my bookshelf, you’ll find a good mix: female authors, black authors, asian authors, latin, african, muslim, and of course, some white american and european male authors as well. I find that diversifying the perspectives we have access to are one of the most important things for us to do. Not only to fight for equality, but to have a better understanding of the world in general, and to keep growing as a society .

But I realized that this thing I do for books, I don’t do for music. I keep listening mainly to music from american men (which is really good let’s face it), and I struggle to find a balance and add more female singers to my playlists. And there is a reason for that:

Around 80% of artists on the year end charts are male and 20% are female. Also, since 2013, more than 1000 artists were nominated to the Grammy Awards, and around 90% were men.

And if a huge part of what builds our music taste comes from exposure, no wonder it is so hard to balance and find a great variety of songs by female artists that we like; the dudes are so much easier to find!

So, as someone who acquired some solid machine learning skills, I decided to build a song recommender that will take as an input a song you like, and recommend a similar song when it comes to the features, but that is performed by a woman.

In order to do that, I learned how to work with Spotify’s API, and I used unsupervised machine learning, in Python. I’ll explain briefly how the logic behind the model was built:

The process can be split into 2 parts: building database of songs to recommend, and the process of getting the song inputted by the user and outputting a recommendation. I’ll dive into them briefly:

  1. Building a database of songs to recommend:
  • Searching for playlists that had ONLY female artists in them, in different music genres
  • Using Spotify API to get these playlists and building the database with them in my local directory
  • Using unsupervised machine learning to cluster those songs (Kmeans), based on their music features (that we can access also using Spotify’s API)

2. Getting song inputted by user, and recommending a similar one:

  • Ask for user to write the name of a song he/she likes
  • Send this song to Spotify, in order to get its music features
  • Find out in which cluster the inputted song would belong, based on the music features
  • Get a song from the same cluster (that will be by a female artist, since we only have females on the database)
  • Recommend it!

I illustrated the process below as well:

I tried the recommender a couple of times and here are the songs I got:

I know there are still improvements to be made in the recommender itself, in order to make it more assertive. But hey, it works!

When it comes to coding, here are the improvements I’d make:

  • Since it is difficult to find long playlists only with female artists, my database now has only around 3.000 songs, with different genres: rap, pop, rock, christian music, electronic… → I would increase database
  • Play with clustering a little more: more clusters? More iterations?

Maybe this is not the more assertive way to build a song recommender, but I sure had fun doing it! And I stand by the idea that we need a tool to help us balance our music choices.

We are the ones with the power to demand for equality in the music industry! Let’s use this power to actively do it!

*Oh and if you’re curious and want to take a look at the code, here it is: https://github.com/Marianadonabella/project3_spotify/blob/main/Code/main.ipynb

--

--

Mariana Donabella

Background in business and marketing, also telling stories with data