Skip to content

Commit 20d4bdd

Browse files
authored
Update README.md
1 parent 812b814 commit 20d4bdd

File tree

1 file changed

+79
-22
lines changed
  • Recommendation Models/Music Recommendation

1 file changed

+79
-22
lines changed
Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,80 @@
1-
## Mock Spotify Music Recommendation System ##
2-
**Project Overview:**
3-
In this project, we will build a song recommendation system based on your personal Spotify data that divides the songs that you liked into 'k' number of playlists using the K-Means Clustering algorithm based on similarity in audio features such as energy, tempo, danceability, etc. Taking a look at the clustering, you will get an idea about what each playlist represents, e.g. you may notice that playlist #1 contains slow and melancholic songs, etc. Further, you get to test the recommendation ability of the system by getting new songs by a particular artist/any other way to get a bunch of unseen random songs to test whether it makes sense for the new songs to be classified under the category they have been assigned to.
4-
K-Means is a popular unsupervised machine learning algorithm used for clustering data into groups based on feature similarity. The goal is to partition a dataset into 'k' distinct clusters, where each data point belongs to the cluster with the nearest mean.
5-
**Steps of the algorithm:**
6-
Initialization: Choose 'k' initial centroids randomly from the data points.
7-
Assignment Step: Assign each data point to the nearest centroid, forming kk clusters.
8-
Update Step: Recalculate the centroids as the mean of the points in each cluster.
9-
Convergence Check: Repeat the assignment and update steps until centroids no longer change significantly or a maximum number of iterations is reached.
10-
We use the library function from sklearn to achieve our purpose here.
11-
**Pros and Cons of the algorithm:**
12-
Pros:
13-
14-
* Simple to implement and understand.
15-
* Efficient for large datasets.
16-
* Works well with spherical clusters.
17-
18-
Cons:
19-
20-
* Requires the number of clusters 'k' to be specified in advance.
21-
* Sensitive to initial centroid placement.
22-
* Can converge to local minima.
1+
# Mock Spotify Music Recommendation System
232

3+
## Project Overview
4+
5+
This project creates a personalized song recommendation system using your own Spotify music data. The system organizes your liked songs into 'k' different playlists based on the similarity of their audio features (such as energy, tempo, danceability, etc.) using the **K-Means Clustering** algorithm. By examining the resulting clusters, you'll be able to discover patterns in your music preferences, such as which songs are more upbeat or melancholic.
6+
7+
Additionally, the system can recommend new songs based on the clusters and test whether new, unseen songs fit into the existing playlists.
8+
9+
### Features:
10+
- **Spotify API Integration**: The system retrieves your personal Spotify data (liked songs) and their audio features.
11+
- **K-Means Clustering**: The songs are grouped into 'k' clusters based on audio feature similarity.
12+
- **Playlist Generation**: Each cluster represents a different playlist with a unique mood or theme.
13+
- **New Song Classification**: You can test the recommendation system with new songs to see if they fit into the appropriate cluster.
14+
15+
## Project Structure
16+
17+
```
18+
.
19+
├── clustering.ipynb # Jupyter notebook containing the implementation
20+
├── README.md # Project documentation
21+
└── requirements.txt # Dependencies needed to run the project
22+
```
23+
24+
## Setup and Dependencies
25+
26+
To run the project, you'll need the following libraries:
27+
28+
```bash
29+
pip install requests base64 numpy pandas sklearn
30+
```
31+
32+
### Spotify API Setup
33+
1. **Create a Spotify App**:
34+
- Login to your Spotify Developer account at [Spotify for Developers](https://developer.spotify.com/dashboard/applications).
35+
- Create a new app, and set a **Redirect URI** (e.g., `https://google.com`).
36+
37+
2. **Get your Credentials**:
38+
- Retrieve your **Client ID** and **Client Secret** from your app.
39+
40+
3. **Authenticate**:
41+
- Set up a URL to request an authorization code:
42+
```
43+
https://accounts.spotify.com/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope=user-library-read&response_type=code
44+
```
45+
- After authorizing, you'll be redirected to your specified redirect URI with a `code` in the URL.
46+
- Use this `code` to exchange for an access token.
47+
48+
4. **Modify the Notebook**:
49+
- Input your **Client ID**, **Client Secret**, **Redirect URI**, and **authorization code** into the notebook.
50+
51+
## Clustering Process
52+
53+
The project uses the **K-Means Clustering** algorithm to group songs based on their audio features. The steps include:
54+
55+
1. **Data Retrieval**: Fetch liked songs from your Spotify library using the Spotify API, along with their corresponding audio features.
56+
2. **Feature Selection**: Use features such as `energy`, `danceability`, `tempo`, and more for clustering.
57+
3. **K-Means Clustering**: Apply the K-Means algorithm to organize songs into 'k' distinct playlists.
58+
4. **Playlist Insights**: Analyze the clusters to understand what type of songs belong to each playlist.
59+
5. **Recommendation Testing**: Test new songs by assigning them to one of the existing clusters.
60+
61+
### Example Workflow
62+
1. **Fetch Your Data**: The notebook first retrieves your liked songs and their features from Spotify.
63+
2. **Cluster the Songs**: Songs are grouped into 'k' clusters, which are essentially playlists with a common theme or mood.
64+
3. **Analyze the Playlists**: You can interpret the playlists, for example, Playlist 1 could represent energetic, fast-paced songs, while Playlist 2 could contain slower, more relaxed tracks.
65+
4. **Test New Songs**: Add new songs to see if they are classified into appropriate clusters based on their audio features.
66+
67+
## How to Run the Notebook
68+
69+
1. Clone the repository or download the `clustering.ipynb` notebook.
70+
2. Ensure that you have your **Spotify Client ID** and **Client Secret**, and generate an access token by following the steps in the notebook.
71+
3. Run the notebook cells to fetch your liked songs, cluster them, and explore your generated playlists.
72+
4. Optionally, test new songs by providing their audio features and observing how the system classifies them.
73+
74+
## Conclusion
75+
76+
The **Mock Spotify Music Recommendation System** demonstrates how clustering algorithms, specifically K-Means, can be applied to personal music data to discover hidden patterns and preferences. By clustering songs based on their audio features, we can automatically generate playlists that reflect different moods or themes in a user's music library.
77+
78+
This system not only helps users explore their listening habits in new ways but also provides a framework for making personalized music recommendations. While K-Means offers a simple and effective solution, future improvements could involve more sophisticated models or additional audio features to enhance the accuracy and relevance of the recommendations.
79+
80+
The project highlights the power of machine learning in personalized applications, showcasing how unsupervised learning can offer valuable insights and user experiences without requiring labeled data.

0 commit comments

Comments
 (0)