Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π΅ Music Preference Classification using Spotify Audio Features
|
| 2 |
+
|
| 3 |
+
## π Project Overview
|
| 4 |
+
|
| 5 |
+
This project aims to classify whether a song is **liked** or **disliked** based on its audio features from Spotify. The dataset includes a curated collection of tracks categorized by personal music taste, and machine learning models are used to identify patterns that predict preference.
|
| 6 |
+
|
| 7 |
---
|
| 8 |
+
|
| 9 |
+
## π Table of Contents
|
| 10 |
+
|
| 11 |
+
1. [Playlist Creation](#1-πΌ-playlist-creation)
|
| 12 |
+
2. [Data Collection](#2-π-data-collection)
|
| 13 |
+
3. [Features Description](#3-π΅-features-description)
|
| 14 |
+
4. [Target Variable](#4-π-target-variable)
|
| 15 |
+
5. [Project Structure](#5-π-project-structure)
|
| 16 |
+
6. [Usage](#6-π-how-to-use)
|
| 17 |
+
|
| 18 |
---
|
| 19 |
+
|
| 20 |
+
## 1. πΌ Playlist Creation
|
| 21 |
+
|
| 22 |
+
### Liked Songs (100 tracks):
|
| 23 |
+
|
| 24 |
+
* Mainly French Rap
|
| 25 |
+
* Some American Rap, Rock, Electro
|
| 26 |
+
|
| 27 |
+
### Disliked Songs (95 tracks):
|
| 28 |
+
|
| 29 |
+
* 25 Metal (e.g. Cannibal Corpse)
|
| 30 |
+
* 20 Disliked Rap (e.g. PNL)
|
| 31 |
+
* 25 Classical
|
| 32 |
+
* 25 Disco
|
| 33 |
+
|
| 34 |
+
> Pop songs are excluded as the user is neutral about them.
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## 2. π Data Collection
|
| 39 |
+
|
| 40 |
+
### Step-by-step:
|
| 41 |
+
|
| 42 |
+
#### 2.1 Get Playlist Track IDs
|
| 43 |
+
|
| 44 |
+
* Spotify API: `Get a Playlist's Items`
|
| 45 |
+
* Fields: `items(track(id,name))`
|
| 46 |
+
* Output saved to: `ids/yes.py`, `ids/no.py`
|
| 47 |
+
|
| 48 |
+
#### 2.2 Convert JSON to Track IDs
|
| 49 |
+
|
| 50 |
+
* Script: `ids/ids_to_data.py`
|
| 51 |
+
* Output: Comma-separated string of track IDs
|
| 52 |
+
|
| 53 |
+
#### 2.3 Fetch Audio Features
|
| 54 |
+
|
| 55 |
+
* Spotify API: `Get Audio Features for Several Tracks`
|
| 56 |
+
* Output Files:
|
| 57 |
+
|
| 58 |
+
* `data/good.json`
|
| 59 |
+
* `data/dislike.json`
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
## 3. π΅ Features Description
|
| 64 |
+
|
| 65 |
+
Each track is represented by 13 Spotify audio features:
|
| 66 |
+
|
| 67 |
+
| Feature | Type | Description |
|
| 68 |
+
| ------------------ | ----------- | ------------------------------------ |
|
| 69 |
+
| `acousticness` | float (0β1) | Likelihood track is acoustic |
|
| 70 |
+
| `danceability` | float (0β1) | Suitability for dancing |
|
| 71 |
+
| `duration_ms` | int | Track length in ms |
|
| 72 |
+
| `energy` | float (0β1) | Intensity/activity level |
|
| 73 |
+
| `instrumentalness` | float (0β1) | Likelihood of no vocals |
|
| 74 |
+
| `key` | int (0β11) | Musical key (0 = C, 1 = C#/Db, etc.) |
|
| 75 |
+
| `liveness` | float (0β1) | Probability of live performance |
|
| 76 |
+
| `loudness` | float (dB) | Average loudness |
|
| 77 |
+
| `mode` | int (0/1) | 1 = major, 0 = minor |
|
| 78 |
+
| `speechiness` | float (0β1) | Presence of spoken words |
|
| 79 |
+
| `tempo` | float | Tempo in BPM |
|
| 80 |
+
| `time_signature` | int | Beats per measure |
|
| 81 |
+
| `valence` | float (0β1) | Musical positiveness |
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## 4. π Target Variable
|
| 86 |
+
|
| 87 |
+
| Column | Type | Description |
|
| 88 |
+
| ------- | ---- | ----------------------- |
|
| 89 |
+
| `liked` | int | 1 = Liked, 0 = Disliked |
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
---
|
| 95 |
+
|
| 96 |
+
## 5. π How to Use
|
| 97 |
+
|
| 98 |
+
1. **Install dependencies:**
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
pip install -r requirements.txt
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
2. **Convert playlist JSON to track IDs** using `ids_to_data.py`
|
| 105 |
+
|
| 106 |
+
3. **Fetch features from Spotify API** using the ID strings
|
| 107 |
+
|
| 108 |
+
4. **Run EDA and train models** in Jupyter notebooks
|
| 109 |
+
|
| 110 |
+
5. **Save and evaluate models**
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## πΉ Notes
|
| 115 |
+
|
| 116 |
+
* Requires a valid **Spotify Developer token**.
|
| 117 |
+
* Fully customizable to user preferences.
|
| 118 |
+
* Great example of personalized ML using real-world API data.
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
Feel free to fork, modify, or contribute to this music recommendation project!
|