The Spotify Web API is a great resource for pulling data about musical artists, especially a list of related artists. While this is helpful for discovering new music, it can also be used to identify seperate factions of artists within this inital grouping.
First a grouping of artists is treated like a digraph, where an arc spans from artist a to artist b if Spotify says artist b is in artist's a's related artists list. Using this Graph G, we then partition this into two distinct subgraphs (G1 and G2) where the number of edges kept is maximized.
The method for determining this graph partition was initally found by M. Newman in his paper Finding community structure in networks using the eigenvectors of matrices. This is a very extensive process that has been reduced to a functional algorithm:
- Find adjanceny matrix (A) of G, and degree vector (d) of A
- Find the probability matrix (P) where p(i,j) ≈ (d[i] * d[j]) / ∑d
- Compute the modular matrix M: M = A - P
- Find eigenvectors V from the eigen decomposition of M
- Looking at the first column in V, if the value is negative that row is in one group and if positive that row is in the other group
Run this tool through the command line in a virtual env, with the inital artist's name in single quotes
$ python request.py '<artist_name>'
Make use of cool pip features, and automatically install relevant dependencies with pip install -r requirements.txt
Then run the create and run the virtual enviroment
$ virtualenv -p python3 myvenv
$ source myvenv/bin/activate
- Make sure you have installed virtualen, or if not then run
pip install virtualenv
- Creating the python three virtual enviroment
virtualenv -p python3 myvenv
[] - Start the enviroment
source myvenv/bin/activate
- Install the pyton requests package
pip install requests
- Install numpy
pip install numpy
- Shoutout to the @Spotify team for an awesome public API 🎵 🍰
- Shoutout to requests for a great HTTP tool for humans 🎉
- Thank you to Dr. Hoon Hong for covering this method in MA305 📚
- Thank you to M. Newman for the inital paper, Finding community structure in networks using the eigenvectors of matrices