vicky4s4s commited on
Commit
81657e3
·
verified ·
1 Parent(s): 4c8da83

Upload 5 files

Browse files
genre_finder/test_some_codes/full_data_train.ipynb ADDED
@@ -0,0 +1,1748 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "id": "initial_id",
6
+ "metadata": {
7
+ "collapsed": true,
8
+ "ExecuteTime": {
9
+ "end_time": "2026-03-30T14:23:35.971085700Z",
10
+ "start_time": "2026-03-30T14:23:35.219016Z"
11
+ }
12
+ },
13
+ "source": [
14
+ "import pandas as pd\n",
15
+ "path1 = r\"assets/model_ready_dataset1.csv\"\n",
16
+ "path2 = r\"assets/model_ready_dataset_final.csv\"\n",
17
+ "path3 = r\"assets/model_ready_dataset_final1.csv\"\n",
18
+ "df1 = pd.read_csv(path1)\n",
19
+ "df2 = pd.read_csv(path2)\n",
20
+ "df3 = pd.read_csv(path3)\n",
21
+ "\n",
22
+ "df1.shape"
23
+ ],
24
+ "outputs": [
25
+ {
26
+ "data": {
27
+ "text/plain": [
28
+ "(34197, 28)"
29
+ ]
30
+ },
31
+ "execution_count": 16,
32
+ "metadata": {},
33
+ "output_type": "execute_result"
34
+ }
35
+ ],
36
+ "execution_count": 16
37
+ },
38
+ {
39
+ "metadata": {
40
+ "ExecuteTime": {
41
+ "end_time": "2026-03-30T14:23:39.069360700Z",
42
+ "start_time": "2026-03-30T14:23:38.981358300Z"
43
+ }
44
+ },
45
+ "cell_type": "code",
46
+ "source": "df2.shape",
47
+ "id": "3a56566012bc4d20",
48
+ "outputs": [
49
+ {
50
+ "data": {
51
+ "text/plain": [
52
+ "(41935, 28)"
53
+ ]
54
+ },
55
+ "execution_count": 17,
56
+ "metadata": {},
57
+ "output_type": "execute_result"
58
+ }
59
+ ],
60
+ "execution_count": 17
61
+ },
62
+ {
63
+ "metadata": {
64
+ "ExecuteTime": {
65
+ "end_time": "2026-03-30T14:23:41.625962100Z",
66
+ "start_time": "2026-03-30T14:23:41.550176200Z"
67
+ }
68
+ },
69
+ "cell_type": "code",
70
+ "source": "df3.shape",
71
+ "id": "cfaa8e83df91c960",
72
+ "outputs": [
73
+ {
74
+ "data": {
75
+ "text/plain": [
76
+ "(49037, 28)"
77
+ ]
78
+ },
79
+ "execution_count": 18,
80
+ "metadata": {},
81
+ "output_type": "execute_result"
82
+ }
83
+ ],
84
+ "execution_count": 18
85
+ },
86
+ {
87
+ "metadata": {
88
+ "ExecuteTime": {
89
+ "end_time": "2026-03-30T14:23:42.129422500Z",
90
+ "start_time": "2026-03-30T14:23:42.060636Z"
91
+ }
92
+ },
93
+ "cell_type": "code",
94
+ "source": "df1[\"genre\"].value_counts()",
95
+ "id": "1bb37e9a1a4a63da",
96
+ "outputs": [
97
+ {
98
+ "data": {
99
+ "text/plain": [
100
+ "genre\n",
101
+ "Hip Hop Rap 21428\n",
102
+ "Folk Singer Songwriter 6917\n",
103
+ "Alternative Indie 5274\n",
104
+ "Gospel Christian 578\n",
105
+ "Name: count, dtype: int64"
106
+ ]
107
+ },
108
+ "execution_count": 19,
109
+ "metadata": {},
110
+ "output_type": "execute_result"
111
+ }
112
+ ],
113
+ "execution_count": 19
114
+ },
115
+ {
116
+ "metadata": {
117
+ "ExecuteTime": {
118
+ "end_time": "2026-03-30T14:23:44.650008100Z",
119
+ "start_time": "2026-03-30T14:23:44.586650900Z"
120
+ }
121
+ },
122
+ "cell_type": "code",
123
+ "source": "df2[\"genre\"].value_counts()",
124
+ "id": "2ef006202738872c",
125
+ "outputs": [
126
+ {
127
+ "data": {
128
+ "text/plain": [
129
+ "genre\n",
130
+ "Rock 29105\n",
131
+ "Country 12499\n",
132
+ "Punk 252\n",
133
+ "Metal 79\n",
134
+ "Name: count, dtype: int64"
135
+ ]
136
+ },
137
+ "execution_count": 20,
138
+ "metadata": {},
139
+ "output_type": "execute_result"
140
+ }
141
+ ],
142
+ "execution_count": 20
143
+ },
144
+ {
145
+ "metadata": {
146
+ "ExecuteTime": {
147
+ "end_time": "2026-03-30T14:23:45.215165Z",
148
+ "start_time": "2026-03-30T14:23:45.151818Z"
149
+ }
150
+ },
151
+ "cell_type": "code",
152
+ "source": "df3[\"genre\"].value_counts()",
153
+ "id": "e24fa51f0ef3da67",
154
+ "outputs": [
155
+ {
156
+ "data": {
157
+ "text/plain": [
158
+ "genre\n",
159
+ "EDM 18903\n",
160
+ "Pop 15967\n",
161
+ "RnB Soul 14167\n",
162
+ "Name: count, dtype: int64"
163
+ ]
164
+ },
165
+ "execution_count": 21,
166
+ "metadata": {},
167
+ "output_type": "execute_result"
168
+ }
169
+ ],
170
+ "execution_count": 21
171
+ },
172
+ {
173
+ "metadata": {
174
+ "ExecuteTime": {
175
+ "end_time": "2026-03-30T14:26:12.355726900Z",
176
+ "start_time": "2026-03-30T14:26:12.287068500Z"
177
+ }
178
+ },
179
+ "cell_type": "code",
180
+ "source": [
181
+ "final_df = pd.concat([df1, df2, df3], ignore_index=True)\n",
182
+ "print(final_df.shape)"
183
+ ],
184
+ "id": "b13f17240912f389",
185
+ "outputs": [
186
+ {
187
+ "name": "stdout",
188
+ "output_type": "stream",
189
+ "text": [
190
+ "(125169, 28)\n"
191
+ ]
192
+ }
193
+ ],
194
+ "execution_count": 22
195
+ },
196
+ {
197
+ "metadata": {
198
+ "ExecuteTime": {
199
+ "end_time": "2026-03-30T14:27:02.483708400Z",
200
+ "start_time": "2026-03-30T14:26:58.546324800Z"
201
+ }
202
+ },
203
+ "cell_type": "code",
204
+ "source": "final_df.to_csv(\"assets/all_genre.csv\",index=False)",
205
+ "id": "15fda3454dffbe41",
206
+ "outputs": [],
207
+ "execution_count": 23
208
+ },
209
+ {
210
+ "metadata": {},
211
+ "cell_type": "markdown",
212
+ "source": "### train the model",
213
+ "id": "20ac2df31c79f4da"
214
+ },
215
+ {
216
+ "metadata": {
217
+ "ExecuteTime": {
218
+ "end_time": "2026-03-30T16:46:45.958963800Z",
219
+ "start_time": "2026-03-30T16:46:44.686791300Z"
220
+ }
221
+ },
222
+ "cell_type": "code",
223
+ "source": [
224
+ "import pandas as pd\n",
225
+ "import numpy as np\n",
226
+ "import re\n",
227
+ "import ast\n",
228
+ "from sklearn.model_selection import train_test_split\n",
229
+ "from sklearn.preprocessing import StandardScaler, MultiLabelBinarizer\n",
230
+ "from sklearn.multioutput import MultiOutputClassifier\n",
231
+ "from xgboost import XGBClassifier\n",
232
+ "from sklearn.metrics import f1_score\n",
233
+ "\n",
234
+ "path = r\"assets/all_genre.csv\"\n",
235
+ "df = pd.read_csv(path)\n",
236
+ "df.sample(3)"
237
+ ],
238
+ "id": "13b7635596d96c8f",
239
+ "outputs": [
240
+ {
241
+ "data": {
242
+ "text/plain": [
243
+ " _id genre \\\n",
244
+ "87997 6996ea8d82f9a4b71aea132e EDM \n",
245
+ "104069 6954f094fe0a759b1bbc1c2f Pop \n",
246
+ "23363 6953758110ee1ae3f18eedf6 Alternative Indie \n",
247
+ "\n",
248
+ " genre_subgenre \\\n",
249
+ "87997 EDM --- [] \n",
250
+ "104069 Pop --- ['Indie Electronic', 'Indie Pop'] \n",
251
+ "23363 Alternative Indie --- ['Folk Rock', 'Indie Pop... \n",
252
+ "\n",
253
+ " trimmed_audio_duration_sec syllable_count word_count \\\n",
254
+ "87997 143.144558 357.0 283.0 \n",
255
+ "104069 183.665918 418.0 370.0 \n",
256
+ "23363 193.548390 282.0 243.0 \n",
257
+ "\n",
258
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
259
+ "87997 19.047967 0.483924 \n",
260
+ "104069 19.945393 0.493085 \n",
261
+ "23363 18.924223 0.461779 \n",
262
+ "\n",
263
+ " melody_variability (vocals) rhythm_onset_rate (mix) ... \\\n",
264
+ "87997 0.428562 4.645653 ... \n",
265
+ "104069 0.558270 4.594444 ... \n",
266
+ "23363 0.462750 2.633333 ... \n",
267
+ "\n",
268
+ " zero_crossing_rate (mix) vocab_richness \\\n",
269
+ "87997 0.073138 0.258 \n",
270
+ "104069 0.059187 0.224 \n",
271
+ "23363 0.086377 0.387 \n",
272
+ "\n",
273
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
274
+ "87997 -12.788278 36.1 \n",
275
+ "104069 -14.280496 45.4 \n",
276
+ "23363 -12.252384 44.8 \n",
277
+ "\n",
278
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
279
+ "87997 0.355957 0.550532 0.569507 \n",
280
+ "104069 0.276840 0.480446 0.480615 \n",
281
+ "23363 0.324193 0.525521 0.545800 \n",
282
+ "\n",
283
+ " sentiment_score melody_complexity (vocals) avg_word_length \n",
284
+ "87997 0.117 2.333333 3.67 \n",
285
+ "104069 0.069 2.666667 3.39 \n",
286
+ "23363 -0.064 2.416667 3.62 \n",
287
+ "\n",
288
+ "[3 rows x 28 columns]"
289
+ ],
290
+ "text/html": [
291
+ "<div>\n",
292
+ "<style scoped>\n",
293
+ " .dataframe tbody tr th:only-of-type {\n",
294
+ " vertical-align: middle;\n",
295
+ " }\n",
296
+ "\n",
297
+ " .dataframe tbody tr th {\n",
298
+ " vertical-align: top;\n",
299
+ " }\n",
300
+ "\n",
301
+ " .dataframe thead th {\n",
302
+ " text-align: right;\n",
303
+ " }\n",
304
+ "</style>\n",
305
+ "<table border=\"1\" class=\"dataframe\">\n",
306
+ " <thead>\n",
307
+ " <tr style=\"text-align: right;\">\n",
308
+ " <th></th>\n",
309
+ " <th>_id</th>\n",
310
+ " <th>genre</th>\n",
311
+ " <th>genre_subgenre</th>\n",
312
+ " <th>trimmed_audio_duration_sec</th>\n",
313
+ " <th>syllable_count</th>\n",
314
+ " <th>word_count</th>\n",
315
+ " <th>spectral_contrast_mean (mix)</th>\n",
316
+ " <th>chroma_mean (mix)</th>\n",
317
+ " <th>melody_variability (vocals)</th>\n",
318
+ " <th>rhythm_onset_rate (mix)</th>\n",
319
+ " <th>...</th>\n",
320
+ " <th>zero_crossing_rate (mix)</th>\n",
321
+ " <th>vocab_richness</th>\n",
322
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
323
+ " <th>readability_score</th>\n",
324
+ " <th>energy_essentia (mix)</th>\n",
325
+ " <th>energy_librosa (mix)</th>\n",
326
+ " <th>rms_energy_mean (mix)</th>\n",
327
+ " <th>sentiment_score</th>\n",
328
+ " <th>melody_complexity (vocals)</th>\n",
329
+ " <th>avg_word_length</th>\n",
330
+ " </tr>\n",
331
+ " </thead>\n",
332
+ " <tbody>\n",
333
+ " <tr>\n",
334
+ " <th>87997</th>\n",
335
+ " <td>6996ea8d82f9a4b71aea132e</td>\n",
336
+ " <td>EDM</td>\n",
337
+ " <td>EDM --- []</td>\n",
338
+ " <td>143.144558</td>\n",
339
+ " <td>357.0</td>\n",
340
+ " <td>283.0</td>\n",
341
+ " <td>19.047967</td>\n",
342
+ " <td>0.483924</td>\n",
343
+ " <td>0.428562</td>\n",
344
+ " <td>4.645653</td>\n",
345
+ " <td>...</td>\n",
346
+ " <td>0.073138</td>\n",
347
+ " <td>0.258</td>\n",
348
+ " <td>-12.788278</td>\n",
349
+ " <td>36.1</td>\n",
350
+ " <td>0.355957</td>\n",
351
+ " <td>0.550532</td>\n",
352
+ " <td>0.569507</td>\n",
353
+ " <td>0.117</td>\n",
354
+ " <td>2.333333</td>\n",
355
+ " <td>3.67</td>\n",
356
+ " </tr>\n",
357
+ " <tr>\n",
358
+ " <th>104069</th>\n",
359
+ " <td>6954f094fe0a759b1bbc1c2f</td>\n",
360
+ " <td>Pop</td>\n",
361
+ " <td>Pop --- ['Indie Electronic', 'Indie Pop']</td>\n",
362
+ " <td>183.665918</td>\n",
363
+ " <td>418.0</td>\n",
364
+ " <td>370.0</td>\n",
365
+ " <td>19.945393</td>\n",
366
+ " <td>0.493085</td>\n",
367
+ " <td>0.558270</td>\n",
368
+ " <td>4.594444</td>\n",
369
+ " <td>...</td>\n",
370
+ " <td>0.059187</td>\n",
371
+ " <td>0.224</td>\n",
372
+ " <td>-14.280496</td>\n",
373
+ " <td>45.4</td>\n",
374
+ " <td>0.276840</td>\n",
375
+ " <td>0.480446</td>\n",
376
+ " <td>0.480615</td>\n",
377
+ " <td>0.069</td>\n",
378
+ " <td>2.666667</td>\n",
379
+ " <td>3.39</td>\n",
380
+ " </tr>\n",
381
+ " <tr>\n",
382
+ " <th>23363</th>\n",
383
+ " <td>6953758110ee1ae3f18eedf6</td>\n",
384
+ " <td>Alternative Indie</td>\n",
385
+ " <td>Alternative Indie --- ['Folk Rock', 'Indie Pop...</td>\n",
386
+ " <td>193.548390</td>\n",
387
+ " <td>282.0</td>\n",
388
+ " <td>243.0</td>\n",
389
+ " <td>18.924223</td>\n",
390
+ " <td>0.461779</td>\n",
391
+ " <td>0.462750</td>\n",
392
+ " <td>2.633333</td>\n",
393
+ " <td>...</td>\n",
394
+ " <td>0.086377</td>\n",
395
+ " <td>0.387</td>\n",
396
+ " <td>-12.252384</td>\n",
397
+ " <td>44.8</td>\n",
398
+ " <td>0.324193</td>\n",
399
+ " <td>0.525521</td>\n",
400
+ " <td>0.545800</td>\n",
401
+ " <td>-0.064</td>\n",
402
+ " <td>2.416667</td>\n",
403
+ " <td>3.62</td>\n",
404
+ " </tr>\n",
405
+ " </tbody>\n",
406
+ "</table>\n",
407
+ "<p>3 rows × 28 columns</p>\n",
408
+ "</div>"
409
+ ]
410
+ },
411
+ "execution_count": 1,
412
+ "metadata": {},
413
+ "output_type": "execute_result"
414
+ }
415
+ ],
416
+ "execution_count": 1
417
+ },
418
+ {
419
+ "metadata": {
420
+ "ExecuteTime": {
421
+ "end_time": "2026-03-30T16:46:45.992830500Z",
422
+ "start_time": "2026-03-30T16:46:45.967978200Z"
423
+ }
424
+ },
425
+ "cell_type": "code",
426
+ "source": "df.shape",
427
+ "id": "aff9220ee6839f04",
428
+ "outputs": [
429
+ {
430
+ "data": {
431
+ "text/plain": [
432
+ "(125169, 28)"
433
+ ]
434
+ },
435
+ "execution_count": 2,
436
+ "metadata": {},
437
+ "output_type": "execute_result"
438
+ }
439
+ ],
440
+ "execution_count": 2
441
+ },
442
+ {
443
+ "metadata": {
444
+ "ExecuteTime": {
445
+ "end_time": "2026-03-30T16:46:47.001568100Z",
446
+ "start_time": "2026-03-30T16:46:46.857630300Z"
447
+ }
448
+ },
449
+ "cell_type": "code",
450
+ "source": [
451
+ "def parse_subgenres_fast(text):\n",
452
+ " if pd.isna(text) or text == \"\":\n",
453
+ " return []\n",
454
+ " text = str(text)\n",
455
+ " parts = text.split('---')\n",
456
+ " main_genre = parts[0].strip()\n",
457
+ " if len(parts) > 1:\n",
458
+ " sub = parts[1].strip()\n",
459
+ " sub = sub.strip('[]')\n",
460
+ " if sub:\n",
461
+ " subgenres = [s.strip().strip(\"'\").strip('\"') for s in sub.split(',')]\n",
462
+ " else:\n",
463
+ " subgenres = []\n",
464
+ " else:\n",
465
+ " subgenres = []\n",
466
+ " return [main_genre] + subgenres\n",
467
+ "df['subgenres_list'] = df['genre_subgenre'].apply(parse_subgenres_fast)"
468
+ ],
469
+ "id": "5ccadaac034f64dc",
470
+ "outputs": [],
471
+ "execution_count": 3
472
+ },
473
+ {
474
+ "metadata": {
475
+ "ExecuteTime": {
476
+ "end_time": "2026-03-30T16:46:47.886086100Z",
477
+ "start_time": "2026-03-30T16:46:47.825067400Z"
478
+ }
479
+ },
480
+ "cell_type": "code",
481
+ "source": "df['subgenres_list'][0]",
482
+ "id": "1e5e62299b79eeac",
483
+ "outputs": [
484
+ {
485
+ "data": {
486
+ "text/plain": [
487
+ "['Hip Hop Rap',\n",
488
+ " 'Alternative Hip Hop',\n",
489
+ " 'Boom Bap',\n",
490
+ " 'Contemporary Hip Hop',\n",
491
+ " 'Trap']"
492
+ ]
493
+ },
494
+ "execution_count": 4,
495
+ "metadata": {},
496
+ "output_type": "execute_result"
497
+ }
498
+ ],
499
+ "execution_count": 4
500
+ },
501
+ {
502
+ "metadata": {
503
+ "ExecuteTime": {
504
+ "end_time": "2026-03-30T16:46:48.597653700Z",
505
+ "start_time": "2026-03-30T16:46:48.481941800Z"
506
+ }
507
+ },
508
+ "cell_type": "code",
509
+ "source": [
510
+ "mlb = MultiLabelBinarizer()\n",
511
+ "y = mlb.fit_transform(df['subgenres_list'])\n",
512
+ "y"
513
+ ],
514
+ "id": "7683931669716dbb",
515
+ "outputs": [
516
+ {
517
+ "data": {
518
+ "text/plain": [
519
+ "array([[0, 0, 0, ..., 0, 0, 0],\n",
520
+ " [0, 0, 0, ..., 0, 0, 0],\n",
521
+ " [0, 0, 0, ..., 0, 0, 0],\n",
522
+ " ...,\n",
523
+ " [0, 0, 0, ..., 0, 0, 0],\n",
524
+ " [0, 0, 0, ..., 0, 0, 0],\n",
525
+ " [0, 0, 0, ..., 0, 0, 0]], shape=(125169, 163))"
526
+ ]
527
+ },
528
+ "execution_count": 5,
529
+ "metadata": {},
530
+ "output_type": "execute_result"
531
+ }
532
+ ],
533
+ "execution_count": 5
534
+ },
535
+ {
536
+ "metadata": {
537
+ "ExecuteTime": {
538
+ "end_time": "2026-03-30T16:57:04.551225300Z",
539
+ "start_time": "2026-03-30T16:46:49.634662300Z"
540
+ }
541
+ },
542
+ "cell_type": "code",
543
+ "source": [
544
+ "drop_cols = ['_id', 'genre', 'genre_subgenre', 'subgenres_list', 'labels',\n",
545
+ " 'trimmed_audio_duration_sec', 'syllable_count', 'word_count',\n",
546
+ " 'sentiment_score', 'avg_word_length']\n",
547
+ "\n",
548
+ "feature_cols = [c for c in df.columns if c not in drop_cols]\n",
549
+ "X = df[feature_cols].copy()\n",
550
+ "X = X.select_dtypes(include=[np.number]).fillna(0)\n",
551
+ "\n",
552
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
553
+ "\n",
554
+ "scaler = StandardScaler()\n",
555
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
556
+ "X_test_scaled = scaler.transform(X_test)\n",
557
+ "\n",
558
+ "model = MultiOutputClassifier(\n",
559
+ " XGBClassifier(\n",
560
+ " n_estimators=1700,\n",
561
+ " learning_rate=0.03,\n",
562
+ " max_depth=8,\n",
563
+ " subsample=0.85,\n",
564
+ " colsample_bytree=0.8,\n",
565
+ " random_state=42,\n",
566
+ " eval_metric='logloss'\n",
567
+ " ),\n",
568
+ " n_jobs=-1\n",
569
+ ")\n",
570
+ "\n",
571
+ "model.fit(X_train_scaled, y_train)\n",
572
+ "\n",
573
+ "def get_accuracy(X_scaled, y_true, name=\"\"):\n",
574
+ " y_pred = model.predict(X_scaled)\n",
575
+ " subset_acc = np.mean(np.all(y_pred == y_true, axis=1))\n",
576
+ " micro_f1 = f1_score(y_true, y_pred, average='micro')\n",
577
+ " print(f\"{name} Subset Accuracy: {subset_acc:.4f}\")\n",
578
+ " print(f\"{name} Micro F1 Score: {micro_f1:.4f}\")\n",
579
+ "\n",
580
+ "print(\"=== MODEL ACCURACY ===\")\n",
581
+ "get_accuracy(X_train_scaled, y_train, \"Train\")\n",
582
+ "get_accuracy(X_test_scaled, y_test, \"Test\")\n",
583
+ "\n",
584
+ "def manual_predict(row):\n",
585
+ " input_df = pd.DataFrame([row])\n",
586
+ " input_numeric = input_df.select_dtypes(include=[np.number]).fillna(0)\n",
587
+ "\n",
588
+ " for col in X.columns:\n",
589
+ " if col not in input_numeric.columns:\n",
590
+ " input_numeric[col] = 0\n",
591
+ " input_numeric = input_numeric[X.columns]\n",
592
+ " input_scaled = scaler.transform(input_numeric)\n",
593
+ " probas = model.predict_proba(input_scaled)\n",
594
+ " threshold = 0.20\n",
595
+ " pred_binary = np.zeros((1, y.shape[1]), dtype=int)\n",
596
+ " for i in range(len(probas)):\n",
597
+ " if probas[i][0][1] > threshold:\n",
598
+ " pred_binary[0, i] = 1\n",
599
+ " subgenres = mlb.inverse_transform(pred_binary)[0]\n",
600
+ " if len(subgenres) == 0:\n",
601
+ " return f\"None\"\n",
602
+ " return f\"{', '.join(sorted(subgenres))}\""
603
+ ],
604
+ "id": "2e87bee87e8284f1",
605
+ "outputs": [
606
+ {
607
+ "name": "stdout",
608
+ "output_type": "stream",
609
+ "text": [
610
+ "=== MODEL ACCURACY ===\n",
611
+ "Train Subset Accuracy: 0.8709\n",
612
+ "Train Micro F1 Score: 0.9673\n",
613
+ "Test Subset Accuracy: 0.1465\n",
614
+ "Test Micro F1 Score: 0.3423\n"
615
+ ]
616
+ }
617
+ ],
618
+ "execution_count": 6
619
+ },
620
+ {
621
+ "metadata": {
622
+ "ExecuteTime": {
623
+ "end_time": "2026-03-30T16:57:34.255351600Z",
624
+ "start_time": "2026-03-30T16:57:27.678874900Z"
625
+ }
626
+ },
627
+ "cell_type": "code",
628
+ "source": [
629
+ "import joblib\n",
630
+ "bundle = {\n",
631
+ " \"model\": model,\n",
632
+ " \"scaler\": scaler,\n",
633
+ " \"mlb\": mlb,\n",
634
+ " \"feature_cols\": X.columns.tolist()\n",
635
+ "}\n",
636
+ "joblib.dump(bundle, \"train_model/all_genre.pkl\")\n",
637
+ "print(\"Model saved successfully!\")"
638
+ ],
639
+ "id": "53c2d801062301d7",
640
+ "outputs": [
641
+ {
642
+ "name": "stdout",
643
+ "output_type": "stream",
644
+ "text": [
645
+ "Model saved successfully!\n"
646
+ ]
647
+ }
648
+ ],
649
+ "execution_count": 7
650
+ },
651
+ {
652
+ "metadata": {
653
+ "ExecuteTime": {
654
+ "end_time": "2026-03-30T17:00:16.116265100Z",
655
+ "start_time": "2026-03-30T17:00:16.024652100Z"
656
+ }
657
+ },
658
+ "cell_type": "code",
659
+ "source": "df[[\"subgenres_list\",\"genre\"]].iloc[508,]",
660
+ "id": "29ae3adc40dc0a2d",
661
+ "outputs": [
662
+ {
663
+ "data": {
664
+ "text/plain": [
665
+ "subgenres_list [Hip Hop Rap, Contemporary Hip Hop, Trap]\n",
666
+ "genre Hip Hop Rap\n",
667
+ "Name: 508, dtype: object"
668
+ ]
669
+ },
670
+ "execution_count": 8,
671
+ "metadata": {},
672
+ "output_type": "execute_result"
673
+ }
674
+ ],
675
+ "execution_count": 8
676
+ },
677
+ {
678
+ "metadata": {},
679
+ "cell_type": "markdown",
680
+ "source": "## 1) Second apporoch",
681
+ "id": "5b64bdd097a9d631"
682
+ },
683
+ {
684
+ "metadata": {},
685
+ "cell_type": "markdown",
686
+ "source": "## 1) SECOND CONCEPTS",
687
+ "id": "3f8160d92c2cd86f"
688
+ },
689
+ {
690
+ "metadata": {
691
+ "ExecuteTime": {
692
+ "end_time": "2026-03-31T05:30:08.866729200Z",
693
+ "start_time": "2026-03-31T05:30:08.800975400Z"
694
+ }
695
+ },
696
+ "cell_type": "code",
697
+ "source": "#! pip install tensorflow",
698
+ "id": "60c350c541592fb8",
699
+ "outputs": [],
700
+ "execution_count": 3
701
+ },
702
+ {
703
+ "metadata": {
704
+ "ExecuteTime": {
705
+ "end_time": "2026-03-31T09:27:58.269252700Z",
706
+ "start_time": "2026-03-31T09:27:56.493881900Z"
707
+ }
708
+ },
709
+ "cell_type": "code",
710
+ "source": [
711
+ "import pandas as pd\n",
712
+ "import numpy as np\n",
713
+ "import re\n",
714
+ "import ast\n",
715
+ "from sklearn.model_selection import train_test_split\n",
716
+ "from sklearn.preprocessing import StandardScaler, MultiLabelBinarizer\n",
717
+ "from sklearn.multioutput import MultiOutputClassifier\n",
718
+ "from xgboost import XGBClassifier\n",
719
+ "from sklearn.metrics import f1_score"
720
+ ],
721
+ "id": "717885273a039bc0",
722
+ "outputs": [],
723
+ "execution_count": 1
724
+ },
725
+ {
726
+ "metadata": {
727
+ "ExecuteTime": {
728
+ "end_time": "2026-03-31T09:28:02.080288200Z",
729
+ "start_time": "2026-03-31T09:27:59.859812300Z"
730
+ }
731
+ },
732
+ "cell_type": "code",
733
+ "source": [
734
+ "df = pd.read_csv(\"final_clean_data.csv\")\n",
735
+ "df['genre_subgenre'] = df['genre_subgenre'].apply(lambda x: ast.literal_eval(x) if isinstance(x, str) else x)"
736
+ ],
737
+ "id": "6460a59542844d74",
738
+ "outputs": [],
739
+ "execution_count": 2
740
+ },
741
+ {
742
+ "metadata": {
743
+ "ExecuteTime": {
744
+ "end_time": "2026-03-31T09:28:44.762378100Z",
745
+ "start_time": "2026-03-31T09:28:44.664699400Z"
746
+ }
747
+ },
748
+ "cell_type": "code",
749
+ "source": "df.sample(3)",
750
+ "id": "a5951d9f9252687e",
751
+ "outputs": [
752
+ {
753
+ "data": {
754
+ "text/plain": [
755
+ " genre_subgenre \\\n",
756
+ "55138 [Indie Folk, Dream Pop, Indie Pop, Folk Pop, I... \n",
757
+ "34570 [Classic Alternative Rock, Rock] \n",
758
+ "115446 [Dream Pop, Indie Pop, Lo Fi, RnB Soul] \n",
759
+ "\n",
760
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
761
+ "55138 18.953288 0.438801 \n",
762
+ "34570 17.648178 0.593524 \n",
763
+ "115446 19.939022 0.460538 \n",
764
+ "\n",
765
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
766
+ "55138 0.276532 5.561111 \n",
767
+ "34570 0.828343 1.917868 \n",
768
+ "115446 0.366296 2.050000 \n",
769
+ "\n",
770
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
771
+ "55138 0.136025 0.006977 \n",
772
+ "34570 0.192934 0.009650 \n",
773
+ "115446 0.137038 0.007738 \n",
774
+ "\n",
775
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
776
+ "55138 48.063896 162.070480 162.070480 \n",
777
+ "34570 132.527191 161.965561 161.965561 \n",
778
+ "115446 108.319832 139.820786 139.820786 \n",
779
+ "\n",
780
+ " ... mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
781
+ "55138 ... -27.844322 6.587286 \n",
782
+ "34570 ... -38.153713 0.697901 \n",
783
+ "115446 ... 21.716513 5.794365 \n",
784
+ "\n",
785
+ " zero_crossing_rate (mix) vocab_richness \\\n",
786
+ "55138 0.058096 0.478 \n",
787
+ "34570 0.103853 0.480 \n",
788
+ "115446 0.046103 0.622 \n",
789
+ "\n",
790
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
791
+ "55138 -15.621501 107.0 \n",
792
+ "34570 -10.773592 37.6 \n",
793
+ "115446 -17.407324 54.4 \n",
794
+ "\n",
795
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
796
+ "55138 0.201458 0.412518 0.417358 \n",
797
+ "34570 0.511921 0.698029 0.706971 \n",
798
+ "115446 0.147544 0.324240 0.332860 \n",
799
+ "\n",
800
+ " melody_complexity (vocals) \n",
801
+ "55138 1.500000 \n",
802
+ "34570 2.916667 \n",
803
+ "115446 1.916667 \n",
804
+ "\n",
805
+ "[3 rows x 21 columns]"
806
+ ],
807
+ "text/html": [
808
+ "<div>\n",
809
+ "<style scoped>\n",
810
+ " .dataframe tbody tr th:only-of-type {\n",
811
+ " vertical-align: middle;\n",
812
+ " }\n",
813
+ "\n",
814
+ " .dataframe tbody tr th {\n",
815
+ " vertical-align: top;\n",
816
+ " }\n",
817
+ "\n",
818
+ " .dataframe thead th {\n",
819
+ " text-align: right;\n",
820
+ " }\n",
821
+ "</style>\n",
822
+ "<table border=\"1\" class=\"dataframe\">\n",
823
+ " <thead>\n",
824
+ " <tr style=\"text-align: right;\">\n",
825
+ " <th></th>\n",
826
+ " <th>genre_subgenre</th>\n",
827
+ " <th>spectral_contrast_mean (mix)</th>\n",
828
+ " <th>chroma_mean (mix)</th>\n",
829
+ " <th>melody_variability (vocals)</th>\n",
830
+ " <th>rhythm_onset_rate (mix)</th>\n",
831
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
832
+ " <th>repetition_score custom (mix)</th>\n",
833
+ " <th>pitch_std (mix)</th>\n",
834
+ " <th>tempo_bpm_corrected (mix)</th>\n",
835
+ " <th>tempo_bpm_original (mix)</th>\n",
836
+ " <th>...</th>\n",
837
+ " <th>mfcc_mean_2 (mix)</th>\n",
838
+ " <th>loudness_range_lu custom (mix)</th>\n",
839
+ " <th>zero_crossing_rate (mix)</th>\n",
840
+ " <th>vocab_richness</th>\n",
841
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
842
+ " <th>readability_score</th>\n",
843
+ " <th>energy_essentia (mix)</th>\n",
844
+ " <th>energy_librosa (mix)</th>\n",
845
+ " <th>rms_energy_mean (mix)</th>\n",
846
+ " <th>melody_complexity (vocals)</th>\n",
847
+ " </tr>\n",
848
+ " </thead>\n",
849
+ " <tbody>\n",
850
+ " <tr>\n",
851
+ " <th>55138</th>\n",
852
+ " <td>[Indie Folk, Dream Pop, Indie Pop, Folk Pop, I...</td>\n",
853
+ " <td>18.953288</td>\n",
854
+ " <td>0.438801</td>\n",
855
+ " <td>0.276532</td>\n",
856
+ " <td>5.561111</td>\n",
857
+ " <td>0.136025</td>\n",
858
+ " <td>0.006977</td>\n",
859
+ " <td>48.063896</td>\n",
860
+ " <td>162.070480</td>\n",
861
+ " <td>162.070480</td>\n",
862
+ " <td>...</td>\n",
863
+ " <td>-27.844322</td>\n",
864
+ " <td>6.587286</td>\n",
865
+ " <td>0.058096</td>\n",
866
+ " <td>0.478</td>\n",
867
+ " <td>-15.621501</td>\n",
868
+ " <td>107.0</td>\n",
869
+ " <td>0.201458</td>\n",
870
+ " <td>0.412518</td>\n",
871
+ " <td>0.417358</td>\n",
872
+ " <td>1.500000</td>\n",
873
+ " </tr>\n",
874
+ " <tr>\n",
875
+ " <th>34570</th>\n",
876
+ " <td>[Classic Alternative Rock, Rock]</td>\n",
877
+ " <td>17.648178</td>\n",
878
+ " <td>0.593524</td>\n",
879
+ " <td>0.828343</td>\n",
880
+ " <td>1.917868</td>\n",
881
+ " <td>0.192934</td>\n",
882
+ " <td>0.009650</td>\n",
883
+ " <td>132.527191</td>\n",
884
+ " <td>161.965561</td>\n",
885
+ " <td>161.965561</td>\n",
886
+ " <td>...</td>\n",
887
+ " <td>-38.153713</td>\n",
888
+ " <td>0.697901</td>\n",
889
+ " <td>0.103853</td>\n",
890
+ " <td>0.480</td>\n",
891
+ " <td>-10.773592</td>\n",
892
+ " <td>37.6</td>\n",
893
+ " <td>0.511921</td>\n",
894
+ " <td>0.698029</td>\n",
895
+ " <td>0.706971</td>\n",
896
+ " <td>2.916667</td>\n",
897
+ " </tr>\n",
898
+ " <tr>\n",
899
+ " <th>115446</th>\n",
900
+ " <td>[Dream Pop, Indie Pop, Lo Fi, RnB Soul]</td>\n",
901
+ " <td>19.939022</td>\n",
902
+ " <td>0.460538</td>\n",
903
+ " <td>0.366296</td>\n",
904
+ " <td>2.050000</td>\n",
905
+ " <td>0.137038</td>\n",
906
+ " <td>0.007738</td>\n",
907
+ " <td>108.319832</td>\n",
908
+ " <td>139.820786</td>\n",
909
+ " <td>139.820786</td>\n",
910
+ " <td>...</td>\n",
911
+ " <td>21.716513</td>\n",
912
+ " <td>5.794365</td>\n",
913
+ " <td>0.046103</td>\n",
914
+ " <td>0.622</td>\n",
915
+ " <td>-17.407324</td>\n",
916
+ " <td>54.4</td>\n",
917
+ " <td>0.147544</td>\n",
918
+ " <td>0.324240</td>\n",
919
+ " <td>0.332860</td>\n",
920
+ " <td>1.916667</td>\n",
921
+ " </tr>\n",
922
+ " </tbody>\n",
923
+ "</table>\n",
924
+ "<p>3 rows × 21 columns</p>\n",
925
+ "</div>"
926
+ ]
927
+ },
928
+ "execution_count": 3,
929
+ "metadata": {},
930
+ "output_type": "execute_result"
931
+ }
932
+ ],
933
+ "execution_count": 3
934
+ },
935
+ {
936
+ "metadata": {
937
+ "ExecuteTime": {
938
+ "end_time": "2026-03-31T09:28:47.156213Z",
939
+ "start_time": "2026-03-31T09:28:47.071559100Z"
940
+ }
941
+ },
942
+ "cell_type": "code",
943
+ "source": [
944
+ "X= df.drop(columns=[\"genre_subgenre\"])\n",
945
+ "X"
946
+ ],
947
+ "id": "9d4d262a6e6158b",
948
+ "outputs": [
949
+ {
950
+ "data": {
951
+ "text/plain": [
952
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
953
+ "0 20.440557 0.464204 \n",
954
+ "1 19.657228 0.424237 \n",
955
+ "2 20.115561 0.454093 \n",
956
+ "3 19.659283 0.443467 \n",
957
+ "4 20.855880 0.461875 \n",
958
+ "... ... ... \n",
959
+ "125164 20.244104 0.503082 \n",
960
+ "125165 19.474557 0.567127 \n",
961
+ "125166 19.522079 0.492525 \n",
962
+ "125167 19.721407 0.529660 \n",
963
+ "125168 20.478757 0.498923 \n",
964
+ "\n",
965
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
966
+ "0 0.434021 3.250000 \n",
967
+ "1 0.351001 2.425576 \n",
968
+ "2 0.327000 2.738889 \n",
969
+ "3 0.360642 3.500000 \n",
970
+ "4 0.767493 4.983333 \n",
971
+ "... ... ... \n",
972
+ "125164 0.872020 3.916667 \n",
973
+ "125165 0.567603 4.211111 \n",
974
+ "125166 0.795226 3.722222 \n",
975
+ "125167 0.640377 3.994444 \n",
976
+ "125168 0.570758 3.436631 \n",
977
+ "\n",
978
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
979
+ "0 0.132002 0.006988 \n",
980
+ "1 0.139757 0.007367 \n",
981
+ "2 0.111282 0.006671 \n",
982
+ "3 0.159247 0.007202 \n",
983
+ "4 0.155302 0.007290 \n",
984
+ "... ... ... \n",
985
+ "125164 0.162460 0.008042 \n",
986
+ "125165 0.202201 0.007874 \n",
987
+ "125166 0.180673 0.006816 \n",
988
+ "125167 0.191156 0.006488 \n",
989
+ "125168 0.166860 0.010107 \n",
990
+ "\n",
991
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
992
+ "0 69.616264 152.006775 152.006775 \n",
993
+ "1 156.358124 117.943665 117.943665 \n",
994
+ "2 69.311798 124.344086 124.344086 \n",
995
+ "3 65.514191 109.909401 109.909401 \n",
996
+ "4 127.873909 151.955536 151.955536 \n",
997
+ "... ... ... ... \n",
998
+ "125164 83.902977 81.075050 81.075050 \n",
999
+ "125165 82.328941 101.035919 101.035919 \n",
1000
+ "125166 179.515854 111.822731 111.822731 \n",
1001
+ "125167 64.050621 93.118805 93.118805 \n",
1002
+ "125168 128.814209 123.944077 123.944077 \n",
1003
+ "\n",
1004
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
1005
+ "0 153.058243 -7.368185 1.143722 \n",
1006
+ "1 148.055832 -49.435444 4.708925 \n",
1007
+ "2 166.170502 -5.852028 1.948263 \n",
1008
+ "3 134.211624 -27.524824 1.244652 \n",
1009
+ "4 129.783264 -11.940094 3.452597 \n",
1010
+ "... ... ... ... \n",
1011
+ "125164 117.612518 9.144649 2.602306 \n",
1012
+ "125165 94.410416 -11.153146 1.345105 \n",
1013
+ "125166 115.851357 -48.314766 3.907774 \n",
1014
+ "125167 111.312195 -16.979046 1.437813 \n",
1015
+ "125168 124.521019 -20.625500 6.944749 \n",
1016
+ "\n",
1017
+ " zero_crossing_rate (mix) vocab_richness \\\n",
1018
+ "0 0.045159 0.305 \n",
1019
+ "1 0.070352 0.352 \n",
1020
+ "2 0.036463 0.400 \n",
1021
+ "3 0.064695 0.365 \n",
1022
+ "4 0.056507 0.281 \n",
1023
+ "... ... ... \n",
1024
+ "125164 0.060365 0.389 \n",
1025
+ "125165 0.077860 0.416 \n",
1026
+ "125166 0.095063 0.436 \n",
1027
+ "125167 0.087692 0.411 \n",
1028
+ "125168 0.075311 0.541 \n",
1029
+ "\n",
1030
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
1031
+ "0 -12.104649 20.9 \n",
1032
+ "1 -11.814197 89.4 \n",
1033
+ "2 -12.000179 107.0 \n",
1034
+ "3 -12.435019 105.8 \n",
1035
+ "4 -16.217091 212.3 \n",
1036
+ "... ... ... \n",
1037
+ "125164 -15.233034 2.0 \n",
1038
+ "125165 -13.726265 94.5 \n",
1039
+ "125166 -14.254233 1.8 \n",
1040
+ "125167 -15.104306 1.5 \n",
1041
+ "125168 -15.867487 21.2 \n",
1042
+ "\n",
1043
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
1044
+ "0 0.349783 0.576250 0.578454 \n",
1045
+ "1 0.429792 0.619931 0.632507 \n",
1046
+ "2 0.325114 0.520390 0.579053 \n",
1047
+ "3 0.407647 0.617191 0.617197 \n",
1048
+ "4 0.255311 0.446953 0.454712 \n",
1049
+ "... ... ... ... \n",
1050
+ "125164 0.202741 0.378823 0.384110 \n",
1051
+ "125165 0.275752 0.470764 0.481895 \n",
1052
+ "125166 0.265776 0.457695 0.472769 \n",
1053
+ "125167 0.185114 0.360564 0.403058 \n",
1054
+ "125168 0.280897 0.475058 0.475100 \n",
1055
+ "\n",
1056
+ " melody_complexity (vocals) \n",
1057
+ "0 2.250000 \n",
1058
+ "1 1.916667 \n",
1059
+ "2 1.833333 \n",
1060
+ "3 1.916667 \n",
1061
+ "4 3.500000 \n",
1062
+ "... ... \n",
1063
+ "125164 3.666667 \n",
1064
+ "125165 2.833333 \n",
1065
+ "125166 3.583333 \n",
1066
+ "125167 3.416667 \n",
1067
+ "125168 2.666667 \n",
1068
+ "\n",
1069
+ "[125169 rows x 20 columns]"
1070
+ ],
1071
+ "text/html": [
1072
+ "<div>\n",
1073
+ "<style scoped>\n",
1074
+ " .dataframe tbody tr th:only-of-type {\n",
1075
+ " vertical-align: middle;\n",
1076
+ " }\n",
1077
+ "\n",
1078
+ " .dataframe tbody tr th {\n",
1079
+ " vertical-align: top;\n",
1080
+ " }\n",
1081
+ "\n",
1082
+ " .dataframe thead th {\n",
1083
+ " text-align: right;\n",
1084
+ " }\n",
1085
+ "</style>\n",
1086
+ "<table border=\"1\" class=\"dataframe\">\n",
1087
+ " <thead>\n",
1088
+ " <tr style=\"text-align: right;\">\n",
1089
+ " <th></th>\n",
1090
+ " <th>spectral_contrast_mean (mix)</th>\n",
1091
+ " <th>chroma_mean (mix)</th>\n",
1092
+ " <th>melody_variability (vocals)</th>\n",
1093
+ " <th>rhythm_onset_rate (mix)</th>\n",
1094
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
1095
+ " <th>repetition_score custom (mix)</th>\n",
1096
+ " <th>pitch_std (mix)</th>\n",
1097
+ " <th>tempo_bpm_corrected (mix)</th>\n",
1098
+ " <th>tempo_bpm_original (mix)</th>\n",
1099
+ " <th>mfcc_mean_1 (mix)</th>\n",
1100
+ " <th>mfcc_mean_2 (mix)</th>\n",
1101
+ " <th>loudness_range_lu custom (mix)</th>\n",
1102
+ " <th>zero_crossing_rate (mix)</th>\n",
1103
+ " <th>vocab_richness</th>\n",
1104
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
1105
+ " <th>readability_score</th>\n",
1106
+ " <th>energy_essentia (mix)</th>\n",
1107
+ " <th>energy_librosa (mix)</th>\n",
1108
+ " <th>rms_energy_mean (mix)</th>\n",
1109
+ " <th>melody_complexity (vocals)</th>\n",
1110
+ " </tr>\n",
1111
+ " </thead>\n",
1112
+ " <tbody>\n",
1113
+ " <tr>\n",
1114
+ " <th>0</th>\n",
1115
+ " <td>20.440557</td>\n",
1116
+ " <td>0.464204</td>\n",
1117
+ " <td>0.434021</td>\n",
1118
+ " <td>3.250000</td>\n",
1119
+ " <td>0.132002</td>\n",
1120
+ " <td>0.006988</td>\n",
1121
+ " <td>69.616264</td>\n",
1122
+ " <td>152.006775</td>\n",
1123
+ " <td>152.006775</td>\n",
1124
+ " <td>153.058243</td>\n",
1125
+ " <td>-7.368185</td>\n",
1126
+ " <td>1.143722</td>\n",
1127
+ " <td>0.045159</td>\n",
1128
+ " <td>0.305</td>\n",
1129
+ " <td>-12.104649</td>\n",
1130
+ " <td>20.9</td>\n",
1131
+ " <td>0.349783</td>\n",
1132
+ " <td>0.576250</td>\n",
1133
+ " <td>0.578454</td>\n",
1134
+ " <td>2.250000</td>\n",
1135
+ " </tr>\n",
1136
+ " <tr>\n",
1137
+ " <th>1</th>\n",
1138
+ " <td>19.657228</td>\n",
1139
+ " <td>0.424237</td>\n",
1140
+ " <td>0.351001</td>\n",
1141
+ " <td>2.425576</td>\n",
1142
+ " <td>0.139757</td>\n",
1143
+ " <td>0.007367</td>\n",
1144
+ " <td>156.358124</td>\n",
1145
+ " <td>117.943665</td>\n",
1146
+ " <td>117.943665</td>\n",
1147
+ " <td>148.055832</td>\n",
1148
+ " <td>-49.435444</td>\n",
1149
+ " <td>4.708925</td>\n",
1150
+ " <td>0.070352</td>\n",
1151
+ " <td>0.352</td>\n",
1152
+ " <td>-11.814197</td>\n",
1153
+ " <td>89.4</td>\n",
1154
+ " <td>0.429792</td>\n",
1155
+ " <td>0.619931</td>\n",
1156
+ " <td>0.632507</td>\n",
1157
+ " <td>1.916667</td>\n",
1158
+ " </tr>\n",
1159
+ " <tr>\n",
1160
+ " <th>2</th>\n",
1161
+ " <td>20.115561</td>\n",
1162
+ " <td>0.454093</td>\n",
1163
+ " <td>0.327000</td>\n",
1164
+ " <td>2.738889</td>\n",
1165
+ " <td>0.111282</td>\n",
1166
+ " <td>0.006671</td>\n",
1167
+ " <td>69.311798</td>\n",
1168
+ " <td>124.344086</td>\n",
1169
+ " <td>124.344086</td>\n",
1170
+ " <td>166.170502</td>\n",
1171
+ " <td>-5.852028</td>\n",
1172
+ " <td>1.948263</td>\n",
1173
+ " <td>0.036463</td>\n",
1174
+ " <td>0.400</td>\n",
1175
+ " <td>-12.000179</td>\n",
1176
+ " <td>107.0</td>\n",
1177
+ " <td>0.325114</td>\n",
1178
+ " <td>0.520390</td>\n",
1179
+ " <td>0.579053</td>\n",
1180
+ " <td>1.833333</td>\n",
1181
+ " </tr>\n",
1182
+ " <tr>\n",
1183
+ " <th>3</th>\n",
1184
+ " <td>19.659283</td>\n",
1185
+ " <td>0.443467</td>\n",
1186
+ " <td>0.360642</td>\n",
1187
+ " <td>3.500000</td>\n",
1188
+ " <td>0.159247</td>\n",
1189
+ " <td>0.007202</td>\n",
1190
+ " <td>65.514191</td>\n",
1191
+ " <td>109.909401</td>\n",
1192
+ " <td>109.909401</td>\n",
1193
+ " <td>134.211624</td>\n",
1194
+ " <td>-27.524824</td>\n",
1195
+ " <td>1.244652</td>\n",
1196
+ " <td>0.064695</td>\n",
1197
+ " <td>0.365</td>\n",
1198
+ " <td>-12.435019</td>\n",
1199
+ " <td>105.8</td>\n",
1200
+ " <td>0.407647</td>\n",
1201
+ " <td>0.617191</td>\n",
1202
+ " <td>0.617197</td>\n",
1203
+ " <td>1.916667</td>\n",
1204
+ " </tr>\n",
1205
+ " <tr>\n",
1206
+ " <th>4</th>\n",
1207
+ " <td>20.855880</td>\n",
1208
+ " <td>0.461875</td>\n",
1209
+ " <td>0.767493</td>\n",
1210
+ " <td>4.983333</td>\n",
1211
+ " <td>0.155302</td>\n",
1212
+ " <td>0.007290</td>\n",
1213
+ " <td>127.873909</td>\n",
1214
+ " <td>151.955536</td>\n",
1215
+ " <td>151.955536</td>\n",
1216
+ " <td>129.783264</td>\n",
1217
+ " <td>-11.940094</td>\n",
1218
+ " <td>3.452597</td>\n",
1219
+ " <td>0.056507</td>\n",
1220
+ " <td>0.281</td>\n",
1221
+ " <td>-16.217091</td>\n",
1222
+ " <td>212.3</td>\n",
1223
+ " <td>0.255311</td>\n",
1224
+ " <td>0.446953</td>\n",
1225
+ " <td>0.454712</td>\n",
1226
+ " <td>3.500000</td>\n",
1227
+ " </tr>\n",
1228
+ " <tr>\n",
1229
+ " <th>...</th>\n",
1230
+ " <td>...</td>\n",
1231
+ " <td>...</td>\n",
1232
+ " <td>...</td>\n",
1233
+ " <td>...</td>\n",
1234
+ " <td>...</td>\n",
1235
+ " <td>...</td>\n",
1236
+ " <td>...</td>\n",
1237
+ " <td>...</td>\n",
1238
+ " <td>...</td>\n",
1239
+ " <td>...</td>\n",
1240
+ " <td>...</td>\n",
1241
+ " <td>...</td>\n",
1242
+ " <td>...</td>\n",
1243
+ " <td>...</td>\n",
1244
+ " <td>...</td>\n",
1245
+ " <td>...</td>\n",
1246
+ " <td>...</td>\n",
1247
+ " <td>...</td>\n",
1248
+ " <td>...</td>\n",
1249
+ " <td>...</td>\n",
1250
+ " </tr>\n",
1251
+ " <tr>\n",
1252
+ " <th>125164</th>\n",
1253
+ " <td>20.244104</td>\n",
1254
+ " <td>0.503082</td>\n",
1255
+ " <td>0.872020</td>\n",
1256
+ " <td>3.916667</td>\n",
1257
+ " <td>0.162460</td>\n",
1258
+ " <td>0.008042</td>\n",
1259
+ " <td>83.902977</td>\n",
1260
+ " <td>81.075050</td>\n",
1261
+ " <td>81.075050</td>\n",
1262
+ " <td>117.612518</td>\n",
1263
+ " <td>9.144649</td>\n",
1264
+ " <td>2.602306</td>\n",
1265
+ " <td>0.060365</td>\n",
1266
+ " <td>0.389</td>\n",
1267
+ " <td>-15.233034</td>\n",
1268
+ " <td>2.0</td>\n",
1269
+ " <td>0.202741</td>\n",
1270
+ " <td>0.378823</td>\n",
1271
+ " <td>0.384110</td>\n",
1272
+ " <td>3.666667</td>\n",
1273
+ " </tr>\n",
1274
+ " <tr>\n",
1275
+ " <th>125165</th>\n",
1276
+ " <td>19.474557</td>\n",
1277
+ " <td>0.567127</td>\n",
1278
+ " <td>0.567603</td>\n",
1279
+ " <td>4.211111</td>\n",
1280
+ " <td>0.202201</td>\n",
1281
+ " <td>0.007874</td>\n",
1282
+ " <td>82.328941</td>\n",
1283
+ " <td>101.035919</td>\n",
1284
+ " <td>101.035919</td>\n",
1285
+ " <td>94.410416</td>\n",
1286
+ " <td>-11.153146</td>\n",
1287
+ " <td>1.345105</td>\n",
1288
+ " <td>0.077860</td>\n",
1289
+ " <td>0.416</td>\n",
1290
+ " <td>-13.726265</td>\n",
1291
+ " <td>94.5</td>\n",
1292
+ " <td>0.275752</td>\n",
1293
+ " <td>0.470764</td>\n",
1294
+ " <td>0.481895</td>\n",
1295
+ " <td>2.833333</td>\n",
1296
+ " </tr>\n",
1297
+ " <tr>\n",
1298
+ " <th>125166</th>\n",
1299
+ " <td>19.522079</td>\n",
1300
+ " <td>0.492525</td>\n",
1301
+ " <td>0.795226</td>\n",
1302
+ " <td>3.722222</td>\n",
1303
+ " <td>0.180673</td>\n",
1304
+ " <td>0.006816</td>\n",
1305
+ " <td>179.515854</td>\n",
1306
+ " <td>111.822731</td>\n",
1307
+ " <td>111.822731</td>\n",
1308
+ " <td>115.851357</td>\n",
1309
+ " <td>-48.314766</td>\n",
1310
+ " <td>3.907774</td>\n",
1311
+ " <td>0.095063</td>\n",
1312
+ " <td>0.436</td>\n",
1313
+ " <td>-14.254233</td>\n",
1314
+ " <td>1.8</td>\n",
1315
+ " <td>0.265776</td>\n",
1316
+ " <td>0.457695</td>\n",
1317
+ " <td>0.472769</td>\n",
1318
+ " <td>3.583333</td>\n",
1319
+ " </tr>\n",
1320
+ " <tr>\n",
1321
+ " <th>125167</th>\n",
1322
+ " <td>19.721407</td>\n",
1323
+ " <td>0.529660</td>\n",
1324
+ " <td>0.640377</td>\n",
1325
+ " <td>3.994444</td>\n",
1326
+ " <td>0.191156</td>\n",
1327
+ " <td>0.006488</td>\n",
1328
+ " <td>64.050621</td>\n",
1329
+ " <td>93.118805</td>\n",
1330
+ " <td>93.118805</td>\n",
1331
+ " <td>111.312195</td>\n",
1332
+ " <td>-16.979046</td>\n",
1333
+ " <td>1.437813</td>\n",
1334
+ " <td>0.087692</td>\n",
1335
+ " <td>0.411</td>\n",
1336
+ " <td>-15.104306</td>\n",
1337
+ " <td>1.5</td>\n",
1338
+ " <td>0.185114</td>\n",
1339
+ " <td>0.360564</td>\n",
1340
+ " <td>0.403058</td>\n",
1341
+ " <td>3.416667</td>\n",
1342
+ " </tr>\n",
1343
+ " <tr>\n",
1344
+ " <th>125168</th>\n",
1345
+ " <td>20.478757</td>\n",
1346
+ " <td>0.498923</td>\n",
1347
+ " <td>0.570758</td>\n",
1348
+ " <td>3.436631</td>\n",
1349
+ " <td>0.166860</td>\n",
1350
+ " <td>0.010107</td>\n",
1351
+ " <td>128.814209</td>\n",
1352
+ " <td>123.944077</td>\n",
1353
+ " <td>123.944077</td>\n",
1354
+ " <td>124.521019</td>\n",
1355
+ " <td>-20.625500</td>\n",
1356
+ " <td>6.944749</td>\n",
1357
+ " <td>0.075311</td>\n",
1358
+ " <td>0.541</td>\n",
1359
+ " <td>-15.867487</td>\n",
1360
+ " <td>21.2</td>\n",
1361
+ " <td>0.280897</td>\n",
1362
+ " <td>0.475058</td>\n",
1363
+ " <td>0.475100</td>\n",
1364
+ " <td>2.666667</td>\n",
1365
+ " </tr>\n",
1366
+ " </tbody>\n",
1367
+ "</table>\n",
1368
+ "<p>125169 rows × 20 columns</p>\n",
1369
+ "</div>"
1370
+ ]
1371
+ },
1372
+ "execution_count": 4,
1373
+ "metadata": {},
1374
+ "output_type": "execute_result"
1375
+ }
1376
+ ],
1377
+ "execution_count": 4
1378
+ },
1379
+ {
1380
+ "metadata": {
1381
+ "ExecuteTime": {
1382
+ "end_time": "2026-03-31T09:28:49.838936400Z",
1383
+ "start_time": "2026-03-31T09:28:49.621738700Z"
1384
+ }
1385
+ },
1386
+ "cell_type": "code",
1387
+ "source": [
1388
+ "mlb = MultiLabelBinarizer()\n",
1389
+ "y = mlb.fit_transform(df['genre_subgenre'])\n",
1390
+ "y"
1391
+ ],
1392
+ "id": "a1b09be302261710",
1393
+ "outputs": [
1394
+ {
1395
+ "data": {
1396
+ "text/plain": [
1397
+ "array([[0, 0, 0, ..., 0, 0, 0],\n",
1398
+ " [0, 0, 0, ..., 0, 0, 0],\n",
1399
+ " [0, 0, 0, ..., 0, 0, 0],\n",
1400
+ " ...,\n",
1401
+ " [0, 0, 0, ..., 0, 0, 0],\n",
1402
+ " [0, 0, 0, ..., 0, 0, 0],\n",
1403
+ " [0, 0, 0, ..., 0, 0, 0]], shape=(125169, 163))"
1404
+ ]
1405
+ },
1406
+ "execution_count": 5,
1407
+ "metadata": {},
1408
+ "output_type": "execute_result"
1409
+ }
1410
+ ],
1411
+ "execution_count": 5
1412
+ },
1413
+ {
1414
+ "metadata": {
1415
+ "ExecuteTime": {
1416
+ "end_time": "2026-03-31T09:28:54.840304600Z",
1417
+ "start_time": "2026-03-31T09:28:54.776756500Z"
1418
+ }
1419
+ },
1420
+ "cell_type": "code",
1421
+ "source": "mlb.classes_",
1422
+ "id": "208d2a63091460eb",
1423
+ "outputs": [
1424
+ {
1425
+ "data": {
1426
+ "text/plain": [
1427
+ "array(['Acoustic', 'Afrobeats', 'Alt', 'Alt Country', 'Alt Electronic',\n",
1428
+ " 'Alt Folk', 'Alt Folk Christian', 'Alt Pop', 'Alt Pop Punk',\n",
1429
+ " 'Alt Punk Rap', 'Alt Soul', 'Alternative Hip Hop',\n",
1430
+ " 'Alternative Indie', 'Alternative RnB', 'Alternative Rock',\n",
1431
+ " 'Ambient', 'Ambient Pop', 'Americana', 'Americana Alt', 'Bad Pop',\n",
1432
+ " 'Baroque Pop', 'Black Metal', 'Bluegrass', 'Boom Bap',\n",
1433
+ " 'British Punk', 'Bro Country', 'CCM', 'Chicano Rap', 'Chillwave',\n",
1434
+ " 'Christian Rap', 'Christian Rock', 'Classic Alternative Rock',\n",
1435
+ " 'Classic Country', 'Classic Rock', 'Conscious Rap',\n",
1436
+ " 'Contemporary Christian', 'Contemporary Country',\n",
1437
+ " 'Contemporary Hip Hop', 'Contemporary RnB', 'Contemporary Singer',\n",
1438
+ " 'Contemporary Singer Songwriter', 'Country', 'Country Folk',\n",
1439
+ " 'Country Gospel', 'Country Pop', 'Country Rock',\n",
1440
+ " 'Country Trap / Hybrid', 'Dance', 'Dance Pop', 'Death Metal',\n",
1441
+ " 'Deep House', 'Doom Metal', 'Dream Pop', 'Drill', 'Drum n Bass',\n",
1442
+ " 'Dubstep', 'EDM', 'East Coast Hip Hop', 'East Coast Rap',\n",
1443
+ " 'Electro', 'Electro Pop', 'Electronic Dance', 'Electropop', 'Emo',\n",
1444
+ " 'Emo Rap', 'Ethereal Wave', 'Folk', 'Folk Alt', 'Folk Pop',\n",
1445
+ " 'Folk Rock', 'Folk Singer Songwriter', 'Funk', 'Funk Alt',\n",
1446
+ " 'Funk Grunge', 'Future Bass', 'G Funk', 'Gangsta', 'Gangsta Rap',\n",
1447
+ " 'Garage Rock', 'Glam Metal', 'Gospel', 'Gospel Christian',\n",
1448
+ " 'Gothic Metal', 'Grunge', 'Hard Rock', 'Hardcore Hip Hop',\n",
1449
+ " 'Hardcore Punk', 'Hardcore Rap', 'Heavy Metal', 'Hip Hop Punk',\n",
1450
+ " 'Hip Hop Rap', 'Honky Tonk', 'House', 'Indie', 'Indie Alt',\n",
1451
+ " 'Indie Electronic', 'Indie Folk', 'Indie Funk', 'Indie Pop',\n",
1452
+ " 'Indie Punk', 'Indie Rock', 'J Pop', 'Jazz Pop', 'Jazz Rap',\n",
1453
+ " 'Jazz-influenced Hip Hop', 'K Pop', 'Latin Pop', 'Lo Fi',\n",
1454
+ " 'Mafioso Rap', 'Mainstream Pop', 'Metal', 'Metal Pop', 'Metalcore',\n",
1455
+ " 'Modern Alternative Rock', 'Modern Neo-Traditional', 'Motown',\n",
1456
+ " 'Neo Soul', 'Neo-Traditional', 'New Jack Swing', 'Noise Pop',\n",
1457
+ " 'Nu Metal', 'Old School Hip Hop', 'Outlaw Country',\n",
1458
+ " 'Political Hip Hop', 'Pop', 'Pop Alt', 'Pop Country', 'Pop Indie',\n",
1459
+ " 'Pop Metal', 'Pop Punk', 'Pop Rap', 'Pop Rock', 'Post Punk',\n",
1460
+ " 'Post-Rock', 'Praise and Worship', 'Progressive Rock',\n",
1461
+ " 'Psychedelic Rock', 'Punk', 'Punk Metal', 'Punk Rock', 'Red Dirt',\n",
1462
+ " 'RnB Soul', 'Rock', 'Shoegaze', 'Songwriter', 'Soul',\n",
1463
+ " 'Southern Gospel', 'Southern Hip Hop', 'Southern Rap',\n",
1464
+ " 'Southern Rock', 'Synth Pop', 'Techno', 'Teen Pop',\n",
1465
+ " 'Texas Country', 'Thrash Metal', 'Traditional Folk', 'Trance',\n",
1466
+ " 'Trap', 'UK Garage', 'Underground Hip Hop', 'Underground Rap',\n",
1467
+ " 'Urban Gospel', 'West Coast Hip Hop'], dtype=object)"
1468
+ ]
1469
+ },
1470
+ "execution_count": 6,
1471
+ "metadata": {},
1472
+ "output_type": "execute_result"
1473
+ }
1474
+ ],
1475
+ "execution_count": 6
1476
+ },
1477
+ {
1478
+ "metadata": {
1479
+ "ExecuteTime": {
1480
+ "end_time": "2026-03-31T09:42:33.539216600Z",
1481
+ "start_time": "2026-03-31T09:29:38.234766500Z"
1482
+ }
1483
+ },
1484
+ "cell_type": "code",
1485
+ "source": [
1486
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)\n",
1487
+ "\n",
1488
+ "scaler = StandardScaler()\n",
1489
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
1490
+ "X_test_scaled = scaler.transform(X_test)\n",
1491
+ "\n",
1492
+ "model = MultiOutputClassifier(\n",
1493
+ " XGBClassifier(\n",
1494
+ " n_estimators=1600,\n",
1495
+ " learning_rate=0.03,\n",
1496
+ " max_depth=8,\n",
1497
+ " subsample=0.85,\n",
1498
+ " colsample_bytree=0.8,\n",
1499
+ " random_state=42,\n",
1500
+ " eval_metric='logloss'\n",
1501
+ " ),\n",
1502
+ " n_jobs=-1\n",
1503
+ ")\n",
1504
+ "\n",
1505
+ "model.fit(X_train_scaled, y_train)\n",
1506
+ "\n",
1507
+ "def get_accuracy(X_scaled, y_true, name=\"\"):\n",
1508
+ " y_pred = model.predict(X_scaled)\n",
1509
+ " subset_acc = np.mean(np.all(y_pred == y_true, axis=1))\n",
1510
+ " micro_f1 = f1_score(y_true, y_pred, average='micro')\n",
1511
+ " print(f\"{name} Subset Accuracy: {subset_acc:.4f}\")\n",
1512
+ " print(f\"{name} Micro F1 Score: {micro_f1:.4f}\")\n",
1513
+ "\n",
1514
+ "print(\"=== MODEL ACCURACY ===\")\n",
1515
+ "get_accuracy(X_train_scaled, y_train, \"Train\")\n",
1516
+ "get_accuracy(X_test_scaled, y_test, \"Test\")\n"
1517
+ ],
1518
+ "id": "4689dad33e9555d7",
1519
+ "outputs": [
1520
+ {
1521
+ "name": "stdout",
1522
+ "output_type": "stream",
1523
+ "text": [
1524
+ "=== MODEL ACCURACY ===\n",
1525
+ "Train Subset Accuracy: 0.8454\n",
1526
+ "Train Micro F1 Score: 0.9588\n",
1527
+ "Test Subset Accuracy: 0.1467\n",
1528
+ "Test Micro F1 Score: 0.3416\n"
1529
+ ]
1530
+ }
1531
+ ],
1532
+ "execution_count": 8
1533
+ },
1534
+ {
1535
+ "metadata": {
1536
+ "ExecuteTime": {
1537
+ "end_time": "2026-03-31T09:43:06.181862900Z",
1538
+ "start_time": "2026-03-31T09:42:59.357899600Z"
1539
+ }
1540
+ },
1541
+ "cell_type": "code",
1542
+ "source": [
1543
+ "import joblib\n",
1544
+ "bundle = {\n",
1545
+ " \"model\": model,\n",
1546
+ " \"scaler\": scaler,\n",
1547
+ " \"mlb\": mlb,\n",
1548
+ " \"feature_cols\": X.columns.tolist()\n",
1549
+ "}\n",
1550
+ "joblib.dump(bundle, \"all_genre_and_subgenre.pkl\")\n",
1551
+ "print(\"Model saved successfully!\")"
1552
+ ],
1553
+ "id": "64f64e491b4c551f",
1554
+ "outputs": [
1555
+ {
1556
+ "name": "stdout",
1557
+ "output_type": "stream",
1558
+ "text": [
1559
+ "Model saved successfully!\n"
1560
+ ]
1561
+ }
1562
+ ],
1563
+ "execution_count": 9
1564
+ },
1565
+ {
1566
+ "metadata": {
1567
+ "ExecuteTime": {
1568
+ "end_time": "2026-03-31T09:54:22.048035300Z",
1569
+ "start_time": "2026-03-31T09:54:22.011206500Z"
1570
+ }
1571
+ },
1572
+ "cell_type": "code",
1573
+ "source": [
1574
+ "def manual_predict(row):\n",
1575
+ " input_df = pd.DataFrame([row])\n",
1576
+ " input_numeric = input_df.select_dtypes(include=[np.number]).fillna(0)\n",
1577
+ " for col in X.columns:\n",
1578
+ " if col not in input_numeric.columns:\n",
1579
+ " input_numeric[col] = 0\n",
1580
+ " input_numeric = input_numeric[X.columns]\n",
1581
+ " input_scaled = scaler.transform(input_numeric)\n",
1582
+ " probas = model.predict_proba(input_scaled)\n",
1583
+ " threshold = 0.17\n",
1584
+ " pred_binary = np.zeros((1, y.shape[1]), dtype=int)\n",
1585
+ " print(pred_binary)\n",
1586
+ " for i in range(len(probas)):\n",
1587
+ " if probas[i][0][1] > threshold:\n",
1588
+ " pred_binary[0, i] = 1\n",
1589
+ " subgenres = mlb.inverse_transform(pred_binary)[0]\n",
1590
+ " if len(subgenres) == 0:\n",
1591
+ " return f\"None\"\n",
1592
+ " return subgenres"
1593
+ ],
1594
+ "id": "3a6b67cc34a84ed0",
1595
+ "outputs": [],
1596
+ "execution_count": 19
1597
+ },
1598
+ {
1599
+ "metadata": {
1600
+ "ExecuteTime": {
1601
+ "end_time": "2026-03-31T09:54:22.490382600Z",
1602
+ "start_time": "2026-03-31T09:54:22.419572Z"
1603
+ }
1604
+ },
1605
+ "cell_type": "code",
1606
+ "source": "df[[\"genre_subgenre\"]].iloc[502,]",
1607
+ "id": "64dde8703c32c743",
1608
+ "outputs": [
1609
+ {
1610
+ "data": {
1611
+ "text/plain": [
1612
+ "genre_subgenre [Alternative Hip Hop, Boom Bap, Contemporary H...\n",
1613
+ "Name: 502, dtype: object"
1614
+ ]
1615
+ },
1616
+ "execution_count": 20,
1617
+ "metadata": {},
1618
+ "output_type": "execute_result"
1619
+ }
1620
+ ],
1621
+ "execution_count": 20
1622
+ },
1623
+ {
1624
+ "metadata": {
1625
+ "ExecuteTime": {
1626
+ "end_time": "2026-03-31T09:54:23.151824900Z",
1627
+ "start_time": "2026-03-31T09:54:23.072274100Z"
1628
+ }
1629
+ },
1630
+ "cell_type": "code",
1631
+ "source": "X.iloc[508].to_dict()",
1632
+ "id": "d5d2b028522a07a5",
1633
+ "outputs": [
1634
+ {
1635
+ "data": {
1636
+ "text/plain": [
1637
+ "{'spectral_contrast_mean (mix)': 18.775835817338336,\n",
1638
+ " 'chroma_mean (mix)': 0.4393191337585449,\n",
1639
+ " 'melody_variability (vocals)': 0.7237541064882048,\n",
1640
+ " 'rhythm_onset_rate (mix)': 4.769279513338826,\n",
1641
+ " 'spectral_centroid_mean custom (mix)': 0.1423719443498439,\n",
1642
+ " 'repetition_score custom (mix)': 0.0086769169570016,\n",
1643
+ " 'pitch_std (mix)': 70.28816223144531,\n",
1644
+ " 'tempo_bpm_corrected (mix)': 120.0334014892578,\n",
1645
+ " 'tempo_bpm_original (mix)': 120.0334014892578,\n",
1646
+ " 'mfcc_mean_1 (mix)': 139.3588104248047,\n",
1647
+ " 'mfcc_mean_2 (mix)': -10.140735626220703,\n",
1648
+ " 'loudness_range_lu custom (mix)': 11.643880844116213,\n",
1649
+ " 'zero_crossing_rate (mix)': 0.0576565340161323,\n",
1650
+ " 'vocab_richness': 0.47,\n",
1651
+ " 'loudness_integrated_lufs custom (mix)': -17.81583023071289,\n",
1652
+ " 'readability_score': 159.6,\n",
1653
+ " 'energy_essentia (mix)': 0.1938344933977563,\n",
1654
+ " 'energy_librosa (mix)': 0.3731466044114756,\n",
1655
+ " 'rms_energy_mean (mix)': 0.3730348890104648,\n",
1656
+ " 'melody_complexity (vocals)': 3.1666666666666665}"
1657
+ ]
1658
+ },
1659
+ "execution_count": 21,
1660
+ "metadata": {},
1661
+ "output_type": "execute_result"
1662
+ }
1663
+ ],
1664
+ "execution_count": 21
1665
+ },
1666
+ {
1667
+ "metadata": {
1668
+ "ExecuteTime": {
1669
+ "end_time": "2026-03-31T09:54:24.444755Z",
1670
+ "start_time": "2026-03-31T09:54:23.999858200Z"
1671
+ }
1672
+ },
1673
+ "cell_type": "code",
1674
+ "source": "print(manual_predict(X.iloc[508].to_dict()))",
1675
+ "id": "48a6edb36a09bb6c",
1676
+ "outputs": [
1677
+ {
1678
+ "name": "stdout",
1679
+ "output_type": "stream",
1680
+ "text": [
1681
+ "[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
1682
+ " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
1683
+ " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
1684
+ " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
1685
+ " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]\n",
1686
+ "('Contemporary Hip Hop', 'Hip Hop Rap', 'Trap')\n"
1687
+ ]
1688
+ }
1689
+ ],
1690
+ "execution_count": 22
1691
+ },
1692
+ {
1693
+ "metadata": {
1694
+ "ExecuteTime": {
1695
+ "end_time": "2026-03-31T09:49:35.281450200Z",
1696
+ "start_time": "2026-03-31T09:49:34.980650900Z"
1697
+ }
1698
+ },
1699
+ "cell_type": "code",
1700
+ "source": [
1701
+ "dict_data = {'spectral_contrast_mean (mix)': 21.826375772089914, 'chroma_mean (mix)': 0.3961135149002075, 'melody_variability (vocals)': 0.38250987027377, 'rhythm_onset_rate (mix)': 3.1277777777777778, 'spectral_centroid_mean custom (mix)': 0.15499075010897467, 'repetition_score custom (mix)': 0.0074139935621249506, 'pitch_std (mix)': 74.42411041259766, 'tempo_bpm_corrected (mix)': 128.70570373535156, 'mfcc_mean_1 (mix)': 131.99278259277344, 'mfcc_mean_2 (mix)': -21.035446166992188, 'loudness_range_lu custom (mix)': 5.404609680175781, 'zero_crossing_rate (mix)': 0.06825674325227737, 'vocab_richness': 0.455, 'loudness_integrated_lufs custom (mix)': -13.08819580078125, 'readability_score': 32.8, 'energy_essentia (mix)': 0.32994533436041884, 'energy_librosa (mix)': 0.5203621226467141, 'rms_energy_mean (mix)': 0.5467776892768835, 'melody_complexity (vocals)': 2.25}\n",
1702
+ "\n",
1703
+ "\n",
1704
+ "print(manual_predict(dict_data))"
1705
+ ],
1706
+ "id": "2c84f939df788c50",
1707
+ "outputs": [
1708
+ {
1709
+ "name": "stdout",
1710
+ "output_type": "stream",
1711
+ "text": [
1712
+ "('Pop', 'RnB Soul', 'Rock')\n"
1713
+ ]
1714
+ }
1715
+ ],
1716
+ "execution_count": 18
1717
+ },
1718
+ {
1719
+ "metadata": {},
1720
+ "cell_type": "code",
1721
+ "outputs": [],
1722
+ "execution_count": null,
1723
+ "source": "",
1724
+ "id": "80ec85ef86f5dbc4"
1725
+ }
1726
+ ],
1727
+ "metadata": {
1728
+ "kernelspec": {
1729
+ "display_name": "Python 3",
1730
+ "language": "python",
1731
+ "name": "python3"
1732
+ },
1733
+ "language_info": {
1734
+ "codemirror_mode": {
1735
+ "name": "ipython",
1736
+ "version": 2
1737
+ },
1738
+ "file_extension": ".py",
1739
+ "mimetype": "text/x-python",
1740
+ "name": "python",
1741
+ "nbconvert_exporter": "python",
1742
+ "pygments_lexer": "ipython2",
1743
+ "version": "2.7.6"
1744
+ }
1745
+ },
1746
+ "nbformat": 4,
1747
+ "nbformat_minor": 5
1748
+ }
genre_finder/test_some_codes/main_file.ipynb ADDED
@@ -0,0 +1,2205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "id": "initial_id",
6
+ "metadata": {
7
+ "collapsed": true,
8
+ "ExecuteTime": {
9
+ "end_time": "2026-03-30T19:07:31.853468800Z",
10
+ "start_time": "2026-03-30T19:07:28.033173600Z"
11
+ }
12
+ },
13
+ "source": [
14
+ "import pandas as pd\n",
15
+ "import numpy as np\n",
16
+ "import re\n",
17
+ "import ast\n",
18
+ "from sklearn.model_selection import train_test_split\n",
19
+ "from sklearn.preprocessing import StandardScaler, MultiLabelBinarizer\n",
20
+ "from sklearn.multioutput import MultiOutputClassifier\n",
21
+ "from xgboost import XGBClassifier\n",
22
+ "from sklearn.metrics import f1_score\n",
23
+ "pd.set_option(\"display.max_columns\", None)\n",
24
+ "df = pd.read_csv(\"assets/all_genre.csv\")\n",
25
+ "df.head()"
26
+ ],
27
+ "outputs": [
28
+ {
29
+ "data": {
30
+ "text/plain": [
31
+ " _id genre \\\n",
32
+ "0 69143037d64595f86b812d77 Hip Hop Rap \n",
33
+ "1 691448a64bef1dcbb1d3da1b Hip Hop Rap \n",
34
+ "2 691453c34bef1dcbb1d3de77 Hip Hop Rap \n",
35
+ "3 6914609dfb8126cae4324718 Hip Hop Rap \n",
36
+ "4 691af0f3979070eb7827937c Hip Hop Rap \n",
37
+ "\n",
38
+ " genre_subgenre \\\n",
39
+ "0 Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ... \n",
40
+ "1 Hip Hop Rap --- ['Americana', 'Contemporary Co... \n",
41
+ "2 Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ... \n",
42
+ "3 Hip Hop Rap --- ['Alternative Hip Hop', 'Conte... \n",
43
+ "4 Hip Hop Rap --- ['Alternative Hip Hop', 'Conte... \n",
44
+ "\n",
45
+ " trimmed_audio_duration_sec syllable_count word_count \\\n",
46
+ "0 183.843991 355.0 298.0 \n",
47
+ "1 160.786576 285.0 236.0 \n",
48
+ "2 202.320000 350.0 285.0 \n",
49
+ "3 187.298798 318.0 285.0 \n",
50
+ "4 185.004989 651.0 551.0 \n",
51
+ "\n",
52
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
53
+ "0 20.440557 0.464204 \n",
54
+ "1 19.657228 0.424237 \n",
55
+ "2 20.115561 0.454093 \n",
56
+ "3 19.659283 0.443467 \n",
57
+ "4 20.855880 0.461875 \n",
58
+ "\n",
59
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
60
+ "0 0.434021 3.250000 \n",
61
+ "1 0.351001 2.425576 \n",
62
+ "2 0.327000 2.738889 \n",
63
+ "3 0.360642 3.500000 \n",
64
+ "4 0.767493 4.983333 \n",
65
+ "\n",
66
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
67
+ "0 0.132002 0.006988 \n",
68
+ "1 0.139757 0.007367 \n",
69
+ "2 0.111282 0.006671 \n",
70
+ "3 0.159247 0.007202 \n",
71
+ "4 0.155302 0.007290 \n",
72
+ "\n",
73
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
74
+ "0 69.616264 152.006775 152.006775 \n",
75
+ "1 156.358124 117.943665 117.943665 \n",
76
+ "2 69.311798 124.344086 124.344086 \n",
77
+ "3 65.514191 109.909401 109.909401 \n",
78
+ "4 127.873909 151.955536 151.955536 \n",
79
+ "\n",
80
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
81
+ "0 153.058243 -7.368185 1.143722 \n",
82
+ "1 148.055832 -49.435444 4.708925 \n",
83
+ "2 166.170502 -5.852028 1.948263 \n",
84
+ "3 134.211624 -27.524824 1.244652 \n",
85
+ "4 129.783264 -11.940094 3.452597 \n",
86
+ "\n",
87
+ " zero_crossing_rate (mix) vocab_richness \\\n",
88
+ "0 0.045159 0.305 \n",
89
+ "1 0.070352 0.352 \n",
90
+ "2 0.036463 0.400 \n",
91
+ "3 0.064695 0.365 \n",
92
+ "4 0.056507 0.281 \n",
93
+ "\n",
94
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
95
+ "0 -12.104649 20.9 \n",
96
+ "1 -11.814197 89.4 \n",
97
+ "2 -12.000179 107.0 \n",
98
+ "3 -12.435019 105.8 \n",
99
+ "4 -16.217091 212.3 \n",
100
+ "\n",
101
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
102
+ "0 0.349783 0.576250 0.578454 \n",
103
+ "1 0.429792 0.619931 0.632507 \n",
104
+ "2 0.325114 0.520390 0.579053 \n",
105
+ "3 0.407647 0.617191 0.617197 \n",
106
+ "4 0.255311 0.446953 0.454712 \n",
107
+ "\n",
108
+ " sentiment_score melody_complexity (vocals) avg_word_length \n",
109
+ "0 0.116 2.250000 3.76 \n",
110
+ "1 0.173 1.916667 3.50 \n",
111
+ "2 0.158 1.833333 3.73 \n",
112
+ "3 0.071 1.916667 3.48 \n",
113
+ "4 0.039 3.500000 3.56 "
114
+ ],
115
+ "text/html": [
116
+ "<div>\n",
117
+ "<style scoped>\n",
118
+ " .dataframe tbody tr th:only-of-type {\n",
119
+ " vertical-align: middle;\n",
120
+ " }\n",
121
+ "\n",
122
+ " .dataframe tbody tr th {\n",
123
+ " vertical-align: top;\n",
124
+ " }\n",
125
+ "\n",
126
+ " .dataframe thead th {\n",
127
+ " text-align: right;\n",
128
+ " }\n",
129
+ "</style>\n",
130
+ "<table border=\"1\" class=\"dataframe\">\n",
131
+ " <thead>\n",
132
+ " <tr style=\"text-align: right;\">\n",
133
+ " <th></th>\n",
134
+ " <th>_id</th>\n",
135
+ " <th>genre</th>\n",
136
+ " <th>genre_subgenre</th>\n",
137
+ " <th>trimmed_audio_duration_sec</th>\n",
138
+ " <th>syllable_count</th>\n",
139
+ " <th>word_count</th>\n",
140
+ " <th>spectral_contrast_mean (mix)</th>\n",
141
+ " <th>chroma_mean (mix)</th>\n",
142
+ " <th>melody_variability (vocals)</th>\n",
143
+ " <th>rhythm_onset_rate (mix)</th>\n",
144
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
145
+ " <th>repetition_score custom (mix)</th>\n",
146
+ " <th>pitch_std (mix)</th>\n",
147
+ " <th>tempo_bpm_corrected (mix)</th>\n",
148
+ " <th>tempo_bpm_original (mix)</th>\n",
149
+ " <th>mfcc_mean_1 (mix)</th>\n",
150
+ " <th>mfcc_mean_2 (mix)</th>\n",
151
+ " <th>loudness_range_lu custom (mix)</th>\n",
152
+ " <th>zero_crossing_rate (mix)</th>\n",
153
+ " <th>vocab_richness</th>\n",
154
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
155
+ " <th>readability_score</th>\n",
156
+ " <th>energy_essentia (mix)</th>\n",
157
+ " <th>energy_librosa (mix)</th>\n",
158
+ " <th>rms_energy_mean (mix)</th>\n",
159
+ " <th>sentiment_score</th>\n",
160
+ " <th>melody_complexity (vocals)</th>\n",
161
+ " <th>avg_word_length</th>\n",
162
+ " </tr>\n",
163
+ " </thead>\n",
164
+ " <tbody>\n",
165
+ " <tr>\n",
166
+ " <th>0</th>\n",
167
+ " <td>69143037d64595f86b812d77</td>\n",
168
+ " <td>Hip Hop Rap</td>\n",
169
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ...</td>\n",
170
+ " <td>183.843991</td>\n",
171
+ " <td>355.0</td>\n",
172
+ " <td>298.0</td>\n",
173
+ " <td>20.440557</td>\n",
174
+ " <td>0.464204</td>\n",
175
+ " <td>0.434021</td>\n",
176
+ " <td>3.250000</td>\n",
177
+ " <td>0.132002</td>\n",
178
+ " <td>0.006988</td>\n",
179
+ " <td>69.616264</td>\n",
180
+ " <td>152.006775</td>\n",
181
+ " <td>152.006775</td>\n",
182
+ " <td>153.058243</td>\n",
183
+ " <td>-7.368185</td>\n",
184
+ " <td>1.143722</td>\n",
185
+ " <td>0.045159</td>\n",
186
+ " <td>0.305</td>\n",
187
+ " <td>-12.104649</td>\n",
188
+ " <td>20.9</td>\n",
189
+ " <td>0.349783</td>\n",
190
+ " <td>0.576250</td>\n",
191
+ " <td>0.578454</td>\n",
192
+ " <td>0.116</td>\n",
193
+ " <td>2.250000</td>\n",
194
+ " <td>3.76</td>\n",
195
+ " </tr>\n",
196
+ " <tr>\n",
197
+ " <th>1</th>\n",
198
+ " <td>691448a64bef1dcbb1d3da1b</td>\n",
199
+ " <td>Hip Hop Rap</td>\n",
200
+ " <td>Hip Hop Rap --- ['Americana', 'Contemporary Co...</td>\n",
201
+ " <td>160.786576</td>\n",
202
+ " <td>285.0</td>\n",
203
+ " <td>236.0</td>\n",
204
+ " <td>19.657228</td>\n",
205
+ " <td>0.424237</td>\n",
206
+ " <td>0.351001</td>\n",
207
+ " <td>2.425576</td>\n",
208
+ " <td>0.139757</td>\n",
209
+ " <td>0.007367</td>\n",
210
+ " <td>156.358124</td>\n",
211
+ " <td>117.943665</td>\n",
212
+ " <td>117.943665</td>\n",
213
+ " <td>148.055832</td>\n",
214
+ " <td>-49.435444</td>\n",
215
+ " <td>4.708925</td>\n",
216
+ " <td>0.070352</td>\n",
217
+ " <td>0.352</td>\n",
218
+ " <td>-11.814197</td>\n",
219
+ " <td>89.4</td>\n",
220
+ " <td>0.429792</td>\n",
221
+ " <td>0.619931</td>\n",
222
+ " <td>0.632507</td>\n",
223
+ " <td>0.173</td>\n",
224
+ " <td>1.916667</td>\n",
225
+ " <td>3.50</td>\n",
226
+ " </tr>\n",
227
+ " <tr>\n",
228
+ " <th>2</th>\n",
229
+ " <td>691453c34bef1dcbb1d3de77</td>\n",
230
+ " <td>Hip Hop Rap</td>\n",
231
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ...</td>\n",
232
+ " <td>202.320000</td>\n",
233
+ " <td>350.0</td>\n",
234
+ " <td>285.0</td>\n",
235
+ " <td>20.115561</td>\n",
236
+ " <td>0.454093</td>\n",
237
+ " <td>0.327000</td>\n",
238
+ " <td>2.738889</td>\n",
239
+ " <td>0.111282</td>\n",
240
+ " <td>0.006671</td>\n",
241
+ " <td>69.311798</td>\n",
242
+ " <td>124.344086</td>\n",
243
+ " <td>124.344086</td>\n",
244
+ " <td>166.170502</td>\n",
245
+ " <td>-5.852028</td>\n",
246
+ " <td>1.948263</td>\n",
247
+ " <td>0.036463</td>\n",
248
+ " <td>0.400</td>\n",
249
+ " <td>-12.000179</td>\n",
250
+ " <td>107.0</td>\n",
251
+ " <td>0.325114</td>\n",
252
+ " <td>0.520390</td>\n",
253
+ " <td>0.579053</td>\n",
254
+ " <td>0.158</td>\n",
255
+ " <td>1.833333</td>\n",
256
+ " <td>3.73</td>\n",
257
+ " </tr>\n",
258
+ " <tr>\n",
259
+ " <th>3</th>\n",
260
+ " <td>6914609dfb8126cae4324718</td>\n",
261
+ " <td>Hip Hop Rap</td>\n",
262
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Conte...</td>\n",
263
+ " <td>187.298798</td>\n",
264
+ " <td>318.0</td>\n",
265
+ " <td>285.0</td>\n",
266
+ " <td>19.659283</td>\n",
267
+ " <td>0.443467</td>\n",
268
+ " <td>0.360642</td>\n",
269
+ " <td>3.500000</td>\n",
270
+ " <td>0.159247</td>\n",
271
+ " <td>0.007202</td>\n",
272
+ " <td>65.514191</td>\n",
273
+ " <td>109.909401</td>\n",
274
+ " <td>109.909401</td>\n",
275
+ " <td>134.211624</td>\n",
276
+ " <td>-27.524824</td>\n",
277
+ " <td>1.244652</td>\n",
278
+ " <td>0.064695</td>\n",
279
+ " <td>0.365</td>\n",
280
+ " <td>-12.435019</td>\n",
281
+ " <td>105.8</td>\n",
282
+ " <td>0.407647</td>\n",
283
+ " <td>0.617191</td>\n",
284
+ " <td>0.617197</td>\n",
285
+ " <td>0.071</td>\n",
286
+ " <td>1.916667</td>\n",
287
+ " <td>3.48</td>\n",
288
+ " </tr>\n",
289
+ " <tr>\n",
290
+ " <th>4</th>\n",
291
+ " <td>691af0f3979070eb7827937c</td>\n",
292
+ " <td>Hip Hop Rap</td>\n",
293
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Conte...</td>\n",
294
+ " <td>185.004989</td>\n",
295
+ " <td>651.0</td>\n",
296
+ " <td>551.0</td>\n",
297
+ " <td>20.855880</td>\n",
298
+ " <td>0.461875</td>\n",
299
+ " <td>0.767493</td>\n",
300
+ " <td>4.983333</td>\n",
301
+ " <td>0.155302</td>\n",
302
+ " <td>0.007290</td>\n",
303
+ " <td>127.873909</td>\n",
304
+ " <td>151.955536</td>\n",
305
+ " <td>151.955536</td>\n",
306
+ " <td>129.783264</td>\n",
307
+ " <td>-11.940094</td>\n",
308
+ " <td>3.452597</td>\n",
309
+ " <td>0.056507</td>\n",
310
+ " <td>0.281</td>\n",
311
+ " <td>-16.217091</td>\n",
312
+ " <td>212.3</td>\n",
313
+ " <td>0.255311</td>\n",
314
+ " <td>0.446953</td>\n",
315
+ " <td>0.454712</td>\n",
316
+ " <td>0.039</td>\n",
317
+ " <td>3.500000</td>\n",
318
+ " <td>3.56</td>\n",
319
+ " </tr>\n",
320
+ " </tbody>\n",
321
+ "</table>\n",
322
+ "</div>"
323
+ ]
324
+ },
325
+ "execution_count": 1,
326
+ "metadata": {},
327
+ "output_type": "execute_result"
328
+ }
329
+ ],
330
+ "execution_count": 1
331
+ },
332
+ {
333
+ "metadata": {
334
+ "ExecuteTime": {
335
+ "end_time": "2026-03-30T19:07:36.085695400Z",
336
+ "start_time": "2026-03-30T19:07:35.837094700Z"
337
+ }
338
+ },
339
+ "cell_type": "code",
340
+ "source": [
341
+ "def parse_subgenres_fast(text):\n",
342
+ " if pd.isna(text) or text == \"\":\n",
343
+ " return []\n",
344
+ " text = str(text)\n",
345
+ " parts = text.split('---')\n",
346
+ "\n",
347
+ " main_genre = parts[0].strip()\n",
348
+ "\n",
349
+ " if len(parts) > 1:\n",
350
+ " sub = parts[1].strip().strip('[]')\n",
351
+ " subgenres = [s.strip().strip(\"'\").strip('\"') for s in sub.split(',')] if sub else []\n",
352
+ " else:\n",
353
+ " subgenres = []\n",
354
+ "\n",
355
+ " return [main_genre] + subgenres\n",
356
+ "df['subgenres_list'] = df['genre_subgenre'].apply(parse_subgenres_fast)"
357
+ ],
358
+ "id": "67098b6deadbc3ef",
359
+ "outputs": [],
360
+ "execution_count": 2
361
+ },
362
+ {
363
+ "metadata": {
364
+ "ExecuteTime": {
365
+ "end_time": "2026-03-30T19:07:39.104448300Z",
366
+ "start_time": "2026-03-30T19:07:39.016728300Z"
367
+ }
368
+ },
369
+ "cell_type": "code",
370
+ "source": "df['subgenres_list'][0]",
371
+ "id": "e0fc9a9de1291e67",
372
+ "outputs": [
373
+ {
374
+ "data": {
375
+ "text/plain": [
376
+ "['Hip Hop Rap',\n",
377
+ " 'Alternative Hip Hop',\n",
378
+ " 'Boom Bap',\n",
379
+ " 'Contemporary Hip Hop',\n",
380
+ " 'Trap']"
381
+ ]
382
+ },
383
+ "execution_count": 3,
384
+ "metadata": {},
385
+ "output_type": "execute_result"
386
+ }
387
+ ],
388
+ "execution_count": 3
389
+ },
390
+ {
391
+ "metadata": {
392
+ "ExecuteTime": {
393
+ "start_time": "2026-03-30T19:07:51.575299200Z"
394
+ }
395
+ },
396
+ "cell_type": "code",
397
+ "source": [
398
+ "mlb = MultiLabelBinarizer()\n",
399
+ "y = mlb.fit_transform(df['subgenres_list'])\n",
400
+ "\n",
401
+ "drop_cols = ['_id', 'genre', 'genre_subgenre', 'subgenres_list', 'labels',\n",
402
+ " 'trimmed_audio_duration_sec', 'syllable_count', 'word_count',\n",
403
+ " 'sentiment_score', 'avg_word_length']\n",
404
+ "\n",
405
+ "feature_cols = [c for c in df.columns if c not in drop_cols]\n",
406
+ "X = df[feature_cols].copy()\n",
407
+ "X = X.select_dtypes(include=[np.number]).fillna(0)\n",
408
+ "\n",
409
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
410
+ "\n",
411
+ "scaler = StandardScaler()\n",
412
+ "X_train_scaled = scaler.fit_transform(X_train)\n",
413
+ "X_test_scaled = scaler.transform(X_test)\n",
414
+ "\n",
415
+ "model = MultiOutputClassifier(\n",
416
+ " XGBClassifier(\n",
417
+ " n_estimators=1500,\n",
418
+ " learning_rate=0.03,\n",
419
+ " max_depth=8,\n",
420
+ " subsample=0.85,\n",
421
+ " colsample_bytree=0.8,\n",
422
+ " random_state=42,\n",
423
+ " eval_metric='logloss'\n",
424
+ " ),\n",
425
+ " n_jobs=-1\n",
426
+ ")\n",
427
+ "\n",
428
+ "model.fit(X_train_scaled, y_train)\n",
429
+ "\n",
430
+ "\n",
431
+ "def get_accuracy(X_scaled, y_true, name=\"\"):\n",
432
+ " y_pred = model.predict(X_scaled)\n",
433
+ " subset_acc = np.mean(np.all(y_pred == y_true, axis=1))\n",
434
+ " micro_f1 = f1_score(y_true, y_pred, average='micro')\n",
435
+ " print(f\"{name} Subset Accuracy: {subset_acc:.4f}\")\n",
436
+ " print(f\"{name} Micro F1 Score: {micro_f1:.4f}\")\n",
437
+ "\n",
438
+ "print(\"=== MODEL ACCURACY ===\")\n",
439
+ "get_accuracy(X_train_scaled, y_train, \"Train\")\n",
440
+ "get_accuracy(X_test_scaled, y_test, \"Test\")\n",
441
+ "\n",
442
+ "def manual_predict(row):\n",
443
+ " input_df = pd.DataFrame([row])\n",
444
+ " input_numeric = input_df.select_dtypes(include=[np.number]).fillna(0)\n",
445
+ "\n",
446
+ " for col in X.columns:\n",
447
+ " if col not in input_numeric.columns:\n",
448
+ " input_numeric[col] = 0\n",
449
+ "\n",
450
+ " input_numeric = input_numeric[X.columns]\n",
451
+ " input_scaled = scaler.transform(input_numeric)\n",
452
+ "\n",
453
+ " probas = model.predict_proba(input_scaled)\n",
454
+ " threshold = 0.20\n",
455
+ " pred_binary = np.zeros((1, y.shape[1]), dtype=int)\n",
456
+ "\n",
457
+ " for i in range(len(probas)):\n",
458
+ " if probas[i][0][1] > threshold:\n",
459
+ " pred_binary[0, i] = 1\n",
460
+ "\n",
461
+ " subgenres = mlb.inverse_transform(pred_binary)[0]\n",
462
+ " #main_genre = row.get('genre', 'Rock')\n",
463
+ "\n",
464
+ " if len(subgenres) == 0:\n",
465
+ " return f\"None\"\n",
466
+ " return f\"{', '.join(sorted(subgenres))}\""
467
+ ],
468
+ "id": "c1086565f89c486b",
469
+ "outputs": [],
470
+ "execution_count": null
471
+ },
472
+ {
473
+ "metadata": {
474
+ "ExecuteTime": {
475
+ "end_time": "2026-03-27T14:45:34.721003500Z",
476
+ "start_time": "2026-03-27T14:45:34.665870Z"
477
+ }
478
+ },
479
+ "cell_type": "code",
480
+ "source": "X.head()",
481
+ "id": "7036f929b47b9932",
482
+ "outputs": [
483
+ {
484
+ "data": {
485
+ "text/plain": [
486
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
487
+ "0 18.938621 0.462013 \n",
488
+ "1 18.361412 0.515950 \n",
489
+ "2 17.545991 0.505095 \n",
490
+ "3 19.065528 0.532723 \n",
491
+ "4 18.549622 0.560616 \n",
492
+ "\n",
493
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
494
+ "0 0.887239 0.550994 \n",
495
+ "1 0.553844 1.785610 \n",
496
+ "2 0.887161 1.691063 \n",
497
+ "3 0.917722 4.237960 \n",
498
+ "4 0.967337 0.847676 \n",
499
+ "\n",
500
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
501
+ "0 0.124953 0.015320 \n",
502
+ "1 0.178827 0.010278 \n",
503
+ "2 0.115442 0.010617 \n",
504
+ "3 0.134564 0.009808 \n",
505
+ "4 0.179751 0.008122 \n",
506
+ "\n",
507
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
508
+ "0 170.196686 117.459671 117.459671 \n",
509
+ "1 174.526428 93.132881 93.132881 \n",
510
+ "2 98.435074 105.041779 105.041779 \n",
511
+ "3 144.853897 94.973419 94.973419 \n",
512
+ "4 94.283890 108.527031 108.527031 \n",
513
+ "\n",
514
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
515
+ "0 159.208038 -47.135399 17.099110 \n",
516
+ "1 124.982330 -54.048897 10.356828 \n",
517
+ "2 178.284927 -41.860600 4.583549 \n",
518
+ "3 166.110214 -79.556442 3.334763 \n",
519
+ "4 118.163094 -54.811043 0.855955 \n",
520
+ "\n",
521
+ " zero_crossing_rate (mix) vocab_richness \\\n",
522
+ "0 0.065750 0.842 \n",
523
+ "1 0.115698 0.312 \n",
524
+ "2 0.050672 0.462 \n",
525
+ "3 0.085350 0.273 \n",
526
+ "4 0.104765 0.350 \n",
527
+ "\n",
528
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
529
+ "0 -17.450430 1.6 \n",
530
+ "1 -14.291489 5.2 \n",
531
+ "2 -14.021948 18.8 \n",
532
+ "3 -11.496668 1.7 \n",
533
+ "4 -10.031396 52.0 \n",
534
+ "\n",
535
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
536
+ "0 0.400498 0.541834 0.545006 \n",
537
+ "1 0.286286 0.491097 0.492117 \n",
538
+ "2 0.330273 0.539636 0.541554 \n",
539
+ "3 0.525465 0.693286 0.702081 \n",
540
+ "4 0.498986 0.696552 0.698920 \n",
541
+ "\n",
542
+ " melody_complexity (vocals) \n",
543
+ "0 2.833333 \n",
544
+ "1 2.333333 \n",
545
+ "2 3.083333 \n",
546
+ "3 3.166667 \n",
547
+ "4 3.500000 "
548
+ ],
549
+ "text/html": [
550
+ "<div>\n",
551
+ "<style scoped>\n",
552
+ " .dataframe tbody tr th:only-of-type {\n",
553
+ " vertical-align: middle;\n",
554
+ " }\n",
555
+ "\n",
556
+ " .dataframe tbody tr th {\n",
557
+ " vertical-align: top;\n",
558
+ " }\n",
559
+ "\n",
560
+ " .dataframe thead th {\n",
561
+ " text-align: right;\n",
562
+ " }\n",
563
+ "</style>\n",
564
+ "<table border=\"1\" class=\"dataframe\">\n",
565
+ " <thead>\n",
566
+ " <tr style=\"text-align: right;\">\n",
567
+ " <th></th>\n",
568
+ " <th>spectral_contrast_mean (mix)</th>\n",
569
+ " <th>chroma_mean (mix)</th>\n",
570
+ " <th>melody_variability (vocals)</th>\n",
571
+ " <th>rhythm_onset_rate (mix)</th>\n",
572
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
573
+ " <th>repetition_score custom (mix)</th>\n",
574
+ " <th>pitch_std (mix)</th>\n",
575
+ " <th>tempo_bpm_corrected (mix)</th>\n",
576
+ " <th>tempo_bpm_original (mix)</th>\n",
577
+ " <th>mfcc_mean_1 (mix)</th>\n",
578
+ " <th>mfcc_mean_2 (mix)</th>\n",
579
+ " <th>loudness_range_lu custom (mix)</th>\n",
580
+ " <th>zero_crossing_rate (mix)</th>\n",
581
+ " <th>vocab_richness</th>\n",
582
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
583
+ " <th>readability_score</th>\n",
584
+ " <th>energy_essentia (mix)</th>\n",
585
+ " <th>energy_librosa (mix)</th>\n",
586
+ " <th>rms_energy_mean (mix)</th>\n",
587
+ " <th>melody_complexity (vocals)</th>\n",
588
+ " </tr>\n",
589
+ " </thead>\n",
590
+ " <tbody>\n",
591
+ " <tr>\n",
592
+ " <th>0</th>\n",
593
+ " <td>18.938621</td>\n",
594
+ " <td>0.462013</td>\n",
595
+ " <td>0.887239</td>\n",
596
+ " <td>0.550994</td>\n",
597
+ " <td>0.124953</td>\n",
598
+ " <td>0.015320</td>\n",
599
+ " <td>170.196686</td>\n",
600
+ " <td>117.459671</td>\n",
601
+ " <td>117.459671</td>\n",
602
+ " <td>159.208038</td>\n",
603
+ " <td>-47.135399</td>\n",
604
+ " <td>17.099110</td>\n",
605
+ " <td>0.065750</td>\n",
606
+ " <td>0.842</td>\n",
607
+ " <td>-17.450430</td>\n",
608
+ " <td>1.6</td>\n",
609
+ " <td>0.400498</td>\n",
610
+ " <td>0.541834</td>\n",
611
+ " <td>0.545006</td>\n",
612
+ " <td>2.833333</td>\n",
613
+ " </tr>\n",
614
+ " <tr>\n",
615
+ " <th>1</th>\n",
616
+ " <td>18.361412</td>\n",
617
+ " <td>0.515950</td>\n",
618
+ " <td>0.553844</td>\n",
619
+ " <td>1.785610</td>\n",
620
+ " <td>0.178827</td>\n",
621
+ " <td>0.010278</td>\n",
622
+ " <td>174.526428</td>\n",
623
+ " <td>93.132881</td>\n",
624
+ " <td>93.132881</td>\n",
625
+ " <td>124.982330</td>\n",
626
+ " <td>-54.048897</td>\n",
627
+ " <td>10.356828</td>\n",
628
+ " <td>0.115698</td>\n",
629
+ " <td>0.312</td>\n",
630
+ " <td>-14.291489</td>\n",
631
+ " <td>5.2</td>\n",
632
+ " <td>0.286286</td>\n",
633
+ " <td>0.491097</td>\n",
634
+ " <td>0.492117</td>\n",
635
+ " <td>2.333333</td>\n",
636
+ " </tr>\n",
637
+ " <tr>\n",
638
+ " <th>2</th>\n",
639
+ " <td>17.545991</td>\n",
640
+ " <td>0.505095</td>\n",
641
+ " <td>0.887161</td>\n",
642
+ " <td>1.691063</td>\n",
643
+ " <td>0.115442</td>\n",
644
+ " <td>0.010617</td>\n",
645
+ " <td>98.435074</td>\n",
646
+ " <td>105.041779</td>\n",
647
+ " <td>105.041779</td>\n",
648
+ " <td>178.284927</td>\n",
649
+ " <td>-41.860600</td>\n",
650
+ " <td>4.583549</td>\n",
651
+ " <td>0.050672</td>\n",
652
+ " <td>0.462</td>\n",
653
+ " <td>-14.021948</td>\n",
654
+ " <td>18.8</td>\n",
655
+ " <td>0.330273</td>\n",
656
+ " <td>0.539636</td>\n",
657
+ " <td>0.541554</td>\n",
658
+ " <td>3.083333</td>\n",
659
+ " </tr>\n",
660
+ " <tr>\n",
661
+ " <th>3</th>\n",
662
+ " <td>19.065528</td>\n",
663
+ " <td>0.532723</td>\n",
664
+ " <td>0.917722</td>\n",
665
+ " <td>4.237960</td>\n",
666
+ " <td>0.134564</td>\n",
667
+ " <td>0.009808</td>\n",
668
+ " <td>144.853897</td>\n",
669
+ " <td>94.973419</td>\n",
670
+ " <td>94.973419</td>\n",
671
+ " <td>166.110214</td>\n",
672
+ " <td>-79.556442</td>\n",
673
+ " <td>3.334763</td>\n",
674
+ " <td>0.085350</td>\n",
675
+ " <td>0.273</td>\n",
676
+ " <td>-11.496668</td>\n",
677
+ " <td>1.7</td>\n",
678
+ " <td>0.525465</td>\n",
679
+ " <td>0.693286</td>\n",
680
+ " <td>0.702081</td>\n",
681
+ " <td>3.166667</td>\n",
682
+ " </tr>\n",
683
+ " <tr>\n",
684
+ " <th>4</th>\n",
685
+ " <td>18.549622</td>\n",
686
+ " <td>0.560616</td>\n",
687
+ " <td>0.967337</td>\n",
688
+ " <td>0.847676</td>\n",
689
+ " <td>0.179751</td>\n",
690
+ " <td>0.008122</td>\n",
691
+ " <td>94.283890</td>\n",
692
+ " <td>108.527031</td>\n",
693
+ " <td>108.527031</td>\n",
694
+ " <td>118.163094</td>\n",
695
+ " <td>-54.811043</td>\n",
696
+ " <td>0.855955</td>\n",
697
+ " <td>0.104765</td>\n",
698
+ " <td>0.350</td>\n",
699
+ " <td>-10.031396</td>\n",
700
+ " <td>52.0</td>\n",
701
+ " <td>0.498986</td>\n",
702
+ " <td>0.696552</td>\n",
703
+ " <td>0.698920</td>\n",
704
+ " <td>3.500000</td>\n",
705
+ " </tr>\n",
706
+ " </tbody>\n",
707
+ "</table>\n",
708
+ "</div>"
709
+ ]
710
+ },
711
+ "execution_count": 6,
712
+ "metadata": {},
713
+ "output_type": "execute_result"
714
+ }
715
+ ],
716
+ "execution_count": 6
717
+ },
718
+ {
719
+ "metadata": {
720
+ "ExecuteTime": {
721
+ "end_time": "2026-03-27T14:55:56.357032800Z",
722
+ "start_time": "2026-03-27T14:55:56.275652600Z"
723
+ }
724
+ },
725
+ "cell_type": "code",
726
+ "source": "X.shape",
727
+ "id": "f7d2011c6b5f8699",
728
+ "outputs": [
729
+ {
730
+ "data": {
731
+ "text/plain": [
732
+ "(41935, 20)"
733
+ ]
734
+ },
735
+ "execution_count": 15,
736
+ "metadata": {},
737
+ "output_type": "execute_result"
738
+ }
739
+ ],
740
+ "execution_count": 15
741
+ },
742
+ {
743
+ "metadata": {
744
+ "ExecuteTime": {
745
+ "end_time": "2026-03-27T15:10:02.865313500Z",
746
+ "start_time": "2026-03-27T15:10:02.807027900Z"
747
+ }
748
+ },
749
+ "cell_type": "code",
750
+ "source": "df[[\"subgenres_list\",\"genre\"]].iloc[502,]",
751
+ "id": "d462801f323e88a",
752
+ "outputs": [
753
+ {
754
+ "data": {
755
+ "text/plain": [
756
+ "subgenres_list [Modern Alternative Rock, Indie Rock]\n",
757
+ "genre Rock\n",
758
+ "Name: 502, dtype: object"
759
+ ]
760
+ },
761
+ "execution_count": 43,
762
+ "metadata": {},
763
+ "output_type": "execute_result"
764
+ }
765
+ ],
766
+ "execution_count": 43
767
+ },
768
+ {
769
+ "metadata": {
770
+ "ExecuteTime": {
771
+ "end_time": "2026-03-27T15:13:50.114563800Z",
772
+ "start_time": "2026-03-27T15:13:50.060507800Z"
773
+ }
774
+ },
775
+ "cell_type": "code",
776
+ "source": [
777
+ "pd.set_option('display.max_columns', None)\n",
778
+ "df[(df[\"genre\"]==\"Metal\")].head(2)"
779
+ ],
780
+ "id": "1fbd1d7876fb8996",
781
+ "outputs": [
782
+ {
783
+ "data": {
784
+ "text/plain": [
785
+ " _id genre \\\n",
786
+ "41856 691b00908e8610886093475b Metal \n",
787
+ "41857 691c4b322bf3d72bd0be023e Metal \n",
788
+ "\n",
789
+ " genre_subgenre \\\n",
790
+ "41856 Metal --- ['Black Metal', 'Death Metal', 'Doom... \n",
791
+ "41857 Metal --- ['Heavy Metal', 'Thrash Metal'] \n",
792
+ "\n",
793
+ " trimmed_audio_duration_sec syllable_count word_count \\\n",
794
+ "41856 185.602971 185.0 158.0 \n",
795
+ "41857 131.819683 353.0 253.0 \n",
796
+ "\n",
797
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
798
+ "41856 20.152063 0.408171 \n",
799
+ "41857 19.495984 0.517214 \n",
800
+ "\n",
801
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
802
+ "41856 0.374856 2.027778 \n",
803
+ "41857 0.475671 5.803382 \n",
804
+ "\n",
805
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
806
+ "41856 0.093899 0.007882 \n",
807
+ "41857 0.168338 0.007993 \n",
808
+ "\n",
809
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
810
+ "41856 108.278755 104.605293 104.605293 \n",
811
+ "41857 134.086761 138.027847 138.027847 \n",
812
+ "\n",
813
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
814
+ "41856 163.308655 22.928051 7.131201 \n",
815
+ "41857 113.692780 -26.532072 2.994879 \n",
816
+ "\n",
817
+ " zero_crossing_rate (mix) vocab_richness \\\n",
818
+ "41856 0.026933 0.582 \n",
819
+ "41857 0.069337 0.352 \n",
820
+ "\n",
821
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
822
+ "41856 -18.566132 27.8 \n",
823
+ "41857 -13.850066 3.0 \n",
824
+ "\n",
825
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
826
+ "41856 0.153738 0.335069 0.346289 \n",
827
+ "41857 0.266081 0.441120 0.467461 \n",
828
+ "\n",
829
+ " sentiment_score melody_complexity (vocals) avg_word_length \\\n",
830
+ "41856 0.050 1.916667 3.97 \n",
831
+ "41857 0.128 2.250000 4.24 \n",
832
+ "\n",
833
+ " subgenres_list \n",
834
+ "41856 [Black Metal, Death Metal, Doom Metal, Heavy M... \n",
835
+ "41857 [Heavy Metal, Thrash Metal] "
836
+ ],
837
+ "text/html": [
838
+ "<div>\n",
839
+ "<style scoped>\n",
840
+ " .dataframe tbody tr th:only-of-type {\n",
841
+ " vertical-align: middle;\n",
842
+ " }\n",
843
+ "\n",
844
+ " .dataframe tbody tr th {\n",
845
+ " vertical-align: top;\n",
846
+ " }\n",
847
+ "\n",
848
+ " .dataframe thead th {\n",
849
+ " text-align: right;\n",
850
+ " }\n",
851
+ "</style>\n",
852
+ "<table border=\"1\" class=\"dataframe\">\n",
853
+ " <thead>\n",
854
+ " <tr style=\"text-align: right;\">\n",
855
+ " <th></th>\n",
856
+ " <th>_id</th>\n",
857
+ " <th>genre</th>\n",
858
+ " <th>genre_subgenre</th>\n",
859
+ " <th>trimmed_audio_duration_sec</th>\n",
860
+ " <th>syllable_count</th>\n",
861
+ " <th>word_count</th>\n",
862
+ " <th>spectral_contrast_mean (mix)</th>\n",
863
+ " <th>chroma_mean (mix)</th>\n",
864
+ " <th>melody_variability (vocals)</th>\n",
865
+ " <th>rhythm_onset_rate (mix)</th>\n",
866
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
867
+ " <th>repetition_score custom (mix)</th>\n",
868
+ " <th>pitch_std (mix)</th>\n",
869
+ " <th>tempo_bpm_corrected (mix)</th>\n",
870
+ " <th>tempo_bpm_original (mix)</th>\n",
871
+ " <th>mfcc_mean_1 (mix)</th>\n",
872
+ " <th>mfcc_mean_2 (mix)</th>\n",
873
+ " <th>loudness_range_lu custom (mix)</th>\n",
874
+ " <th>zero_crossing_rate (mix)</th>\n",
875
+ " <th>vocab_richness</th>\n",
876
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
877
+ " <th>readability_score</th>\n",
878
+ " <th>energy_essentia (mix)</th>\n",
879
+ " <th>energy_librosa (mix)</th>\n",
880
+ " <th>rms_energy_mean (mix)</th>\n",
881
+ " <th>sentiment_score</th>\n",
882
+ " <th>melody_complexity (vocals)</th>\n",
883
+ " <th>avg_word_length</th>\n",
884
+ " <th>subgenres_list</th>\n",
885
+ " </tr>\n",
886
+ " </thead>\n",
887
+ " <tbody>\n",
888
+ " <tr>\n",
889
+ " <th>41856</th>\n",
890
+ " <td>691b00908e8610886093475b</td>\n",
891
+ " <td>Metal</td>\n",
892
+ " <td>Metal --- ['Black Metal', 'Death Metal', 'Doom...</td>\n",
893
+ " <td>185.602971</td>\n",
894
+ " <td>185.0</td>\n",
895
+ " <td>158.0</td>\n",
896
+ " <td>20.152063</td>\n",
897
+ " <td>0.408171</td>\n",
898
+ " <td>0.374856</td>\n",
899
+ " <td>2.027778</td>\n",
900
+ " <td>0.093899</td>\n",
901
+ " <td>0.007882</td>\n",
902
+ " <td>108.278755</td>\n",
903
+ " <td>104.605293</td>\n",
904
+ " <td>104.605293</td>\n",
905
+ " <td>163.308655</td>\n",
906
+ " <td>22.928051</td>\n",
907
+ " <td>7.131201</td>\n",
908
+ " <td>0.026933</td>\n",
909
+ " <td>0.582</td>\n",
910
+ " <td>-18.566132</td>\n",
911
+ " <td>27.8</td>\n",
912
+ " <td>0.153738</td>\n",
913
+ " <td>0.335069</td>\n",
914
+ " <td>0.346289</td>\n",
915
+ " <td>0.050</td>\n",
916
+ " <td>1.916667</td>\n",
917
+ " <td>3.97</td>\n",
918
+ " <td>[Black Metal, Death Metal, Doom Metal, Heavy M...</td>\n",
919
+ " </tr>\n",
920
+ " <tr>\n",
921
+ " <th>41857</th>\n",
922
+ " <td>691c4b322bf3d72bd0be023e</td>\n",
923
+ " <td>Metal</td>\n",
924
+ " <td>Metal --- ['Heavy Metal', 'Thrash Metal']</td>\n",
925
+ " <td>131.819683</td>\n",
926
+ " <td>353.0</td>\n",
927
+ " <td>253.0</td>\n",
928
+ " <td>19.495984</td>\n",
929
+ " <td>0.517214</td>\n",
930
+ " <td>0.475671</td>\n",
931
+ " <td>5.803382</td>\n",
932
+ " <td>0.168338</td>\n",
933
+ " <td>0.007993</td>\n",
934
+ " <td>134.086761</td>\n",
935
+ " <td>138.027847</td>\n",
936
+ " <td>138.027847</td>\n",
937
+ " <td>113.692780</td>\n",
938
+ " <td>-26.532072</td>\n",
939
+ " <td>2.994879</td>\n",
940
+ " <td>0.069337</td>\n",
941
+ " <td>0.352</td>\n",
942
+ " <td>-13.850066</td>\n",
943
+ " <td>3.0</td>\n",
944
+ " <td>0.266081</td>\n",
945
+ " <td>0.441120</td>\n",
946
+ " <td>0.467461</td>\n",
947
+ " <td>0.128</td>\n",
948
+ " <td>2.250000</td>\n",
949
+ " <td>4.24</td>\n",
950
+ " <td>[Heavy Metal, Thrash Metal]</td>\n",
951
+ " </tr>\n",
952
+ " </tbody>\n",
953
+ "</table>\n",
954
+ "</div>"
955
+ ]
956
+ },
957
+ "execution_count": 50,
958
+ "metadata": {},
959
+ "output_type": "execute_result"
960
+ }
961
+ ],
962
+ "execution_count": 50
963
+ },
964
+ {
965
+ "metadata": {
966
+ "ExecuteTime": {
967
+ "end_time": "2026-03-27T15:24:32.000214700Z",
968
+ "start_time": "2026-03-27T15:24:31.938664600Z"
969
+ }
970
+ },
971
+ "cell_type": "code",
972
+ "source": "X.iloc[41856].to_dict()",
973
+ "id": "37ef9304bdae300c",
974
+ "outputs": [
975
+ {
976
+ "data": {
977
+ "text/plain": [
978
+ "{'spectral_contrast_mean (mix)': 20.1520629356514,\n",
979
+ " 'chroma_mean (mix)': 0.408170998096466,\n",
980
+ " 'melody_variability (vocals)': 0.3748557548841115,\n",
981
+ " 'rhythm_onset_rate (mix)': 2.0277777777777777,\n",
982
+ " 'spectral_centroid_mean custom (mix)': 0.0938994687064515,\n",
983
+ " 'repetition_score custom (mix)': 0.0078822056596288,\n",
984
+ " 'pitch_std (mix)': 108.27875518798828,\n",
985
+ " 'tempo_bpm_corrected (mix)': 104.60529327392578,\n",
986
+ " 'tempo_bpm_original (mix)': 104.60529327392578,\n",
987
+ " 'mfcc_mean_1 (mix)': 163.30865478515625,\n",
988
+ " 'mfcc_mean_2 (mix)': 22.928050994873047,\n",
989
+ " 'loudness_range_lu custom (mix)': 7.131200790405273,\n",
990
+ " 'zero_crossing_rate (mix)': 0.02693298086524,\n",
991
+ " 'vocab_richness': 0.582,\n",
992
+ " 'loudness_integrated_lufs custom (mix)': -18.566131591796875,\n",
993
+ " 'readability_score': 27.8,\n",
994
+ " 'energy_essentia (mix)': 0.1537376961168162,\n",
995
+ " 'energy_librosa (mix)': 0.335069430512918,\n",
996
+ " 'rms_energy_mean (mix)': 0.3462888819034169,\n",
997
+ " 'melody_complexity (vocals)': 1.9166666666666667}"
998
+ ]
999
+ },
1000
+ "execution_count": 58,
1001
+ "metadata": {},
1002
+ "output_type": "execute_result"
1003
+ }
1004
+ ],
1005
+ "execution_count": 58
1006
+ },
1007
+ {
1008
+ "metadata": {
1009
+ "ExecuteTime": {
1010
+ "end_time": "2026-03-27T15:32:09.375740200Z",
1011
+ "start_time": "2026-03-27T15:32:08.891439Z"
1012
+ }
1013
+ },
1014
+ "cell_type": "code",
1015
+ "source": [
1016
+ "print(\"\\n=== FIRST ROW PREDICTION ===\")\n",
1017
+ "print(manual_predict(X.iloc[508].to_dict()))\n",
1018
+ "\n",
1019
+ "print(\"\\n=== LAST ROW PREDICTION ===\")\n",
1020
+ "print(manual_predict(X.iloc[-1].to_dict()))"
1021
+ ],
1022
+ "id": "fef35c101a9a6ad",
1023
+ "outputs": [
1024
+ {
1025
+ "name": "stdout",
1026
+ "output_type": "stream",
1027
+ "text": [
1028
+ "\n",
1029
+ "=== FIRST ROW PREDICTION ===\n",
1030
+ "Indie Pop, Indie Rock, Modern Alternative Rock\n",
1031
+ "\n",
1032
+ "=== LAST ROW PREDICTION ===\n",
1033
+ "Gothic Metal, Heavy Metal, Metalcore\n"
1034
+ ]
1035
+ }
1036
+ ],
1037
+ "execution_count": 63
1038
+ },
1039
+ {
1040
+ "metadata": {
1041
+ "ExecuteTime": {
1042
+ "end_time": "2026-03-27T15:31:39.900012500Z",
1043
+ "start_time": "2026-03-27T15:31:39.638999300Z"
1044
+ }
1045
+ },
1046
+ "cell_type": "code",
1047
+ "source": [
1048
+ "audio_features_ = {\n",
1049
+ " 'spectral_contrast_mean (mix)': 17.245,\n",
1050
+ " 'chroma_mean (mix)': 0.482,\n",
1051
+ " 'melody_variability (vocals)': 0.612,\n",
1052
+ " 'rhythm_onset_rate (mix)': 2.145,\n",
1053
+ " 'spectral_centroid_mean custom (mix)': 0.165,\n",
1054
+ " 'repetition_score custom (mix)': 0.015,\n",
1055
+ " 'pitch_std (mix)': 120.75,\n",
1056
+ " 'tempo_bpm_corrected (mix)': 98.34,\n",
1057
+ " 'tempo_bpm_original (mix)': 100.12,\n",
1058
+ " 'mfcc_mean_1 (mix)': 128.56,\n",
1059
+ " 'mfcc_mean_2 (mix)': -35.78,\n",
1060
+ " 'loudness_range_lu custom (mix)': 8.45,\n",
1061
+ " 'zero_crossing_rate (mix)': 0.089,\n",
1062
+ " 'vocab_richness': 0.29,\n",
1063
+ " 'loudness_integrated_lufs custom (mix)': -12.85,\n",
1064
+ " 'readability_score': 48.5,\n",
1065
+ " 'energy_essentia (mix)': 0.41,\n",
1066
+ " 'energy_librosa (mix)': 0.52,\n",
1067
+ " 'rms_energy_mean (mix)': 0.50,\n",
1068
+ " 'melody_complexity (vocals)': 2.75\n",
1069
+ "}\n",
1070
+ "\n",
1071
+ "answer = manual_predict(audio_features_)\n",
1072
+ "print(answer)"
1073
+ ],
1074
+ "id": "6d8f315863783a68",
1075
+ "outputs": [
1076
+ {
1077
+ "name": "stdout",
1078
+ "output_type": "stream",
1079
+ "text": [
1080
+ "Indie Pop, Indie Rock, Modern Alternative Rock\n"
1081
+ ]
1082
+ }
1083
+ ],
1084
+ "execution_count": 61
1085
+ },
1086
+ {
1087
+ "metadata": {
1088
+ "ExecuteTime": {
1089
+ "end_time": "2026-03-27T15:31:41.650948200Z",
1090
+ "start_time": "2026-03-27T15:31:41.421694900Z"
1091
+ }
1092
+ },
1093
+ "cell_type": "code",
1094
+ "source": [
1095
+ "fake_audio_features_2 = {'spectral_contrast_mean (mix)': 20.1520629356514,\n",
1096
+ " 'chroma_mean (mix)': 0.408170998096466,\n",
1097
+ " 'melody_variability (vocals)': 0.3748557548841115,\n",
1098
+ " 'rhythm_onset_rate (mix)': 2.0277777777777777,\n",
1099
+ " 'spectral_centroid_mean custom (mix)': 0.0938994687064515,\n",
1100
+ " 'repetition_score custom (mix)': 0.0078822056596288,\n",
1101
+ " 'pitch_std (mix)': 108.27875518798828,\n",
1102
+ " 'tempo_bpm_corrected (mix)': 104.60529327392578,\n",
1103
+ " 'tempo_bpm_original (mix)': 104.60529327392578,\n",
1104
+ " 'mfcc_mean_1 (mix)': 163.30865478515625,\n",
1105
+ " 'mfcc_mean_2 (mix)': 22.928050994873047,\n",
1106
+ " 'loudness_range_lu custom (mix)': 7.131200790405273,\n",
1107
+ " 'zero_crossing_rate (mix)': 0.02693298086524,\n",
1108
+ " 'vocab_richness': 0.582,\n",
1109
+ " 'loudness_integrated_lufs custom (mix)': -18.566131591796875,\n",
1110
+ " 'readability_score': 27.8,\n",
1111
+ " 'energy_essentia (mix)': 0.1537376961168162,\n",
1112
+ " 'energy_librosa (mix)': 0.335069430512918,\n",
1113
+ " 'rms_energy_mean (mix)': 0.3462888819034169,\n",
1114
+ " 'melody_complexity (vocals)': 1.9166666666666667}\n",
1115
+ "answer = manual_predict(fake_audio_features_2)\n",
1116
+ "print(answer)"
1117
+ ],
1118
+ "id": "b998289b1d156dc2",
1119
+ "outputs": [
1120
+ {
1121
+ "name": "stdout",
1122
+ "output_type": "stream",
1123
+ "text": [
1124
+ "Black Metal, Death Metal, Doom Metal, Heavy Metal, Metalcore, Thrash Metal\n"
1125
+ ]
1126
+ }
1127
+ ],
1128
+ "execution_count": 62
1129
+ },
1130
+ {
1131
+ "metadata": {
1132
+ "ExecuteTime": {
1133
+ "end_time": "2026-03-27T15:24:02.082478Z",
1134
+ "start_time": "2026-03-27T15:24:01.848007Z"
1135
+ }
1136
+ },
1137
+ "cell_type": "code",
1138
+ "source": [
1139
+ "fake_metal_audio = {\n",
1140
+ " 'spectral_contrast_mean (mix)': 24.85,\n",
1141
+ " 'chroma_mean (mix)': 0.38,\n",
1142
+ " 'melody_variability (vocals)': 0.72,\n",
1143
+ " 'rhythm_onset_rate (mix)': 4.95,\n",
1144
+ " 'spectral_centroid_mean custom (mix)': 0.29,\n",
1145
+ " 'repetition_score custom (mix)': 0.006,\n",
1146
+ " 'pitch_std (mix)': 210.45,\n",
1147
+ " 'tempo_bpm_corrected (mix)': 145.60,\n",
1148
+ " 'tempo_bpm_original (mix)': 147.20,\n",
1149
+ " 'mfcc_mean_1 (mix)': 142.75,\n",
1150
+ " 'mfcc_mean_2 (mix)': -18.34,\n",
1151
+ " 'loudness_range_lu custom (mix)': 6.25,\n",
1152
+ " 'zero_crossing_rate (mix)': 0.18,\n",
1153
+ " 'vocab_richness': 0.27,\n",
1154
+ " 'loudness_integrated_lufs custom (mix)': -8.95,\n",
1155
+ " 'readability_score': 42.0,\n",
1156
+ " 'energy_essentia (mix)': 0.78,\n",
1157
+ " 'energy_librosa (mix)': 0.82,\n",
1158
+ " 'rms_energy_mean (mix)': 0.80,\n",
1159
+ " 'melody_complexity (vocals)': 3.95\n",
1160
+ "}\n",
1161
+ "\n",
1162
+ "answer = manual_predict(fake_metal_audio)\n",
1163
+ "print(answer)"
1164
+ ],
1165
+ "id": "b265ee987709c2a3",
1166
+ "outputs": [
1167
+ {
1168
+ "name": "stdout",
1169
+ "output_type": "stream",
1170
+ "text": [
1171
+ "Rock -- Americana\n"
1172
+ ]
1173
+ }
1174
+ ],
1175
+ "execution_count": 57
1176
+ },
1177
+ {
1178
+ "metadata": {
1179
+ "ExecuteTime": {
1180
+ "end_time": "2026-03-27T15:38:00.278309800Z",
1181
+ "start_time": "2026-03-27T15:37:57.734946600Z"
1182
+ }
1183
+ },
1184
+ "cell_type": "code",
1185
+ "source": "",
1186
+ "id": "228a47b066312e75",
1187
+ "outputs": [
1188
+ {
1189
+ "name": "stdout",
1190
+ "output_type": "stream",
1191
+ "text": [
1192
+ "✅ Model saved as genre_model.pkl\n"
1193
+ ]
1194
+ }
1195
+ ],
1196
+ "execution_count": 64
1197
+ },
1198
+ {
1199
+ "metadata": {
1200
+ "ExecuteTime": {
1201
+ "end_time": "2026-03-27T15:49:22.832888800Z",
1202
+ "start_time": "2026-03-27T15:49:20.228927800Z"
1203
+ }
1204
+ },
1205
+ "cell_type": "code",
1206
+ "source": [
1207
+ "import joblib\n",
1208
+ "bundle = {\n",
1209
+ " \"model\": model,\n",
1210
+ " \"scaler\": scaler,\n",
1211
+ " \"mlb\": mlb,\n",
1212
+ " \"feature_cols\": X.columns.tolist()\n",
1213
+ "}\n",
1214
+ "joblib.dump(bundle, \"genre_model1.pkl\")\n",
1215
+ "print(\"Model saved successfully!\")"
1216
+ ],
1217
+ "id": "694614771e1c62a9",
1218
+ "outputs": [
1219
+ {
1220
+ "name": "stdout",
1221
+ "output_type": "stream",
1222
+ "text": [
1223
+ "Model saved successfully!\n"
1224
+ ]
1225
+ }
1226
+ ],
1227
+ "execution_count": 68
1228
+ },
1229
+ {
1230
+ "metadata": {
1231
+ "ExecuteTime": {
1232
+ "end_time": "2026-03-27T15:49:54.380812800Z",
1233
+ "start_time": "2026-03-27T15:49:51.308892Z"
1234
+ }
1235
+ },
1236
+ "cell_type": "code",
1237
+ "source": [
1238
+ "import joblib\n",
1239
+ "bundle = joblib.load(\"genre_model1.pkl\")\n",
1240
+ "model = bundle[\"model\"]\n",
1241
+ "scaler = bundle[\"scaler\"]\n",
1242
+ "mlb = bundle[\"mlb\"]\n",
1243
+ "feature_cols = bundle[\"feature_cols\"]"
1244
+ ],
1245
+ "id": "bb9f24b4e0947c22",
1246
+ "outputs": [],
1247
+ "execution_count": 70
1248
+ },
1249
+ {
1250
+ "metadata": {
1251
+ "ExecuteTime": {
1252
+ "end_time": "2026-03-27T15:51:05.220558400Z",
1253
+ "start_time": "2026-03-27T15:51:05.157646Z"
1254
+ }
1255
+ },
1256
+ "cell_type": "code",
1257
+ "source": [
1258
+ "def predict_from_loaded(row, model, scaler, mlb, feature_cols):\n",
1259
+ " import pandas as pd\n",
1260
+ " import numpy as np\n",
1261
+ " input_df = pd.DataFrame([row])\n",
1262
+ " input_numeric = input_df.select_dtypes(include=[np.number]).fillna(0)\n",
1263
+ " for col in feature_cols:\n",
1264
+ " if col not in input_numeric.columns:\n",
1265
+ " input_numeric[col] = 0\n",
1266
+ " input_numeric = input_numeric[feature_cols]\n",
1267
+ " input_scaled = scaler.transform(input_numeric)\n",
1268
+ " probas = model.predict_proba(input_scaled)\n",
1269
+ " threshold = 0.20\n",
1270
+ " pred_binary = np.zeros((1, len(probas)), dtype=int)\n",
1271
+ " for i in range(len(probas)):\n",
1272
+ " if probas[i][0][1] > threshold:\n",
1273
+ " pred_binary[0, i] = 1\n",
1274
+ " subgenres = mlb.inverse_transform(pred_binary)[0]\n",
1275
+ " if len(subgenres) == 0:\n",
1276
+ " return \"None\"\n",
1277
+ " return \", \".join(sorted(subgenres))"
1278
+ ],
1279
+ "id": "5391f7697e93bcad",
1280
+ "outputs": [],
1281
+ "execution_count": 71
1282
+ },
1283
+ {
1284
+ "metadata": {
1285
+ "ExecuteTime": {
1286
+ "end_time": "2026-03-27T15:51:42.665671400Z",
1287
+ "start_time": "2026-03-27T15:51:42.509361Z"
1288
+ }
1289
+ },
1290
+ "cell_type": "code",
1291
+ "source": [
1292
+ "audio_features_ = {'spectral_contrast_mean (mix)': 20.1520629356514,\n",
1293
+ " 'chroma_mean (mix)': 0.408170998096466,\n",
1294
+ " 'melody_variability (vocals)': 0.3748557548841115,\n",
1295
+ " 'rhythm_onset_rate (mix)': 2.0277777777777777,\n",
1296
+ " 'spectral_centroid_mean custom (mix)': 0.0938994687064515,\n",
1297
+ " 'repetition_score custom (mix)': 0.0078822056596288,\n",
1298
+ " 'pitch_std (mix)': 108.27875518798828,\n",
1299
+ " 'tempo_bpm_corrected (mix)': 104.60529327392578,\n",
1300
+ " 'tempo_bpm_original (mix)': 104.60529327392578,\n",
1301
+ " 'mfcc_mean_1 (mix)': 163.30865478515625,\n",
1302
+ " 'mfcc_mean_2 (mix)': 22.928050994873047,\n",
1303
+ " 'loudness_range_lu custom (mix)': 7.131200790405273,\n",
1304
+ " 'zero_crossing_rate (mix)': 0.02693298086524,\n",
1305
+ " 'vocab_richness': 0.582,\n",
1306
+ " 'loudness_integrated_lufs custom (mix)': -18.566131591796875,\n",
1307
+ " 'readability_score': 27.8,\n",
1308
+ " 'energy_essentia (mix)': 0.1537376961168162,\n",
1309
+ " 'energy_librosa (mix)': 0.335069430512918,\n",
1310
+ " 'rms_energy_mean (mix)': 0.3462888819034169,\n",
1311
+ " 'melody_complexity (vocals)': 1.9166666666666667}\n",
1312
+ "\n",
1313
+ "result = predict_from_loaded(audio_features_, model, scaler, mlb, feature_cols)\n",
1314
+ "print(result)"
1315
+ ],
1316
+ "id": "cbc80439273b814f",
1317
+ "outputs": [
1318
+ {
1319
+ "name": "stdout",
1320
+ "output_type": "stream",
1321
+ "text": [
1322
+ "Black Metal, Death Metal, Doom Metal, Heavy Metal, Metalcore, Thrash Metal\n"
1323
+ ]
1324
+ }
1325
+ ],
1326
+ "execution_count": 73
1327
+ },
1328
+ {
1329
+ "metadata": {},
1330
+ "cell_type": "markdown",
1331
+ "source": "### 1) All Data",
1332
+ "id": "9a576cffaecfd507"
1333
+ },
1334
+ {
1335
+ "metadata": {
1336
+ "ExecuteTime": {
1337
+ "end_time": "2026-03-30T09:59:36.204702500Z",
1338
+ "start_time": "2026-03-30T09:59:34.858890200Z"
1339
+ }
1340
+ },
1341
+ "cell_type": "code",
1342
+ "source": [
1343
+ "import pandas as pd\n",
1344
+ "path = r\"C:\\Users\\VigneshSubramani\\Downloads\\features_dataset.csv\"\n",
1345
+ "pd.set_option(\"display.max_columns\", None)\n",
1346
+ "data = pd.read_csv(path,low_memory=False)\n",
1347
+ "data"
1348
+ ],
1349
+ "id": "16dcec42226f1c5d",
1350
+ "outputs": [
1351
+ {
1352
+ "data": {
1353
+ "text/plain": [
1354
+ " track_url genre \\\n",
1355
+ "0 https://open.spotify.com/track/38RJG8nLAwGycit... Country \n",
1356
+ "1 https://open.spotify.com/track/2uqYupMHANxnwge... Country \n",
1357
+ "2 https://open.spotify.com/track/48X5k2vce5rXckg... Country \n",
1358
+ "3 https://open.spotify.com/track/3SaS0Va6o6jYkWv... Country \n",
1359
+ "4 https://open.spotify.com/track/09hVlIVHtEE1nLU... Country \n",
1360
+ "... ... ... \n",
1361
+ "138685 https://open.spotify.com/track/6rZno3nqeT7hv2P... Latin Urban \n",
1362
+ "138686 https://open.spotify.com/track/0O4ZJKR2QDLGrBZ... Latin Urban \n",
1363
+ "138687 https://open.spotify.com/track/4oV82xuYkYgyM2n... Latin Urban \n",
1364
+ "138688 https://open.spotify.com/track/3jztoVZMBEaTX0b... Latin Urban \n",
1365
+ "138689 https://open.spotify.com/track/3mUr9hl2VhqorCu... Latin Urban \n",
1366
+ "\n",
1367
+ " name features.melody_complexity (vocals) \\\n",
1368
+ "0 Forever To Me 3.500000 \n",
1369
+ "1 Austin 3.250000 \n",
1370
+ "2 Dirt Cheap 2.750000 \n",
1371
+ "3 I Am Not Okay 2.333333 \n",
1372
+ "4 Burn It Down 3.166667 \n",
1373
+ "... ... ... \n",
1374
+ "138685 YOGURCITO NaN \n",
1375
+ "138686 Me Arriesgo Contigo NaN \n",
1376
+ "138687 Vocales NaN \n",
1377
+ "138688 Tímida NaN \n",
1378
+ "138689 Romeo Y Julieta NaN \n",
1379
+ "\n",
1380
+ " features.melody_range (vocals) features.melody_variability (vocals) \\\n",
1381
+ "0 41.0 0.751713 \n",
1382
+ "1 35.0 0.715152 \n",
1383
+ "2 34.0 0.453325 \n",
1384
+ "3 34.0 0.436993 \n",
1385
+ "4 38.0 0.531330 \n",
1386
+ "... ... ... \n",
1387
+ "138685 NaN NaN \n",
1388
+ "138686 NaN NaN \n",
1389
+ "138687 NaN NaN \n",
1390
+ "138688 NaN NaN \n",
1391
+ "138689 NaN NaN \n",
1392
+ "\n",
1393
+ " features.tempo_bpm_original (mix) features.danceability custom (mix) \\\n",
1394
+ "0 141.384491 0.580731 \n",
1395
+ "1 105.666534 0.747039 \n",
1396
+ "2 110.124130 0.694952 \n",
1397
+ "3 141.088547 0.602134 \n",
1398
+ "4 148.782501 0.603468 \n",
1399
+ "... ... ... \n",
1400
+ "138685 NaN NaN \n",
1401
+ "138686 NaN NaN \n",
1402
+ "138687 NaN NaN \n",
1403
+ "138688 NaN NaN \n",
1404
+ "138689 NaN NaN \n",
1405
+ "\n",
1406
+ " features.loudness_integrated_lufs custom (mix) \\\n",
1407
+ "0 -15.467463 \n",
1408
+ "1 -12.137867 \n",
1409
+ "2 -14.214710 \n",
1410
+ "3 -12.991043 \n",
1411
+ "4 -12.433587 \n",
1412
+ "... ... \n",
1413
+ "138685 NaN \n",
1414
+ "138686 NaN \n",
1415
+ "138687 NaN \n",
1416
+ "138688 NaN \n",
1417
+ "138689 NaN \n",
1418
+ "\n",
1419
+ " features.loudness_range_lu custom (mix) \\\n",
1420
+ "0 11.282878 \n",
1421
+ "1 3.665868 \n",
1422
+ "2 8.500771 \n",
1423
+ "3 3.841528 \n",
1424
+ "4 5.801809 \n",
1425
+ "... ... \n",
1426
+ "138685 NaN \n",
1427
+ "138686 NaN \n",
1428
+ "138687 NaN \n",
1429
+ "138688 NaN \n",
1430
+ "138689 NaN \n",
1431
+ "\n",
1432
+ " features.energy_librosa (mix) features.energy_librosa_std (mix) \\\n",
1433
+ "0 0.419014 0.191760 \n",
1434
+ "1 0.469624 0.169444 \n",
1435
+ "2 0.427623 0.194988 \n",
1436
+ "3 0.524690 0.185032 \n",
1437
+ "4 0.566157 0.145061 \n",
1438
+ "... ... ... \n",
1439
+ "138685 NaN NaN \n",
1440
+ "138686 NaN NaN \n",
1441
+ "138687 NaN NaN \n",
1442
+ "138688 NaN NaN \n",
1443
+ "138689 NaN NaN \n",
1444
+ "\n",
1445
+ " features.energy_essentia (mix) features.energy_essentia_std (mix) \\\n",
1446
+ "0 0.225257 0.167297 \n",
1447
+ "1 0.255954 0.162414 \n",
1448
+ "2 0.226500 0.159222 \n",
1449
+ "3 0.321317 0.172458 \n",
1450
+ "4 0.355688 0.138871 \n",
1451
+ "... ... ... \n",
1452
+ "138685 NaN NaN \n",
1453
+ "138686 NaN NaN \n",
1454
+ "138687 NaN NaN \n",
1455
+ "138688 NaN NaN \n",
1456
+ "138689 NaN NaN \n",
1457
+ "\n",
1458
+ " features.energy_combined (mix) \\\n",
1459
+ "0 0.322135 \n",
1460
+ "1 0.362789 \n",
1461
+ "2 0.327062 \n",
1462
+ "3 0.423004 \n",
1463
+ "4 0.460922 \n",
1464
+ "... ... \n",
1465
+ "138685 NaN \n",
1466
+ "138686 NaN \n",
1467
+ "138687 NaN \n",
1468
+ "138688 NaN \n",
1469
+ "138689 NaN \n",
1470
+ "\n",
1471
+ " features.spectral_centroid_mean custom (mix) \\\n",
1472
+ "0 0.128541 \n",
1473
+ "1 0.121481 \n",
1474
+ "2 0.120138 \n",
1475
+ "3 0.140651 \n",
1476
+ "4 0.127909 \n",
1477
+ "... ... \n",
1478
+ "138685 NaN \n",
1479
+ "138686 NaN \n",
1480
+ "138687 NaN \n",
1481
+ "138688 NaN \n",
1482
+ "138689 NaN \n",
1483
+ "\n",
1484
+ " features.mfcc_mean_1 (mix) features.mfcc_mean_2 (mix) \\\n",
1485
+ "0 144.864594 -7.119251 \n",
1486
+ "1 160.318756 -3.738415 \n",
1487
+ "2 156.815781 -13.236840 \n",
1488
+ "3 143.763428 -21.374804 \n",
1489
+ "4 156.998581 -24.430223 \n",
1490
+ "... ... ... \n",
1491
+ "138685 NaN NaN \n",
1492
+ "138686 NaN NaN \n",
1493
+ "138687 NaN NaN \n",
1494
+ "138688 NaN NaN \n",
1495
+ "138689 NaN NaN \n",
1496
+ "\n",
1497
+ " features.chroma_mean (mix) features.spectral_contrast_mean (mix) \\\n",
1498
+ "0 0.482208 19.678119 \n",
1499
+ "1 0.501811 19.144755 \n",
1500
+ "2 0.452644 19.641929 \n",
1501
+ "3 0.434028 19.570383 \n",
1502
+ "4 0.493009 19.436073 \n",
1503
+ "... ... ... \n",
1504
+ "138685 NaN NaN \n",
1505
+ "138686 NaN NaN \n",
1506
+ "138687 NaN NaN \n",
1507
+ "138688 NaN NaN \n",
1508
+ "138689 NaN NaN \n",
1509
+ "\n",
1510
+ " features.repetition_score custom (mix) features.pitch_mean (mix) \\\n",
1511
+ "0 0.007355 188.741852 \n",
1512
+ "1 0.007224 225.259796 \n",
1513
+ "2 0.006500 184.371185 \n",
1514
+ "3 0.006950 232.608765 \n",
1515
+ "4 0.005922 241.072388 \n",
1516
+ "... ... ... \n",
1517
+ "138685 NaN NaN \n",
1518
+ "138686 NaN NaN \n",
1519
+ "138687 NaN NaN \n",
1520
+ "138688 NaN NaN \n",
1521
+ "138689 NaN NaN \n",
1522
+ "\n",
1523
+ " features.pitch_std (mix) features.rms_energy_mean (mix) \\\n",
1524
+ "0 54.632015 0.432170 \n",
1525
+ "1 90.800995 0.477567 \n",
1526
+ "2 49.438427 0.436157 \n",
1527
+ "3 60.514282 0.537289 \n",
1528
+ "4 98.557098 0.579285 \n",
1529
+ "... ... ... \n",
1530
+ "138685 NaN NaN \n",
1531
+ "138686 NaN NaN \n",
1532
+ "138687 NaN NaN \n",
1533
+ "138688 NaN NaN \n",
1534
+ "138689 NaN NaN \n",
1535
+ "\n",
1536
+ " features.rms_energy_std (mix) features.zero_crossing_rate (mix) \\\n",
1537
+ "0 0.194504 0.042678 \n",
1538
+ "1 0.166947 0.040959 \n",
1539
+ "2 0.192781 0.046456 \n",
1540
+ "3 0.180169 0.056903 \n",
1541
+ "4 0.140620 0.053897 \n",
1542
+ "... ... ... \n",
1543
+ "138685 NaN NaN \n",
1544
+ "138686 NaN NaN \n",
1545
+ "138687 NaN NaN \n",
1546
+ "138688 NaN NaN \n",
1547
+ "138689 NaN NaN \n",
1548
+ "\n",
1549
+ " sub_genre[0] sub_genre[1] sub_genre[2] \\\n",
1550
+ "0 Contemporary Country NaN NaN \n",
1551
+ "1 NaN NaN NaN \n",
1552
+ "2 Modern Neo-Traditional Contemporary Country NaN \n",
1553
+ "3 Americana Country Rock Country Folk \n",
1554
+ "4 NaN NaN NaN \n",
1555
+ "... ... ... ... \n",
1556
+ "138685 Latin Urban NaN NaN \n",
1557
+ "138686 Latin Urban NaN NaN \n",
1558
+ "138687 Latin Urban NaN NaN \n",
1559
+ "138688 Latin Urban NaN NaN \n",
1560
+ "138689 Latin Urban NaN NaN \n",
1561
+ "\n",
1562
+ " sub_genre[3] sub_genre[4] sub_genre[5] sub_genre[6] \\\n",
1563
+ "0 NaN NaN NaN NaN \n",
1564
+ "1 NaN NaN NaN NaN \n",
1565
+ "2 NaN NaN NaN NaN \n",
1566
+ "3 Contemporary Country NaN NaN NaN \n",
1567
+ "4 NaN NaN NaN NaN \n",
1568
+ "... ... ... ... ... \n",
1569
+ "138685 NaN NaN NaN NaN \n",
1570
+ "138686 NaN NaN NaN NaN \n",
1571
+ "138687 NaN NaN NaN NaN \n",
1572
+ "138688 NaN NaN NaN NaN \n",
1573
+ "138689 NaN NaN NaN NaN \n",
1574
+ "\n",
1575
+ " sub_genre[7] sub_genre[8] sub_genre[9] sub_genre[10] sub_genre[11] \\\n",
1576
+ "0 NaN NaN NaN NaN NaN \n",
1577
+ "1 NaN NaN NaN NaN NaN \n",
1578
+ "2 NaN NaN NaN NaN NaN \n",
1579
+ "3 NaN NaN NaN NaN NaN \n",
1580
+ "4 NaN NaN NaN NaN NaN \n",
1581
+ "... ... ... ... ... ... \n",
1582
+ "138685 NaN NaN NaN NaN NaN \n",
1583
+ "138686 NaN NaN NaN NaN NaN \n",
1584
+ "138687 NaN NaN NaN NaN NaN \n",
1585
+ "138688 NaN NaN NaN NaN NaN \n",
1586
+ "138689 NaN NaN NaN NaN NaN \n",
1587
+ "\n",
1588
+ " sub_genre[12] sub_genre[13] sub_genre[14] sub_genre[15] \n",
1589
+ "0 NaN NaN NaN NaN \n",
1590
+ "1 NaN NaN NaN NaN \n",
1591
+ "2 NaN NaN NaN NaN \n",
1592
+ "3 NaN NaN NaN NaN \n",
1593
+ "4 NaN NaN NaN NaN \n",
1594
+ "... ... ... ... ... \n",
1595
+ "138685 NaN NaN NaN NaN \n",
1596
+ "138686 NaN NaN NaN NaN \n",
1597
+ "138687 NaN NaN NaN NaN \n",
1598
+ "138688 NaN NaN NaN NaN \n",
1599
+ "138689 NaN NaN NaN NaN \n",
1600
+ "\n",
1601
+ "[138690 rows x 42 columns]"
1602
+ ],
1603
+ "text/html": [
1604
+ "<div>\n",
1605
+ "<style scoped>\n",
1606
+ " .dataframe tbody tr th:only-of-type {\n",
1607
+ " vertical-align: middle;\n",
1608
+ " }\n",
1609
+ "\n",
1610
+ " .dataframe tbody tr th {\n",
1611
+ " vertical-align: top;\n",
1612
+ " }\n",
1613
+ "\n",
1614
+ " .dataframe thead th {\n",
1615
+ " text-align: right;\n",
1616
+ " }\n",
1617
+ "</style>\n",
1618
+ "<table border=\"1\" class=\"dataframe\">\n",
1619
+ " <thead>\n",
1620
+ " <tr style=\"text-align: right;\">\n",
1621
+ " <th></th>\n",
1622
+ " <th>track_url</th>\n",
1623
+ " <th>genre</th>\n",
1624
+ " <th>name</th>\n",
1625
+ " <th>features.melody_complexity (vocals)</th>\n",
1626
+ " <th>features.melody_range (vocals)</th>\n",
1627
+ " <th>features.melody_variability (vocals)</th>\n",
1628
+ " <th>features.tempo_bpm_original (mix)</th>\n",
1629
+ " <th>features.danceability custom (mix)</th>\n",
1630
+ " <th>features.loudness_integrated_lufs custom (mix)</th>\n",
1631
+ " <th>features.loudness_range_lu custom (mix)</th>\n",
1632
+ " <th>features.energy_librosa (mix)</th>\n",
1633
+ " <th>features.energy_librosa_std (mix)</th>\n",
1634
+ " <th>features.energy_essentia (mix)</th>\n",
1635
+ " <th>features.energy_essentia_std (mix)</th>\n",
1636
+ " <th>features.energy_combined (mix)</th>\n",
1637
+ " <th>features.spectral_centroid_mean custom (mix)</th>\n",
1638
+ " <th>features.mfcc_mean_1 (mix)</th>\n",
1639
+ " <th>features.mfcc_mean_2 (mix)</th>\n",
1640
+ " <th>features.chroma_mean (mix)</th>\n",
1641
+ " <th>features.spectral_contrast_mean (mix)</th>\n",
1642
+ " <th>features.repetition_score custom (mix)</th>\n",
1643
+ " <th>features.pitch_mean (mix)</th>\n",
1644
+ " <th>features.pitch_std (mix)</th>\n",
1645
+ " <th>features.rms_energy_mean (mix)</th>\n",
1646
+ " <th>features.rms_energy_std (mix)</th>\n",
1647
+ " <th>features.zero_crossing_rate (mix)</th>\n",
1648
+ " <th>sub_genre[0]</th>\n",
1649
+ " <th>sub_genre[1]</th>\n",
1650
+ " <th>sub_genre[2]</th>\n",
1651
+ " <th>sub_genre[3]</th>\n",
1652
+ " <th>sub_genre[4]</th>\n",
1653
+ " <th>sub_genre[5]</th>\n",
1654
+ " <th>sub_genre[6]</th>\n",
1655
+ " <th>sub_genre[7]</th>\n",
1656
+ " <th>sub_genre[8]</th>\n",
1657
+ " <th>sub_genre[9]</th>\n",
1658
+ " <th>sub_genre[10]</th>\n",
1659
+ " <th>sub_genre[11]</th>\n",
1660
+ " <th>sub_genre[12]</th>\n",
1661
+ " <th>sub_genre[13]</th>\n",
1662
+ " <th>sub_genre[14]</th>\n",
1663
+ " <th>sub_genre[15]</th>\n",
1664
+ " </tr>\n",
1665
+ " </thead>\n",
1666
+ " <tbody>\n",
1667
+ " <tr>\n",
1668
+ " <th>0</th>\n",
1669
+ " <td>https://open.spotify.com/track/38RJG8nLAwGycit...</td>\n",
1670
+ " <td>Country</td>\n",
1671
+ " <td>Forever To Me</td>\n",
1672
+ " <td>3.500000</td>\n",
1673
+ " <td>41.0</td>\n",
1674
+ " <td>0.751713</td>\n",
1675
+ " <td>141.384491</td>\n",
1676
+ " <td>0.580731</td>\n",
1677
+ " <td>-15.467463</td>\n",
1678
+ " <td>11.282878</td>\n",
1679
+ " <td>0.419014</td>\n",
1680
+ " <td>0.191760</td>\n",
1681
+ " <td>0.225257</td>\n",
1682
+ " <td>0.167297</td>\n",
1683
+ " <td>0.322135</td>\n",
1684
+ " <td>0.128541</td>\n",
1685
+ " <td>144.864594</td>\n",
1686
+ " <td>-7.119251</td>\n",
1687
+ " <td>0.482208</td>\n",
1688
+ " <td>19.678119</td>\n",
1689
+ " <td>0.007355</td>\n",
1690
+ " <td>188.741852</td>\n",
1691
+ " <td>54.632015</td>\n",
1692
+ " <td>0.432170</td>\n",
1693
+ " <td>0.194504</td>\n",
1694
+ " <td>0.042678</td>\n",
1695
+ " <td>Contemporary Country</td>\n",
1696
+ " <td>NaN</td>\n",
1697
+ " <td>NaN</td>\n",
1698
+ " <td>NaN</td>\n",
1699
+ " <td>NaN</td>\n",
1700
+ " <td>NaN</td>\n",
1701
+ " <td>NaN</td>\n",
1702
+ " <td>NaN</td>\n",
1703
+ " <td>NaN</td>\n",
1704
+ " <td>NaN</td>\n",
1705
+ " <td>NaN</td>\n",
1706
+ " <td>NaN</td>\n",
1707
+ " <td>NaN</td>\n",
1708
+ " <td>NaN</td>\n",
1709
+ " <td>NaN</td>\n",
1710
+ " <td>NaN</td>\n",
1711
+ " </tr>\n",
1712
+ " <tr>\n",
1713
+ " <th>1</th>\n",
1714
+ " <td>https://open.spotify.com/track/2uqYupMHANxnwge...</td>\n",
1715
+ " <td>Country</td>\n",
1716
+ " <td>Austin</td>\n",
1717
+ " <td>3.250000</td>\n",
1718
+ " <td>35.0</td>\n",
1719
+ " <td>0.715152</td>\n",
1720
+ " <td>105.666534</td>\n",
1721
+ " <td>0.747039</td>\n",
1722
+ " <td>-12.137867</td>\n",
1723
+ " <td>3.665868</td>\n",
1724
+ " <td>0.469624</td>\n",
1725
+ " <td>0.169444</td>\n",
1726
+ " <td>0.255954</td>\n",
1727
+ " <td>0.162414</td>\n",
1728
+ " <td>0.362789</td>\n",
1729
+ " <td>0.121481</td>\n",
1730
+ " <td>160.318756</td>\n",
1731
+ " <td>-3.738415</td>\n",
1732
+ " <td>0.501811</td>\n",
1733
+ " <td>19.144755</td>\n",
1734
+ " <td>0.007224</td>\n",
1735
+ " <td>225.259796</td>\n",
1736
+ " <td>90.800995</td>\n",
1737
+ " <td>0.477567</td>\n",
1738
+ " <td>0.166947</td>\n",
1739
+ " <td>0.040959</td>\n",
1740
+ " <td>NaN</td>\n",
1741
+ " <td>NaN</td>\n",
1742
+ " <td>NaN</td>\n",
1743
+ " <td>NaN</td>\n",
1744
+ " <td>NaN</td>\n",
1745
+ " <td>NaN</td>\n",
1746
+ " <td>NaN</td>\n",
1747
+ " <td>NaN</td>\n",
1748
+ " <td>NaN</td>\n",
1749
+ " <td>NaN</td>\n",
1750
+ " <td>NaN</td>\n",
1751
+ " <td>NaN</td>\n",
1752
+ " <td>NaN</td>\n",
1753
+ " <td>NaN</td>\n",
1754
+ " <td>NaN</td>\n",
1755
+ " <td>NaN</td>\n",
1756
+ " </tr>\n",
1757
+ " <tr>\n",
1758
+ " <th>2</th>\n",
1759
+ " <td>https://open.spotify.com/track/48X5k2vce5rXckg...</td>\n",
1760
+ " <td>Country</td>\n",
1761
+ " <td>Dirt Cheap</td>\n",
1762
+ " <td>2.750000</td>\n",
1763
+ " <td>34.0</td>\n",
1764
+ " <td>0.453325</td>\n",
1765
+ " <td>110.124130</td>\n",
1766
+ " <td>0.694952</td>\n",
1767
+ " <td>-14.214710</td>\n",
1768
+ " <td>8.500771</td>\n",
1769
+ " <td>0.427623</td>\n",
1770
+ " <td>0.194988</td>\n",
1771
+ " <td>0.226500</td>\n",
1772
+ " <td>0.159222</td>\n",
1773
+ " <td>0.327062</td>\n",
1774
+ " <td>0.120138</td>\n",
1775
+ " <td>156.815781</td>\n",
1776
+ " <td>-13.236840</td>\n",
1777
+ " <td>0.452644</td>\n",
1778
+ " <td>19.641929</td>\n",
1779
+ " <td>0.006500</td>\n",
1780
+ " <td>184.371185</td>\n",
1781
+ " <td>49.438427</td>\n",
1782
+ " <td>0.436157</td>\n",
1783
+ " <td>0.192781</td>\n",
1784
+ " <td>0.046456</td>\n",
1785
+ " <td>Modern Neo-Traditional</td>\n",
1786
+ " <td>Contemporary Country</td>\n",
1787
+ " <td>NaN</td>\n",
1788
+ " <td>NaN</td>\n",
1789
+ " <td>NaN</td>\n",
1790
+ " <td>NaN</td>\n",
1791
+ " <td>NaN</td>\n",
1792
+ " <td>NaN</td>\n",
1793
+ " <td>NaN</td>\n",
1794
+ " <td>NaN</td>\n",
1795
+ " <td>NaN</td>\n",
1796
+ " <td>NaN</td>\n",
1797
+ " <td>NaN</td>\n",
1798
+ " <td>NaN</td>\n",
1799
+ " <td>NaN</td>\n",
1800
+ " <td>NaN</td>\n",
1801
+ " </tr>\n",
1802
+ " <tr>\n",
1803
+ " <th>3</th>\n",
1804
+ " <td>https://open.spotify.com/track/3SaS0Va6o6jYkWv...</td>\n",
1805
+ " <td>Country</td>\n",
1806
+ " <td>I Am Not Okay</td>\n",
1807
+ " <td>2.333333</td>\n",
1808
+ " <td>34.0</td>\n",
1809
+ " <td>0.436993</td>\n",
1810
+ " <td>141.088547</td>\n",
1811
+ " <td>0.602134</td>\n",
1812
+ " <td>-12.991043</td>\n",
1813
+ " <td>3.841528</td>\n",
1814
+ " <td>0.524690</td>\n",
1815
+ " <td>0.185032</td>\n",
1816
+ " <td>0.321317</td>\n",
1817
+ " <td>0.172458</td>\n",
1818
+ " <td>0.423004</td>\n",
1819
+ " <td>0.140651</td>\n",
1820
+ " <td>143.763428</td>\n",
1821
+ " <td>-21.374804</td>\n",
1822
+ " <td>0.434028</td>\n",
1823
+ " <td>19.570383</td>\n",
1824
+ " <td>0.006950</td>\n",
1825
+ " <td>232.608765</td>\n",
1826
+ " <td>60.514282</td>\n",
1827
+ " <td>0.537289</td>\n",
1828
+ " <td>0.180169</td>\n",
1829
+ " <td>0.056903</td>\n",
1830
+ " <td>Americana</td>\n",
1831
+ " <td>Country Rock</td>\n",
1832
+ " <td>Country Folk</td>\n",
1833
+ " <td>Contemporary Country</td>\n",
1834
+ " <td>NaN</td>\n",
1835
+ " <td>NaN</td>\n",
1836
+ " <td>NaN</td>\n",
1837
+ " <td>NaN</td>\n",
1838
+ " <td>NaN</td>\n",
1839
+ " <td>NaN</td>\n",
1840
+ " <td>NaN</td>\n",
1841
+ " <td>NaN</td>\n",
1842
+ " <td>NaN</td>\n",
1843
+ " <td>NaN</td>\n",
1844
+ " <td>NaN</td>\n",
1845
+ " <td>NaN</td>\n",
1846
+ " </tr>\n",
1847
+ " <tr>\n",
1848
+ " <th>4</th>\n",
1849
+ " <td>https://open.spotify.com/track/09hVlIVHtEE1nLU...</td>\n",
1850
+ " <td>Country</td>\n",
1851
+ " <td>Burn It Down</td>\n",
1852
+ " <td>3.166667</td>\n",
1853
+ " <td>38.0</td>\n",
1854
+ " <td>0.531330</td>\n",
1855
+ " <td>148.782501</td>\n",
1856
+ " <td>0.603468</td>\n",
1857
+ " <td>-12.433587</td>\n",
1858
+ " <td>5.801809</td>\n",
1859
+ " <td>0.566157</td>\n",
1860
+ " <td>0.145061</td>\n",
1861
+ " <td>0.355688</td>\n",
1862
+ " <td>0.138871</td>\n",
1863
+ " <td>0.460922</td>\n",
1864
+ " <td>0.127909</td>\n",
1865
+ " <td>156.998581</td>\n",
1866
+ " <td>-24.430223</td>\n",
1867
+ " <td>0.493009</td>\n",
1868
+ " <td>19.436073</td>\n",
1869
+ " <td>0.005922</td>\n",
1870
+ " <td>241.072388</td>\n",
1871
+ " <td>98.557098</td>\n",
1872
+ " <td>0.579285</td>\n",
1873
+ " <td>0.140620</td>\n",
1874
+ " <td>0.053897</td>\n",
1875
+ " <td>NaN</td>\n",
1876
+ " <td>NaN</td>\n",
1877
+ " <td>NaN</td>\n",
1878
+ " <td>NaN</td>\n",
1879
+ " <td>NaN</td>\n",
1880
+ " <td>NaN</td>\n",
1881
+ " <td>NaN</td>\n",
1882
+ " <td>NaN</td>\n",
1883
+ " <td>NaN</td>\n",
1884
+ " <td>NaN</td>\n",
1885
+ " <td>NaN</td>\n",
1886
+ " <td>NaN</td>\n",
1887
+ " <td>NaN</td>\n",
1888
+ " <td>NaN</td>\n",
1889
+ " <td>NaN</td>\n",
1890
+ " <td>NaN</td>\n",
1891
+ " </tr>\n",
1892
+ " <tr>\n",
1893
+ " <th>...</th>\n",
1894
+ " <td>...</td>\n",
1895
+ " <td>...</td>\n",
1896
+ " <td>...</td>\n",
1897
+ " <td>...</td>\n",
1898
+ " <td>...</td>\n",
1899
+ " <td>...</td>\n",
1900
+ " <td>...</td>\n",
1901
+ " <td>...</td>\n",
1902
+ " <td>...</td>\n",
1903
+ " <td>...</td>\n",
1904
+ " <td>...</td>\n",
1905
+ " <td>...</td>\n",
1906
+ " <td>...</td>\n",
1907
+ " <td>...</td>\n",
1908
+ " <td>...</td>\n",
1909
+ " <td>...</td>\n",
1910
+ " <td>...</td>\n",
1911
+ " <td>...</td>\n",
1912
+ " <td>...</td>\n",
1913
+ " <td>...</td>\n",
1914
+ " <td>...</td>\n",
1915
+ " <td>...</td>\n",
1916
+ " <td>...</td>\n",
1917
+ " <td>...</td>\n",
1918
+ " <td>...</td>\n",
1919
+ " <td>...</td>\n",
1920
+ " <td>...</td>\n",
1921
+ " <td>...</td>\n",
1922
+ " <td>...</td>\n",
1923
+ " <td>...</td>\n",
1924
+ " <td>...</td>\n",
1925
+ " <td>...</td>\n",
1926
+ " <td>...</td>\n",
1927
+ " <td>...</td>\n",
1928
+ " <td>...</td>\n",
1929
+ " <td>...</td>\n",
1930
+ " <td>...</td>\n",
1931
+ " <td>...</td>\n",
1932
+ " <td>...</td>\n",
1933
+ " <td>...</td>\n",
1934
+ " <td>...</td>\n",
1935
+ " <td>...</td>\n",
1936
+ " </tr>\n",
1937
+ " <tr>\n",
1938
+ " <th>138685</th>\n",
1939
+ " <td>https://open.spotify.com/track/6rZno3nqeT7hv2P...</td>\n",
1940
+ " <td>Latin Urban</td>\n",
1941
+ " <td>YOGURCITO</td>\n",
1942
+ " <td>NaN</td>\n",
1943
+ " <td>NaN</td>\n",
1944
+ " <td>NaN</td>\n",
1945
+ " <td>NaN</td>\n",
1946
+ " <td>NaN</td>\n",
1947
+ " <td>NaN</td>\n",
1948
+ " <td>NaN</td>\n",
1949
+ " <td>NaN</td>\n",
1950
+ " <td>NaN</td>\n",
1951
+ " <td>NaN</td>\n",
1952
+ " <td>NaN</td>\n",
1953
+ " <td>NaN</td>\n",
1954
+ " <td>NaN</td>\n",
1955
+ " <td>NaN</td>\n",
1956
+ " <td>NaN</td>\n",
1957
+ " <td>NaN</td>\n",
1958
+ " <td>NaN</td>\n",
1959
+ " <td>NaN</td>\n",
1960
+ " <td>NaN</td>\n",
1961
+ " <td>NaN</td>\n",
1962
+ " <td>NaN</td>\n",
1963
+ " <td>NaN</td>\n",
1964
+ " <td>NaN</td>\n",
1965
+ " <td>Latin Urban</td>\n",
1966
+ " <td>NaN</td>\n",
1967
+ " <td>NaN</td>\n",
1968
+ " <td>NaN</td>\n",
1969
+ " <td>NaN</td>\n",
1970
+ " <td>NaN</td>\n",
1971
+ " <td>NaN</td>\n",
1972
+ " <td>NaN</td>\n",
1973
+ " <td>NaN</td>\n",
1974
+ " <td>NaN</td>\n",
1975
+ " <td>NaN</td>\n",
1976
+ " <td>NaN</td>\n",
1977
+ " <td>NaN</td>\n",
1978
+ " <td>NaN</td>\n",
1979
+ " <td>NaN</td>\n",
1980
+ " <td>NaN</td>\n",
1981
+ " </tr>\n",
1982
+ " <tr>\n",
1983
+ " <th>138686</th>\n",
1984
+ " <td>https://open.spotify.com/track/0O4ZJKR2QDLGrBZ...</td>\n",
1985
+ " <td>Latin Urban</td>\n",
1986
+ " <td>Me Arriesgo Contigo</td>\n",
1987
+ " <td>NaN</td>\n",
1988
+ " <td>NaN</td>\n",
1989
+ " <td>NaN</td>\n",
1990
+ " <td>NaN</td>\n",
1991
+ " <td>NaN</td>\n",
1992
+ " <td>NaN</td>\n",
1993
+ " <td>NaN</td>\n",
1994
+ " <td>NaN</td>\n",
1995
+ " <td>NaN</td>\n",
1996
+ " <td>NaN</td>\n",
1997
+ " <td>NaN</td>\n",
1998
+ " <td>NaN</td>\n",
1999
+ " <td>NaN</td>\n",
2000
+ " <td>NaN</td>\n",
2001
+ " <td>NaN</td>\n",
2002
+ " <td>NaN</td>\n",
2003
+ " <td>NaN</td>\n",
2004
+ " <td>NaN</td>\n",
2005
+ " <td>NaN</td>\n",
2006
+ " <td>NaN</td>\n",
2007
+ " <td>NaN</td>\n",
2008
+ " <td>NaN</td>\n",
2009
+ " <td>NaN</td>\n",
2010
+ " <td>Latin Urban</td>\n",
2011
+ " <td>NaN</td>\n",
2012
+ " <td>NaN</td>\n",
2013
+ " <td>NaN</td>\n",
2014
+ " <td>NaN</td>\n",
2015
+ " <td>NaN</td>\n",
2016
+ " <td>NaN</td>\n",
2017
+ " <td>NaN</td>\n",
2018
+ " <td>NaN</td>\n",
2019
+ " <td>NaN</td>\n",
2020
+ " <td>NaN</td>\n",
2021
+ " <td>NaN</td>\n",
2022
+ " <td>NaN</td>\n",
2023
+ " <td>NaN</td>\n",
2024
+ " <td>NaN</td>\n",
2025
+ " <td>NaN</td>\n",
2026
+ " </tr>\n",
2027
+ " <tr>\n",
2028
+ " <th>138687</th>\n",
2029
+ " <td>https://open.spotify.com/track/4oV82xuYkYgyM2n...</td>\n",
2030
+ " <td>Latin Urban</td>\n",
2031
+ " <td>Vocales</td>\n",
2032
+ " <td>NaN</td>\n",
2033
+ " <td>NaN</td>\n",
2034
+ " <td>NaN</td>\n",
2035
+ " <td>NaN</td>\n",
2036
+ " <td>NaN</td>\n",
2037
+ " <td>NaN</td>\n",
2038
+ " <td>NaN</td>\n",
2039
+ " <td>NaN</td>\n",
2040
+ " <td>NaN</td>\n",
2041
+ " <td>NaN</td>\n",
2042
+ " <td>NaN</td>\n",
2043
+ " <td>NaN</td>\n",
2044
+ " <td>NaN</td>\n",
2045
+ " <td>NaN</td>\n",
2046
+ " <td>NaN</td>\n",
2047
+ " <td>NaN</td>\n",
2048
+ " <td>NaN</td>\n",
2049
+ " <td>NaN</td>\n",
2050
+ " <td>NaN</td>\n",
2051
+ " <td>NaN</td>\n",
2052
+ " <td>NaN</td>\n",
2053
+ " <td>NaN</td>\n",
2054
+ " <td>NaN</td>\n",
2055
+ " <td>Latin Urban</td>\n",
2056
+ " <td>NaN</td>\n",
2057
+ " <td>NaN</td>\n",
2058
+ " <td>NaN</td>\n",
2059
+ " <td>NaN</td>\n",
2060
+ " <td>NaN</td>\n",
2061
+ " <td>NaN</td>\n",
2062
+ " <td>NaN</td>\n",
2063
+ " <td>NaN</td>\n",
2064
+ " <td>NaN</td>\n",
2065
+ " <td>NaN</td>\n",
2066
+ " <td>NaN</td>\n",
2067
+ " <td>NaN</td>\n",
2068
+ " <td>NaN</td>\n",
2069
+ " <td>NaN</td>\n",
2070
+ " <td>NaN</td>\n",
2071
+ " </tr>\n",
2072
+ " <tr>\n",
2073
+ " <th>138688</th>\n",
2074
+ " <td>https://open.spotify.com/track/3jztoVZMBEaTX0b...</td>\n",
2075
+ " <td>Latin Urban</td>\n",
2076
+ " <td>Tímida</td>\n",
2077
+ " <td>NaN</td>\n",
2078
+ " <td>NaN</td>\n",
2079
+ " <td>NaN</td>\n",
2080
+ " <td>NaN</td>\n",
2081
+ " <td>NaN</td>\n",
2082
+ " <td>NaN</td>\n",
2083
+ " <td>NaN</td>\n",
2084
+ " <td>NaN</td>\n",
2085
+ " <td>NaN</td>\n",
2086
+ " <td>NaN</td>\n",
2087
+ " <td>NaN</td>\n",
2088
+ " <td>NaN</td>\n",
2089
+ " <td>NaN</td>\n",
2090
+ " <td>NaN</td>\n",
2091
+ " <td>NaN</td>\n",
2092
+ " <td>NaN</td>\n",
2093
+ " <td>NaN</td>\n",
2094
+ " <td>NaN</td>\n",
2095
+ " <td>NaN</td>\n",
2096
+ " <td>NaN</td>\n",
2097
+ " <td>NaN</td>\n",
2098
+ " <td>NaN</td>\n",
2099
+ " <td>NaN</td>\n",
2100
+ " <td>Latin Urban</td>\n",
2101
+ " <td>NaN</td>\n",
2102
+ " <td>NaN</td>\n",
2103
+ " <td>NaN</td>\n",
2104
+ " <td>NaN</td>\n",
2105
+ " <td>NaN</td>\n",
2106
+ " <td>NaN</td>\n",
2107
+ " <td>NaN</td>\n",
2108
+ " <td>NaN</td>\n",
2109
+ " <td>NaN</td>\n",
2110
+ " <td>NaN</td>\n",
2111
+ " <td>NaN</td>\n",
2112
+ " <td>NaN</td>\n",
2113
+ " <td>NaN</td>\n",
2114
+ " <td>NaN</td>\n",
2115
+ " <td>NaN</td>\n",
2116
+ " </tr>\n",
2117
+ " <tr>\n",
2118
+ " <th>138689</th>\n",
2119
+ " <td>https://open.spotify.com/track/3mUr9hl2VhqorCu...</td>\n",
2120
+ " <td>Latin Urban</td>\n",
2121
+ " <td>Romeo Y Julieta</td>\n",
2122
+ " <td>NaN</td>\n",
2123
+ " <td>NaN</td>\n",
2124
+ " <td>NaN</td>\n",
2125
+ " <td>NaN</td>\n",
2126
+ " <td>NaN</td>\n",
2127
+ " <td>NaN</td>\n",
2128
+ " <td>NaN</td>\n",
2129
+ " <td>NaN</td>\n",
2130
+ " <td>NaN</td>\n",
2131
+ " <td>NaN</td>\n",
2132
+ " <td>NaN</td>\n",
2133
+ " <td>NaN</td>\n",
2134
+ " <td>NaN</td>\n",
2135
+ " <td>NaN</td>\n",
2136
+ " <td>NaN</td>\n",
2137
+ " <td>NaN</td>\n",
2138
+ " <td>NaN</td>\n",
2139
+ " <td>NaN</td>\n",
2140
+ " <td>NaN</td>\n",
2141
+ " <td>NaN</td>\n",
2142
+ " <td>NaN</td>\n",
2143
+ " <td>NaN</td>\n",
2144
+ " <td>NaN</td>\n",
2145
+ " <td>Latin Urban</td>\n",
2146
+ " <td>NaN</td>\n",
2147
+ " <td>NaN</td>\n",
2148
+ " <td>NaN</td>\n",
2149
+ " <td>NaN</td>\n",
2150
+ " <td>NaN</td>\n",
2151
+ " <td>NaN</td>\n",
2152
+ " <td>NaN</td>\n",
2153
+ " <td>NaN</td>\n",
2154
+ " <td>NaN</td>\n",
2155
+ " <td>NaN</td>\n",
2156
+ " <td>NaN</td>\n",
2157
+ " <td>NaN</td>\n",
2158
+ " <td>NaN</td>\n",
2159
+ " <td>NaN</td>\n",
2160
+ " <td>NaN</td>\n",
2161
+ " </tr>\n",
2162
+ " </tbody>\n",
2163
+ "</table>\n",
2164
+ "<p>138690 rows × 42 columns</p>\n",
2165
+ "</div>"
2166
+ ]
2167
+ },
2168
+ "execution_count": 2,
2169
+ "metadata": {},
2170
+ "output_type": "execute_result"
2171
+ }
2172
+ ],
2173
+ "execution_count": 2
2174
+ },
2175
+ {
2176
+ "metadata": {},
2177
+ "cell_type": "code",
2178
+ "outputs": [],
2179
+ "execution_count": null,
2180
+ "source": "",
2181
+ "id": "a73b0a2127420c43"
2182
+ }
2183
+ ],
2184
+ "metadata": {
2185
+ "kernelspec": {
2186
+ "display_name": "Python 3",
2187
+ "language": "python",
2188
+ "name": "python3"
2189
+ },
2190
+ "language_info": {
2191
+ "codemirror_mode": {
2192
+ "name": "ipython",
2193
+ "version": 2
2194
+ },
2195
+ "file_extension": ".py",
2196
+ "mimetype": "text/x-python",
2197
+ "name": "python",
2198
+ "nbconvert_exporter": "python",
2199
+ "pygments_lexer": "ipython2",
2200
+ "version": "2.7.6"
2201
+ }
2202
+ },
2203
+ "nbformat": 4,
2204
+ "nbformat_minor": 5
2205
+ }
genre_finder/test_some_codes/new_method.ipynb ADDED
@@ -0,0 +1,1523 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "id": "initial_id",
6
+ "metadata": {
7
+ "collapsed": true,
8
+ "ExecuteTime": {
9
+ "end_time": "2026-03-31T03:54:55.631220900Z",
10
+ "start_time": "2026-03-31T03:54:54.937932400Z"
11
+ }
12
+ },
13
+ "source": [
14
+ "import pandas as pd\n",
15
+ "import numpy as np\n",
16
+ "pd.set_option(\"display.max_columns\", None)\n",
17
+ "df = pd.read_csv(\"assets/all_genre.csv\")\n",
18
+ "df.head()"
19
+ ],
20
+ "outputs": [
21
+ {
22
+ "data": {
23
+ "text/plain": [
24
+ " _id genre \\\n",
25
+ "0 69143037d64595f86b812d77 Hip Hop Rap \n",
26
+ "1 691448a64bef1dcbb1d3da1b Hip Hop Rap \n",
27
+ "2 691453c34bef1dcbb1d3de77 Hip Hop Rap \n",
28
+ "3 6914609dfb8126cae4324718 Hip Hop Rap \n",
29
+ "4 691af0f3979070eb7827937c Hip Hop Rap \n",
30
+ "\n",
31
+ " genre_subgenre \\\n",
32
+ "0 Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ... \n",
33
+ "1 Hip Hop Rap --- ['Americana', 'Contemporary Co... \n",
34
+ "2 Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ... \n",
35
+ "3 Hip Hop Rap --- ['Alternative Hip Hop', 'Conte... \n",
36
+ "4 Hip Hop Rap --- ['Alternative Hip Hop', 'Conte... \n",
37
+ "\n",
38
+ " trimmed_audio_duration_sec syllable_count word_count \\\n",
39
+ "0 183.843991 355.0 298.0 \n",
40
+ "1 160.786576 285.0 236.0 \n",
41
+ "2 202.320000 350.0 285.0 \n",
42
+ "3 187.298798 318.0 285.0 \n",
43
+ "4 185.004989 651.0 551.0 \n",
44
+ "\n",
45
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
46
+ "0 20.440557 0.464204 \n",
47
+ "1 19.657228 0.424237 \n",
48
+ "2 20.115561 0.454093 \n",
49
+ "3 19.659283 0.443467 \n",
50
+ "4 20.855880 0.461875 \n",
51
+ "\n",
52
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
53
+ "0 0.434021 3.250000 \n",
54
+ "1 0.351001 2.425576 \n",
55
+ "2 0.327000 2.738889 \n",
56
+ "3 0.360642 3.500000 \n",
57
+ "4 0.767493 4.983333 \n",
58
+ "\n",
59
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
60
+ "0 0.132002 0.006988 \n",
61
+ "1 0.139757 0.007367 \n",
62
+ "2 0.111282 0.006671 \n",
63
+ "3 0.159247 0.007202 \n",
64
+ "4 0.155302 0.007290 \n",
65
+ "\n",
66
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
67
+ "0 69.616264 152.006775 152.006775 \n",
68
+ "1 156.358124 117.943665 117.943665 \n",
69
+ "2 69.311798 124.344086 124.344086 \n",
70
+ "3 65.514191 109.909401 109.909401 \n",
71
+ "4 127.873909 151.955536 151.955536 \n",
72
+ "\n",
73
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
74
+ "0 153.058243 -7.368185 1.143722 \n",
75
+ "1 148.055832 -49.435444 4.708925 \n",
76
+ "2 166.170502 -5.852028 1.948263 \n",
77
+ "3 134.211624 -27.524824 1.244652 \n",
78
+ "4 129.783264 -11.940094 3.452597 \n",
79
+ "\n",
80
+ " zero_crossing_rate (mix) vocab_richness \\\n",
81
+ "0 0.045159 0.305 \n",
82
+ "1 0.070352 0.352 \n",
83
+ "2 0.036463 0.400 \n",
84
+ "3 0.064695 0.365 \n",
85
+ "4 0.056507 0.281 \n",
86
+ "\n",
87
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
88
+ "0 -12.104649 20.9 \n",
89
+ "1 -11.814197 89.4 \n",
90
+ "2 -12.000179 107.0 \n",
91
+ "3 -12.435019 105.8 \n",
92
+ "4 -16.217091 212.3 \n",
93
+ "\n",
94
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
95
+ "0 0.349783 0.576250 0.578454 \n",
96
+ "1 0.429792 0.619931 0.632507 \n",
97
+ "2 0.325114 0.520390 0.579053 \n",
98
+ "3 0.407647 0.617191 0.617197 \n",
99
+ "4 0.255311 0.446953 0.454712 \n",
100
+ "\n",
101
+ " sentiment_score melody_complexity (vocals) avg_word_length \n",
102
+ "0 0.116 2.250000 3.76 \n",
103
+ "1 0.173 1.916667 3.50 \n",
104
+ "2 0.158 1.833333 3.73 \n",
105
+ "3 0.071 1.916667 3.48 \n",
106
+ "4 0.039 3.500000 3.56 "
107
+ ],
108
+ "text/html": [
109
+ "<div>\n",
110
+ "<style scoped>\n",
111
+ " .dataframe tbody tr th:only-of-type {\n",
112
+ " vertical-align: middle;\n",
113
+ " }\n",
114
+ "\n",
115
+ " .dataframe tbody tr th {\n",
116
+ " vertical-align: top;\n",
117
+ " }\n",
118
+ "\n",
119
+ " .dataframe thead th {\n",
120
+ " text-align: right;\n",
121
+ " }\n",
122
+ "</style>\n",
123
+ "<table border=\"1\" class=\"dataframe\">\n",
124
+ " <thead>\n",
125
+ " <tr style=\"text-align: right;\">\n",
126
+ " <th></th>\n",
127
+ " <th>_id</th>\n",
128
+ " <th>genre</th>\n",
129
+ " <th>genre_subgenre</th>\n",
130
+ " <th>trimmed_audio_duration_sec</th>\n",
131
+ " <th>syllable_count</th>\n",
132
+ " <th>word_count</th>\n",
133
+ " <th>spectral_contrast_mean (mix)</th>\n",
134
+ " <th>chroma_mean (mix)</th>\n",
135
+ " <th>melody_variability (vocals)</th>\n",
136
+ " <th>rhythm_onset_rate (mix)</th>\n",
137
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
138
+ " <th>repetition_score custom (mix)</th>\n",
139
+ " <th>pitch_std (mix)</th>\n",
140
+ " <th>tempo_bpm_corrected (mix)</th>\n",
141
+ " <th>tempo_bpm_original (mix)</th>\n",
142
+ " <th>mfcc_mean_1 (mix)</th>\n",
143
+ " <th>mfcc_mean_2 (mix)</th>\n",
144
+ " <th>loudness_range_lu custom (mix)</th>\n",
145
+ " <th>zero_crossing_rate (mix)</th>\n",
146
+ " <th>vocab_richness</th>\n",
147
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
148
+ " <th>readability_score</th>\n",
149
+ " <th>energy_essentia (mix)</th>\n",
150
+ " <th>energy_librosa (mix)</th>\n",
151
+ " <th>rms_energy_mean (mix)</th>\n",
152
+ " <th>sentiment_score</th>\n",
153
+ " <th>melody_complexity (vocals)</th>\n",
154
+ " <th>avg_word_length</th>\n",
155
+ " </tr>\n",
156
+ " </thead>\n",
157
+ " <tbody>\n",
158
+ " <tr>\n",
159
+ " <th>0</th>\n",
160
+ " <td>69143037d64595f86b812d77</td>\n",
161
+ " <td>Hip Hop Rap</td>\n",
162
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ...</td>\n",
163
+ " <td>183.843991</td>\n",
164
+ " <td>355.0</td>\n",
165
+ " <td>298.0</td>\n",
166
+ " <td>20.440557</td>\n",
167
+ " <td>0.464204</td>\n",
168
+ " <td>0.434021</td>\n",
169
+ " <td>3.250000</td>\n",
170
+ " <td>0.132002</td>\n",
171
+ " <td>0.006988</td>\n",
172
+ " <td>69.616264</td>\n",
173
+ " <td>152.006775</td>\n",
174
+ " <td>152.006775</td>\n",
175
+ " <td>153.058243</td>\n",
176
+ " <td>-7.368185</td>\n",
177
+ " <td>1.143722</td>\n",
178
+ " <td>0.045159</td>\n",
179
+ " <td>0.305</td>\n",
180
+ " <td>-12.104649</td>\n",
181
+ " <td>20.9</td>\n",
182
+ " <td>0.349783</td>\n",
183
+ " <td>0.576250</td>\n",
184
+ " <td>0.578454</td>\n",
185
+ " <td>0.116</td>\n",
186
+ " <td>2.250000</td>\n",
187
+ " <td>3.76</td>\n",
188
+ " </tr>\n",
189
+ " <tr>\n",
190
+ " <th>1</th>\n",
191
+ " <td>691448a64bef1dcbb1d3da1b</td>\n",
192
+ " <td>Hip Hop Rap</td>\n",
193
+ " <td>Hip Hop Rap --- ['Americana', 'Contemporary Co...</td>\n",
194
+ " <td>160.786576</td>\n",
195
+ " <td>285.0</td>\n",
196
+ " <td>236.0</td>\n",
197
+ " <td>19.657228</td>\n",
198
+ " <td>0.424237</td>\n",
199
+ " <td>0.351001</td>\n",
200
+ " <td>2.425576</td>\n",
201
+ " <td>0.139757</td>\n",
202
+ " <td>0.007367</td>\n",
203
+ " <td>156.358124</td>\n",
204
+ " <td>117.943665</td>\n",
205
+ " <td>117.943665</td>\n",
206
+ " <td>148.055832</td>\n",
207
+ " <td>-49.435444</td>\n",
208
+ " <td>4.708925</td>\n",
209
+ " <td>0.070352</td>\n",
210
+ " <td>0.352</td>\n",
211
+ " <td>-11.814197</td>\n",
212
+ " <td>89.4</td>\n",
213
+ " <td>0.429792</td>\n",
214
+ " <td>0.619931</td>\n",
215
+ " <td>0.632507</td>\n",
216
+ " <td>0.173</td>\n",
217
+ " <td>1.916667</td>\n",
218
+ " <td>3.50</td>\n",
219
+ " </tr>\n",
220
+ " <tr>\n",
221
+ " <th>2</th>\n",
222
+ " <td>691453c34bef1dcbb1d3de77</td>\n",
223
+ " <td>Hip Hop Rap</td>\n",
224
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Boom ...</td>\n",
225
+ " <td>202.320000</td>\n",
226
+ " <td>350.0</td>\n",
227
+ " <td>285.0</td>\n",
228
+ " <td>20.115561</td>\n",
229
+ " <td>0.454093</td>\n",
230
+ " <td>0.327000</td>\n",
231
+ " <td>2.738889</td>\n",
232
+ " <td>0.111282</td>\n",
233
+ " <td>0.006671</td>\n",
234
+ " <td>69.311798</td>\n",
235
+ " <td>124.344086</td>\n",
236
+ " <td>124.344086</td>\n",
237
+ " <td>166.170502</td>\n",
238
+ " <td>-5.852028</td>\n",
239
+ " <td>1.948263</td>\n",
240
+ " <td>0.036463</td>\n",
241
+ " <td>0.400</td>\n",
242
+ " <td>-12.000179</td>\n",
243
+ " <td>107.0</td>\n",
244
+ " <td>0.325114</td>\n",
245
+ " <td>0.520390</td>\n",
246
+ " <td>0.579053</td>\n",
247
+ " <td>0.158</td>\n",
248
+ " <td>1.833333</td>\n",
249
+ " <td>3.73</td>\n",
250
+ " </tr>\n",
251
+ " <tr>\n",
252
+ " <th>3</th>\n",
253
+ " <td>6914609dfb8126cae4324718</td>\n",
254
+ " <td>Hip Hop Rap</td>\n",
255
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Conte...</td>\n",
256
+ " <td>187.298798</td>\n",
257
+ " <td>318.0</td>\n",
258
+ " <td>285.0</td>\n",
259
+ " <td>19.659283</td>\n",
260
+ " <td>0.443467</td>\n",
261
+ " <td>0.360642</td>\n",
262
+ " <td>3.500000</td>\n",
263
+ " <td>0.159247</td>\n",
264
+ " <td>0.007202</td>\n",
265
+ " <td>65.514191</td>\n",
266
+ " <td>109.909401</td>\n",
267
+ " <td>109.909401</td>\n",
268
+ " <td>134.211624</td>\n",
269
+ " <td>-27.524824</td>\n",
270
+ " <td>1.244652</td>\n",
271
+ " <td>0.064695</td>\n",
272
+ " <td>0.365</td>\n",
273
+ " <td>-12.435019</td>\n",
274
+ " <td>105.8</td>\n",
275
+ " <td>0.407647</td>\n",
276
+ " <td>0.617191</td>\n",
277
+ " <td>0.617197</td>\n",
278
+ " <td>0.071</td>\n",
279
+ " <td>1.916667</td>\n",
280
+ " <td>3.48</td>\n",
281
+ " </tr>\n",
282
+ " <tr>\n",
283
+ " <th>4</th>\n",
284
+ " <td>691af0f3979070eb7827937c</td>\n",
285
+ " <td>Hip Hop Rap</td>\n",
286
+ " <td>Hip Hop Rap --- ['Alternative Hip Hop', 'Conte...</td>\n",
287
+ " <td>185.004989</td>\n",
288
+ " <td>651.0</td>\n",
289
+ " <td>551.0</td>\n",
290
+ " <td>20.855880</td>\n",
291
+ " <td>0.461875</td>\n",
292
+ " <td>0.767493</td>\n",
293
+ " <td>4.983333</td>\n",
294
+ " <td>0.155302</td>\n",
295
+ " <td>0.007290</td>\n",
296
+ " <td>127.873909</td>\n",
297
+ " <td>151.955536</td>\n",
298
+ " <td>151.955536</td>\n",
299
+ " <td>129.783264</td>\n",
300
+ " <td>-11.940094</td>\n",
301
+ " <td>3.452597</td>\n",
302
+ " <td>0.056507</td>\n",
303
+ " <td>0.281</td>\n",
304
+ " <td>-16.217091</td>\n",
305
+ " <td>212.3</td>\n",
306
+ " <td>0.255311</td>\n",
307
+ " <td>0.446953</td>\n",
308
+ " <td>0.454712</td>\n",
309
+ " <td>0.039</td>\n",
310
+ " <td>3.500000</td>\n",
311
+ " <td>3.56</td>\n",
312
+ " </tr>\n",
313
+ " </tbody>\n",
314
+ "</table>\n",
315
+ "</div>"
316
+ ]
317
+ },
318
+ "execution_count": 1,
319
+ "metadata": {},
320
+ "output_type": "execute_result"
321
+ }
322
+ ],
323
+ "execution_count": 1
324
+ },
325
+ {
326
+ "metadata": {
327
+ "ExecuteTime": {
328
+ "end_time": "2026-03-31T03:54:55.696551500Z",
329
+ "start_time": "2026-03-31T03:54:55.635800100Z"
330
+ }
331
+ },
332
+ "cell_type": "code",
333
+ "source": "df[\"genre\"].value_counts()",
334
+ "id": "9fe14275a70aaae0",
335
+ "outputs": [
336
+ {
337
+ "data": {
338
+ "text/plain": [
339
+ "genre\n",
340
+ "Rock 29105\n",
341
+ "Hip Hop Rap 21428\n",
342
+ "EDM 18903\n",
343
+ "Pop 15967\n",
344
+ "RnB Soul 14167\n",
345
+ "Country 12499\n",
346
+ "Folk Singer Songwriter 6917\n",
347
+ "Alternative Indie 5274\n",
348
+ "Gospel Christian 578\n",
349
+ "Punk 252\n",
350
+ "Metal 79\n",
351
+ "Name: count, dtype: int64"
352
+ ]
353
+ },
354
+ "execution_count": 2,
355
+ "metadata": {},
356
+ "output_type": "execute_result"
357
+ }
358
+ ],
359
+ "execution_count": 2
360
+ },
361
+ {
362
+ "metadata": {
363
+ "ExecuteTime": {
364
+ "end_time": "2026-03-31T03:54:55.725419Z",
365
+ "start_time": "2026-03-31T03:54:55.699556300Z"
366
+ }
367
+ },
368
+ "cell_type": "code",
369
+ "source": "df['genre_subgenre'][0]",
370
+ "id": "7412f3d028afc4e3",
371
+ "outputs": [
372
+ {
373
+ "data": {
374
+ "text/plain": [
375
+ "\"Hip Hop Rap --- ['Alternative Hip Hop', 'Boom Bap', 'Contemporary Hip Hop', 'Trap']\""
376
+ ]
377
+ },
378
+ "execution_count": 3,
379
+ "metadata": {},
380
+ "output_type": "execute_result"
381
+ }
382
+ ],
383
+ "execution_count": 3
384
+ },
385
+ {
386
+ "metadata": {
387
+ "ExecuteTime": {
388
+ "end_time": "2026-03-31T03:55:00.359660300Z",
389
+ "start_time": "2026-03-31T03:54:59.377188700Z"
390
+ }
391
+ },
392
+ "cell_type": "code",
393
+ "source": [
394
+ "import ast\n",
395
+ "\n",
396
+ "def transform(x):\n",
397
+ " main, sub = x.split(' --- ')\n",
398
+ " sub_list = ast.literal_eval(sub)\n",
399
+ " return sub_list + [main]\n",
400
+ "\n",
401
+ "df['genre_subgenre'] = df['genre_subgenre'].apply(transform)"
402
+ ],
403
+ "id": "928d1aa5fab137df",
404
+ "outputs": [],
405
+ "execution_count": 4
406
+ },
407
+ {
408
+ "metadata": {
409
+ "ExecuteTime": {
410
+ "end_time": "2026-03-31T03:55:01.168965400Z",
411
+ "start_time": "2026-03-31T03:55:01.111013400Z"
412
+ }
413
+ },
414
+ "cell_type": "code",
415
+ "source": [
416
+ "drop_cols = ['_id', 'genre','labels',\n",
417
+ " 'trimmed_audio_duration_sec', 'syllable_count', 'word_count',\n",
418
+ " 'sentiment_score', 'avg_word_length']\n",
419
+ "\n",
420
+ "feature_cols = [c for c in df.columns if c not in drop_cols]\n",
421
+ "df = df[feature_cols].copy()\n",
422
+ "df.shape"
423
+ ],
424
+ "id": "7b947270eb4fe3b0",
425
+ "outputs": [
426
+ {
427
+ "data": {
428
+ "text/plain": [
429
+ "(125169, 21)"
430
+ ]
431
+ },
432
+ "execution_count": 5,
433
+ "metadata": {},
434
+ "output_type": "execute_result"
435
+ }
436
+ ],
437
+ "execution_count": 5
438
+ },
439
+ {
440
+ "metadata": {
441
+ "ExecuteTime": {
442
+ "end_time": "2026-03-31T03:55:02.488063800Z",
443
+ "start_time": "2026-03-31T03:55:02.451762900Z"
444
+ }
445
+ },
446
+ "cell_type": "code",
447
+ "source": "df.head()",
448
+ "id": "1827b0bcaf4b3af3",
449
+ "outputs": [
450
+ {
451
+ "data": {
452
+ "text/plain": [
453
+ " genre_subgenre \\\n",
454
+ "0 [Alternative Hip Hop, Boom Bap, Contemporary H... \n",
455
+ "1 [Americana, Contemporary Country, Bro Country,... \n",
456
+ "2 [Alternative Hip Hop, Boom Bap, Contemporary H... \n",
457
+ "3 [Alternative Hip Hop, Contemporary Hip Hop, Hi... \n",
458
+ "4 [Alternative Hip Hop, Contemporary Hip Hop, Tr... \n",
459
+ "\n",
460
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
461
+ "0 20.440557 0.464204 \n",
462
+ "1 19.657228 0.424237 \n",
463
+ "2 20.115561 0.454093 \n",
464
+ "3 19.659283 0.443467 \n",
465
+ "4 20.855880 0.461875 \n",
466
+ "\n",
467
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
468
+ "0 0.434021 3.250000 \n",
469
+ "1 0.351001 2.425576 \n",
470
+ "2 0.327000 2.738889 \n",
471
+ "3 0.360642 3.500000 \n",
472
+ "4 0.767493 4.983333 \n",
473
+ "\n",
474
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
475
+ "0 0.132002 0.006988 \n",
476
+ "1 0.139757 0.007367 \n",
477
+ "2 0.111282 0.006671 \n",
478
+ "3 0.159247 0.007202 \n",
479
+ "4 0.155302 0.007290 \n",
480
+ "\n",
481
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
482
+ "0 69.616264 152.006775 152.006775 \n",
483
+ "1 156.358124 117.943665 117.943665 \n",
484
+ "2 69.311798 124.344086 124.344086 \n",
485
+ "3 65.514191 109.909401 109.909401 \n",
486
+ "4 127.873909 151.955536 151.955536 \n",
487
+ "\n",
488
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
489
+ "0 153.058243 -7.368185 1.143722 \n",
490
+ "1 148.055832 -49.435444 4.708925 \n",
491
+ "2 166.170502 -5.852028 1.948263 \n",
492
+ "3 134.211624 -27.524824 1.244652 \n",
493
+ "4 129.783264 -11.940094 3.452597 \n",
494
+ "\n",
495
+ " zero_crossing_rate (mix) vocab_richness \\\n",
496
+ "0 0.045159 0.305 \n",
497
+ "1 0.070352 0.352 \n",
498
+ "2 0.036463 0.400 \n",
499
+ "3 0.064695 0.365 \n",
500
+ "4 0.056507 0.281 \n",
501
+ "\n",
502
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
503
+ "0 -12.104649 20.9 \n",
504
+ "1 -11.814197 89.4 \n",
505
+ "2 -12.000179 107.0 \n",
506
+ "3 -12.435019 105.8 \n",
507
+ "4 -16.217091 212.3 \n",
508
+ "\n",
509
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
510
+ "0 0.349783 0.576250 0.578454 \n",
511
+ "1 0.429792 0.619931 0.632507 \n",
512
+ "2 0.325114 0.520390 0.579053 \n",
513
+ "3 0.407647 0.617191 0.617197 \n",
514
+ "4 0.255311 0.446953 0.454712 \n",
515
+ "\n",
516
+ " melody_complexity (vocals) \n",
517
+ "0 2.250000 \n",
518
+ "1 1.916667 \n",
519
+ "2 1.833333 \n",
520
+ "3 1.916667 \n",
521
+ "4 3.500000 "
522
+ ],
523
+ "text/html": [
524
+ "<div>\n",
525
+ "<style scoped>\n",
526
+ " .dataframe tbody tr th:only-of-type {\n",
527
+ " vertical-align: middle;\n",
528
+ " }\n",
529
+ "\n",
530
+ " .dataframe tbody tr th {\n",
531
+ " vertical-align: top;\n",
532
+ " }\n",
533
+ "\n",
534
+ " .dataframe thead th {\n",
535
+ " text-align: right;\n",
536
+ " }\n",
537
+ "</style>\n",
538
+ "<table border=\"1\" class=\"dataframe\">\n",
539
+ " <thead>\n",
540
+ " <tr style=\"text-align: right;\">\n",
541
+ " <th></th>\n",
542
+ " <th>genre_subgenre</th>\n",
543
+ " <th>spectral_contrast_mean (mix)</th>\n",
544
+ " <th>chroma_mean (mix)</th>\n",
545
+ " <th>melody_variability (vocals)</th>\n",
546
+ " <th>rhythm_onset_rate (mix)</th>\n",
547
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
548
+ " <th>repetition_score custom (mix)</th>\n",
549
+ " <th>pitch_std (mix)</th>\n",
550
+ " <th>tempo_bpm_corrected (mix)</th>\n",
551
+ " <th>tempo_bpm_original (mix)</th>\n",
552
+ " <th>mfcc_mean_1 (mix)</th>\n",
553
+ " <th>mfcc_mean_2 (mix)</th>\n",
554
+ " <th>loudness_range_lu custom (mix)</th>\n",
555
+ " <th>zero_crossing_rate (mix)</th>\n",
556
+ " <th>vocab_richness</th>\n",
557
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
558
+ " <th>readability_score</th>\n",
559
+ " <th>energy_essentia (mix)</th>\n",
560
+ " <th>energy_librosa (mix)</th>\n",
561
+ " <th>rms_energy_mean (mix)</th>\n",
562
+ " <th>melody_complexity (vocals)</th>\n",
563
+ " </tr>\n",
564
+ " </thead>\n",
565
+ " <tbody>\n",
566
+ " <tr>\n",
567
+ " <th>0</th>\n",
568
+ " <td>[Alternative Hip Hop, Boom Bap, Contemporary H...</td>\n",
569
+ " <td>20.440557</td>\n",
570
+ " <td>0.464204</td>\n",
571
+ " <td>0.434021</td>\n",
572
+ " <td>3.250000</td>\n",
573
+ " <td>0.132002</td>\n",
574
+ " <td>0.006988</td>\n",
575
+ " <td>69.616264</td>\n",
576
+ " <td>152.006775</td>\n",
577
+ " <td>152.006775</td>\n",
578
+ " <td>153.058243</td>\n",
579
+ " <td>-7.368185</td>\n",
580
+ " <td>1.143722</td>\n",
581
+ " <td>0.045159</td>\n",
582
+ " <td>0.305</td>\n",
583
+ " <td>-12.104649</td>\n",
584
+ " <td>20.9</td>\n",
585
+ " <td>0.349783</td>\n",
586
+ " <td>0.576250</td>\n",
587
+ " <td>0.578454</td>\n",
588
+ " <td>2.250000</td>\n",
589
+ " </tr>\n",
590
+ " <tr>\n",
591
+ " <th>1</th>\n",
592
+ " <td>[Americana, Contemporary Country, Bro Country,...</td>\n",
593
+ " <td>19.657228</td>\n",
594
+ " <td>0.424237</td>\n",
595
+ " <td>0.351001</td>\n",
596
+ " <td>2.425576</td>\n",
597
+ " <td>0.139757</td>\n",
598
+ " <td>0.007367</td>\n",
599
+ " <td>156.358124</td>\n",
600
+ " <td>117.943665</td>\n",
601
+ " <td>117.943665</td>\n",
602
+ " <td>148.055832</td>\n",
603
+ " <td>-49.435444</td>\n",
604
+ " <td>4.708925</td>\n",
605
+ " <td>0.070352</td>\n",
606
+ " <td>0.352</td>\n",
607
+ " <td>-11.814197</td>\n",
608
+ " <td>89.4</td>\n",
609
+ " <td>0.429792</td>\n",
610
+ " <td>0.619931</td>\n",
611
+ " <td>0.632507</td>\n",
612
+ " <td>1.916667</td>\n",
613
+ " </tr>\n",
614
+ " <tr>\n",
615
+ " <th>2</th>\n",
616
+ " <td>[Alternative Hip Hop, Boom Bap, Contemporary H...</td>\n",
617
+ " <td>20.115561</td>\n",
618
+ " <td>0.454093</td>\n",
619
+ " <td>0.327000</td>\n",
620
+ " <td>2.738889</td>\n",
621
+ " <td>0.111282</td>\n",
622
+ " <td>0.006671</td>\n",
623
+ " <td>69.311798</td>\n",
624
+ " <td>124.344086</td>\n",
625
+ " <td>124.344086</td>\n",
626
+ " <td>166.170502</td>\n",
627
+ " <td>-5.852028</td>\n",
628
+ " <td>1.948263</td>\n",
629
+ " <td>0.036463</td>\n",
630
+ " <td>0.400</td>\n",
631
+ " <td>-12.000179</td>\n",
632
+ " <td>107.0</td>\n",
633
+ " <td>0.325114</td>\n",
634
+ " <td>0.520390</td>\n",
635
+ " <td>0.579053</td>\n",
636
+ " <td>1.833333</td>\n",
637
+ " </tr>\n",
638
+ " <tr>\n",
639
+ " <th>3</th>\n",
640
+ " <td>[Alternative Hip Hop, Contemporary Hip Hop, Hi...</td>\n",
641
+ " <td>19.659283</td>\n",
642
+ " <td>0.443467</td>\n",
643
+ " <td>0.360642</td>\n",
644
+ " <td>3.500000</td>\n",
645
+ " <td>0.159247</td>\n",
646
+ " <td>0.007202</td>\n",
647
+ " <td>65.514191</td>\n",
648
+ " <td>109.909401</td>\n",
649
+ " <td>109.909401</td>\n",
650
+ " <td>134.211624</td>\n",
651
+ " <td>-27.524824</td>\n",
652
+ " <td>1.244652</td>\n",
653
+ " <td>0.064695</td>\n",
654
+ " <td>0.365</td>\n",
655
+ " <td>-12.435019</td>\n",
656
+ " <td>105.8</td>\n",
657
+ " <td>0.407647</td>\n",
658
+ " <td>0.617191</td>\n",
659
+ " <td>0.617197</td>\n",
660
+ " <td>1.916667</td>\n",
661
+ " </tr>\n",
662
+ " <tr>\n",
663
+ " <th>4</th>\n",
664
+ " <td>[Alternative Hip Hop, Contemporary Hip Hop, Tr...</td>\n",
665
+ " <td>20.855880</td>\n",
666
+ " <td>0.461875</td>\n",
667
+ " <td>0.767493</td>\n",
668
+ " <td>4.983333</td>\n",
669
+ " <td>0.155302</td>\n",
670
+ " <td>0.007290</td>\n",
671
+ " <td>127.873909</td>\n",
672
+ " <td>151.955536</td>\n",
673
+ " <td>151.955536</td>\n",
674
+ " <td>129.783264</td>\n",
675
+ " <td>-11.940094</td>\n",
676
+ " <td>3.452597</td>\n",
677
+ " <td>0.056507</td>\n",
678
+ " <td>0.281</td>\n",
679
+ " <td>-16.217091</td>\n",
680
+ " <td>212.3</td>\n",
681
+ " <td>0.255311</td>\n",
682
+ " <td>0.446953</td>\n",
683
+ " <td>0.454712</td>\n",
684
+ " <td>3.500000</td>\n",
685
+ " </tr>\n",
686
+ " </tbody>\n",
687
+ "</table>\n",
688
+ "</div>"
689
+ ]
690
+ },
691
+ "execution_count": 6,
692
+ "metadata": {},
693
+ "output_type": "execute_result"
694
+ }
695
+ ],
696
+ "execution_count": 6
697
+ },
698
+ {
699
+ "metadata": {
700
+ "ExecuteTime": {
701
+ "end_time": "2026-03-31T03:55:06.547702800Z",
702
+ "start_time": "2026-03-31T03:55:04.612860200Z"
703
+ }
704
+ },
705
+ "cell_type": "code",
706
+ "source": "df.to_csv(\"final_clean_data.csv\", index=False)",
707
+ "id": "28af8793bd0eab61",
708
+ "outputs": [],
709
+ "execution_count": 7
710
+ },
711
+ {
712
+ "metadata": {
713
+ "ExecuteTime": {
714
+ "end_time": "2026-03-31T03:57:01.018726Z",
715
+ "start_time": "2026-03-31T03:57:00.889301700Z"
716
+ }
717
+ },
718
+ "cell_type": "code",
719
+ "source": "df.isna().sum()",
720
+ "id": "8b904435409f0a49",
721
+ "outputs": [
722
+ {
723
+ "data": {
724
+ "text/plain": [
725
+ "genre_subgenre 0\n",
726
+ "spectral_contrast_mean (mix) 0\n",
727
+ "chroma_mean (mix) 0\n",
728
+ "melody_variability (vocals) 0\n",
729
+ "rhythm_onset_rate (mix) 0\n",
730
+ "spectral_centroid_mean custom (mix) 0\n",
731
+ "repetition_score custom (mix) 0\n",
732
+ "pitch_std (mix) 0\n",
733
+ "tempo_bpm_corrected (mix) 0\n",
734
+ "tempo_bpm_original (mix) 0\n",
735
+ "mfcc_mean_1 (mix) 0\n",
736
+ "mfcc_mean_2 (mix) 0\n",
737
+ "loudness_range_lu custom (mix) 0\n",
738
+ "zero_crossing_rate (mix) 0\n",
739
+ "vocab_richness 0\n",
740
+ "loudness_integrated_lufs custom (mix) 0\n",
741
+ "readability_score 0\n",
742
+ "energy_essentia (mix) 0\n",
743
+ "energy_librosa (mix) 0\n",
744
+ "rms_energy_mean (mix) 0\n",
745
+ "melody_complexity (vocals) 0\n",
746
+ "dtype: int64"
747
+ ]
748
+ },
749
+ "execution_count": 8,
750
+ "metadata": {},
751
+ "output_type": "execute_result"
752
+ }
753
+ ],
754
+ "execution_count": 8
755
+ },
756
+ {
757
+ "metadata": {},
758
+ "cell_type": "markdown",
759
+ "source": "### 2) Load Dataset",
760
+ "id": "9168083c291938d"
761
+ },
762
+ {
763
+ "metadata": {
764
+ "ExecuteTime": {
765
+ "end_time": "2026-03-31T03:57:05.398199900Z",
766
+ "start_time": "2026-03-31T03:57:04.817653900Z"
767
+ }
768
+ },
769
+ "cell_type": "code",
770
+ "source": [
771
+ "df = pd.read_csv(\"final_clean_data.csv\", low_memory=False)\n",
772
+ "df.shape"
773
+ ],
774
+ "id": "61c97b293f69eec",
775
+ "outputs": [
776
+ {
777
+ "data": {
778
+ "text/plain": [
779
+ "(125169, 21)"
780
+ ]
781
+ },
782
+ "execution_count": 9,
783
+ "metadata": {},
784
+ "output_type": "execute_result"
785
+ }
786
+ ],
787
+ "execution_count": 9
788
+ },
789
+ {
790
+ "metadata": {
791
+ "ExecuteTime": {
792
+ "end_time": "2026-03-31T03:57:05.736114800Z",
793
+ "start_time": "2026-03-31T03:57:05.656718500Z"
794
+ }
795
+ },
796
+ "cell_type": "code",
797
+ "source": "df.head(10)",
798
+ "id": "1b84bca88fc20c5b",
799
+ "outputs": [
800
+ {
801
+ "data": {
802
+ "text/plain": [
803
+ " genre_subgenre \\\n",
804
+ "0 ['Alternative Hip Hop', 'Boom Bap', 'Contempor... \n",
805
+ "1 ['Americana', 'Contemporary Country', 'Bro Cou... \n",
806
+ "2 ['Alternative Hip Hop', 'Boom Bap', 'Contempor... \n",
807
+ "3 ['Alternative Hip Hop', 'Contemporary Hip Hop'... \n",
808
+ "4 ['Alternative Hip Hop', 'Contemporary Hip Hop'... \n",
809
+ "5 ['Alternative Hip Hop', 'Contemporary Hip Hop'... \n",
810
+ "6 ['Alternative Hip Hop', 'Boom Bap', 'Contempor... \n",
811
+ "7 ['Alternative Hip Hop', 'Contemporary Hip Hop'... \n",
812
+ "8 ['Alternative Hip Hop', 'Boom Bap', 'Contempor... \n",
813
+ "9 ['Boom Bap', 'Contemporary Hip Hop', 'Trap', '... \n",
814
+ "\n",
815
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
816
+ "0 20.440557 0.464204 \n",
817
+ "1 19.657228 0.424237 \n",
818
+ "2 20.115561 0.454093 \n",
819
+ "3 19.659283 0.443467 \n",
820
+ "4 20.855880 0.461875 \n",
821
+ "5 20.649601 0.582342 \n",
822
+ "6 20.591029 0.531958 \n",
823
+ "7 20.365473 0.527672 \n",
824
+ "8 20.128469 0.526556 \n",
825
+ "9 20.410229 0.432254 \n",
826
+ "\n",
827
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
828
+ "0 0.434021 3.250000 \n",
829
+ "1 0.351001 2.425576 \n",
830
+ "2 0.327000 2.738889 \n",
831
+ "3 0.360642 3.500000 \n",
832
+ "4 0.767493 4.983333 \n",
833
+ "5 0.625612 5.522135 \n",
834
+ "6 0.700000 4.647586 \n",
835
+ "7 0.604867 5.311232 \n",
836
+ "8 0.802125 4.563691 \n",
837
+ "9 0.613747 4.785156 \n",
838
+ "\n",
839
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
840
+ "0 0.132002 0.006988 \n",
841
+ "1 0.139757 0.007367 \n",
842
+ "2 0.111282 0.006671 \n",
843
+ "3 0.159247 0.007202 \n",
844
+ "4 0.155302 0.007290 \n",
845
+ "5 0.158728 0.007571 \n",
846
+ "6 0.144791 0.008084 \n",
847
+ "7 0.193616 0.007258 \n",
848
+ "8 0.158051 0.007390 \n",
849
+ "9 0.215118 0.007961 \n",
850
+ "\n",
851
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
852
+ "0 69.616264 152.006775 152.006775 \n",
853
+ "1 156.358124 117.943665 117.943665 \n",
854
+ "2 69.311798 124.344086 124.344086 \n",
855
+ "3 65.514191 109.909401 109.909401 \n",
856
+ "4 127.873909 151.955536 151.955536 \n",
857
+ "5 98.469620 103.800598 103.800598 \n",
858
+ "6 96.689476 133.976532 133.976532 \n",
859
+ "7 175.793594 129.943954 129.943954 \n",
860
+ "8 143.052185 150.016129 150.016129 \n",
861
+ "9 127.890625 116.976936 116.976936 \n",
862
+ "\n",
863
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
864
+ "0 153.058243 -7.368185 1.143722 \n",
865
+ "1 148.055832 -49.435444 4.708925 \n",
866
+ "2 166.170502 -5.852028 1.948263 \n",
867
+ "3 134.211624 -27.524824 1.244652 \n",
868
+ "4 129.783264 -11.940094 3.452597 \n",
869
+ "5 115.804680 -15.190744 4.185527 \n",
870
+ "6 128.920319 -6.285958 5.836010 \n",
871
+ "7 110.702339 -5.517988 8.970278 \n",
872
+ "8 122.700783 -31.691156 4.626307 \n",
873
+ "9 94.988937 -20.226351 4.125075 \n",
874
+ "\n",
875
+ " zero_crossing_rate (mix) vocab_richness \\\n",
876
+ "0 0.045159 0.305 \n",
877
+ "1 0.070352 0.352 \n",
878
+ "2 0.036463 0.400 \n",
879
+ "3 0.064695 0.365 \n",
880
+ "4 0.056507 0.281 \n",
881
+ "5 0.049998 0.255 \n",
882
+ "6 0.043094 0.308 \n",
883
+ "7 0.078429 0.267 \n",
884
+ "8 0.060048 0.261 \n",
885
+ "9 0.111702 0.503 \n",
886
+ "\n",
887
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
888
+ "0 -12.104649 20.9 \n",
889
+ "1 -11.814197 89.4 \n",
890
+ "2 -12.000179 107.0 \n",
891
+ "3 -12.435019 105.8 \n",
892
+ "4 -16.217091 212.3 \n",
893
+ "5 -16.153070 43.6 \n",
894
+ "6 -17.065815 94.9 \n",
895
+ "7 -18.897171 38.7 \n",
896
+ "8 -15.986657 2.2 \n",
897
+ "9 -13.382388 41.0 \n",
898
+ "\n",
899
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
900
+ "0 0.349783 0.576250 0.578454 \n",
901
+ "1 0.429792 0.619931 0.632507 \n",
902
+ "2 0.325114 0.520390 0.579053 \n",
903
+ "3 0.407647 0.617191 0.617197 \n",
904
+ "4 0.255311 0.446953 0.454712 \n",
905
+ "5 0.310462 0.503279 0.503863 \n",
906
+ "6 0.299608 0.478562 0.484519 \n",
907
+ "7 0.221316 0.408594 0.419370 \n",
908
+ "8 0.252100 0.435974 0.464947 \n",
909
+ "9 0.335388 0.531125 0.549042 \n",
910
+ "\n",
911
+ " melody_complexity (vocals) \n",
912
+ "0 2.250000 \n",
913
+ "1 1.916667 \n",
914
+ "2 1.833333 \n",
915
+ "3 1.916667 \n",
916
+ "4 3.500000 \n",
917
+ "5 2.916667 \n",
918
+ "6 3.250000 \n",
919
+ "7 2.500000 \n",
920
+ "8 3.416667 \n",
921
+ "9 2.833333 "
922
+ ],
923
+ "text/html": [
924
+ "<div>\n",
925
+ "<style scoped>\n",
926
+ " .dataframe tbody tr th:only-of-type {\n",
927
+ " vertical-align: middle;\n",
928
+ " }\n",
929
+ "\n",
930
+ " .dataframe tbody tr th {\n",
931
+ " vertical-align: top;\n",
932
+ " }\n",
933
+ "\n",
934
+ " .dataframe thead th {\n",
935
+ " text-align: right;\n",
936
+ " }\n",
937
+ "</style>\n",
938
+ "<table border=\"1\" class=\"dataframe\">\n",
939
+ " <thead>\n",
940
+ " <tr style=\"text-align: right;\">\n",
941
+ " <th></th>\n",
942
+ " <th>genre_subgenre</th>\n",
943
+ " <th>spectral_contrast_mean (mix)</th>\n",
944
+ " <th>chroma_mean (mix)</th>\n",
945
+ " <th>melody_variability (vocals)</th>\n",
946
+ " <th>rhythm_onset_rate (mix)</th>\n",
947
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
948
+ " <th>repetition_score custom (mix)</th>\n",
949
+ " <th>pitch_std (mix)</th>\n",
950
+ " <th>tempo_bpm_corrected (mix)</th>\n",
951
+ " <th>tempo_bpm_original (mix)</th>\n",
952
+ " <th>mfcc_mean_1 (mix)</th>\n",
953
+ " <th>mfcc_mean_2 (mix)</th>\n",
954
+ " <th>loudness_range_lu custom (mix)</th>\n",
955
+ " <th>zero_crossing_rate (mix)</th>\n",
956
+ " <th>vocab_richness</th>\n",
957
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
958
+ " <th>readability_score</th>\n",
959
+ " <th>energy_essentia (mix)</th>\n",
960
+ " <th>energy_librosa (mix)</th>\n",
961
+ " <th>rms_energy_mean (mix)</th>\n",
962
+ " <th>melody_complexity (vocals)</th>\n",
963
+ " </tr>\n",
964
+ " </thead>\n",
965
+ " <tbody>\n",
966
+ " <tr>\n",
967
+ " <th>0</th>\n",
968
+ " <td>['Alternative Hip Hop', 'Boom Bap', 'Contempor...</td>\n",
969
+ " <td>20.440557</td>\n",
970
+ " <td>0.464204</td>\n",
971
+ " <td>0.434021</td>\n",
972
+ " <td>3.250000</td>\n",
973
+ " <td>0.132002</td>\n",
974
+ " <td>0.006988</td>\n",
975
+ " <td>69.616264</td>\n",
976
+ " <td>152.006775</td>\n",
977
+ " <td>152.006775</td>\n",
978
+ " <td>153.058243</td>\n",
979
+ " <td>-7.368185</td>\n",
980
+ " <td>1.143722</td>\n",
981
+ " <td>0.045159</td>\n",
982
+ " <td>0.305</td>\n",
983
+ " <td>-12.104649</td>\n",
984
+ " <td>20.9</td>\n",
985
+ " <td>0.349783</td>\n",
986
+ " <td>0.576250</td>\n",
987
+ " <td>0.578454</td>\n",
988
+ " <td>2.250000</td>\n",
989
+ " </tr>\n",
990
+ " <tr>\n",
991
+ " <th>1</th>\n",
992
+ " <td>['Americana', 'Contemporary Country', 'Bro Cou...</td>\n",
993
+ " <td>19.657228</td>\n",
994
+ " <td>0.424237</td>\n",
995
+ " <td>0.351001</td>\n",
996
+ " <td>2.425576</td>\n",
997
+ " <td>0.139757</td>\n",
998
+ " <td>0.007367</td>\n",
999
+ " <td>156.358124</td>\n",
1000
+ " <td>117.943665</td>\n",
1001
+ " <td>117.943665</td>\n",
1002
+ " <td>148.055832</td>\n",
1003
+ " <td>-49.435444</td>\n",
1004
+ " <td>4.708925</td>\n",
1005
+ " <td>0.070352</td>\n",
1006
+ " <td>0.352</td>\n",
1007
+ " <td>-11.814197</td>\n",
1008
+ " <td>89.4</td>\n",
1009
+ " <td>0.429792</td>\n",
1010
+ " <td>0.619931</td>\n",
1011
+ " <td>0.632507</td>\n",
1012
+ " <td>1.916667</td>\n",
1013
+ " </tr>\n",
1014
+ " <tr>\n",
1015
+ " <th>2</th>\n",
1016
+ " <td>['Alternative Hip Hop', 'Boom Bap', 'Contempor...</td>\n",
1017
+ " <td>20.115561</td>\n",
1018
+ " <td>0.454093</td>\n",
1019
+ " <td>0.327000</td>\n",
1020
+ " <td>2.738889</td>\n",
1021
+ " <td>0.111282</td>\n",
1022
+ " <td>0.006671</td>\n",
1023
+ " <td>69.311798</td>\n",
1024
+ " <td>124.344086</td>\n",
1025
+ " <td>124.344086</td>\n",
1026
+ " <td>166.170502</td>\n",
1027
+ " <td>-5.852028</td>\n",
1028
+ " <td>1.948263</td>\n",
1029
+ " <td>0.036463</td>\n",
1030
+ " <td>0.400</td>\n",
1031
+ " <td>-12.000179</td>\n",
1032
+ " <td>107.0</td>\n",
1033
+ " <td>0.325114</td>\n",
1034
+ " <td>0.520390</td>\n",
1035
+ " <td>0.579053</td>\n",
1036
+ " <td>1.833333</td>\n",
1037
+ " </tr>\n",
1038
+ " <tr>\n",
1039
+ " <th>3</th>\n",
1040
+ " <td>['Alternative Hip Hop', 'Contemporary Hip Hop'...</td>\n",
1041
+ " <td>19.659283</td>\n",
1042
+ " <td>0.443467</td>\n",
1043
+ " <td>0.360642</td>\n",
1044
+ " <td>3.500000</td>\n",
1045
+ " <td>0.159247</td>\n",
1046
+ " <td>0.007202</td>\n",
1047
+ " <td>65.514191</td>\n",
1048
+ " <td>109.909401</td>\n",
1049
+ " <td>109.909401</td>\n",
1050
+ " <td>134.211624</td>\n",
1051
+ " <td>-27.524824</td>\n",
1052
+ " <td>1.244652</td>\n",
1053
+ " <td>0.064695</td>\n",
1054
+ " <td>0.365</td>\n",
1055
+ " <td>-12.435019</td>\n",
1056
+ " <td>105.8</td>\n",
1057
+ " <td>0.407647</td>\n",
1058
+ " <td>0.617191</td>\n",
1059
+ " <td>0.617197</td>\n",
1060
+ " <td>1.916667</td>\n",
1061
+ " </tr>\n",
1062
+ " <tr>\n",
1063
+ " <th>4</th>\n",
1064
+ " <td>['Alternative Hip Hop', 'Contemporary Hip Hop'...</td>\n",
1065
+ " <td>20.855880</td>\n",
1066
+ " <td>0.461875</td>\n",
1067
+ " <td>0.767493</td>\n",
1068
+ " <td>4.983333</td>\n",
1069
+ " <td>0.155302</td>\n",
1070
+ " <td>0.007290</td>\n",
1071
+ " <td>127.873909</td>\n",
1072
+ " <td>151.955536</td>\n",
1073
+ " <td>151.955536</td>\n",
1074
+ " <td>129.783264</td>\n",
1075
+ " <td>-11.940094</td>\n",
1076
+ " <td>3.452597</td>\n",
1077
+ " <td>0.056507</td>\n",
1078
+ " <td>0.281</td>\n",
1079
+ " <td>-16.217091</td>\n",
1080
+ " <td>212.3</td>\n",
1081
+ " <td>0.255311</td>\n",
1082
+ " <td>0.446953</td>\n",
1083
+ " <td>0.454712</td>\n",
1084
+ " <td>3.500000</td>\n",
1085
+ " </tr>\n",
1086
+ " <tr>\n",
1087
+ " <th>5</th>\n",
1088
+ " <td>['Alternative Hip Hop', 'Contemporary Hip Hop'...</td>\n",
1089
+ " <td>20.649601</td>\n",
1090
+ " <td>0.582342</td>\n",
1091
+ " <td>0.625612</td>\n",
1092
+ " <td>5.522135</td>\n",
1093
+ " <td>0.158728</td>\n",
1094
+ " <td>0.007571</td>\n",
1095
+ " <td>98.469620</td>\n",
1096
+ " <td>103.800598</td>\n",
1097
+ " <td>103.800598</td>\n",
1098
+ " <td>115.804680</td>\n",
1099
+ " <td>-15.190744</td>\n",
1100
+ " <td>4.185527</td>\n",
1101
+ " <td>0.049998</td>\n",
1102
+ " <td>0.255</td>\n",
1103
+ " <td>-16.153070</td>\n",
1104
+ " <td>43.6</td>\n",
1105
+ " <td>0.310462</td>\n",
1106
+ " <td>0.503279</td>\n",
1107
+ " <td>0.503863</td>\n",
1108
+ " <td>2.916667</td>\n",
1109
+ " </tr>\n",
1110
+ " <tr>\n",
1111
+ " <th>6</th>\n",
1112
+ " <td>['Alternative Hip Hop', 'Boom Bap', 'Contempor...</td>\n",
1113
+ " <td>20.591029</td>\n",
1114
+ " <td>0.531958</td>\n",
1115
+ " <td>0.700000</td>\n",
1116
+ " <td>4.647586</td>\n",
1117
+ " <td>0.144791</td>\n",
1118
+ " <td>0.008084</td>\n",
1119
+ " <td>96.689476</td>\n",
1120
+ " <td>133.976532</td>\n",
1121
+ " <td>133.976532</td>\n",
1122
+ " <td>128.920319</td>\n",
1123
+ " <td>-6.285958</td>\n",
1124
+ " <td>5.836010</td>\n",
1125
+ " <td>0.043094</td>\n",
1126
+ " <td>0.308</td>\n",
1127
+ " <td>-17.065815</td>\n",
1128
+ " <td>94.9</td>\n",
1129
+ " <td>0.299608</td>\n",
1130
+ " <td>0.478562</td>\n",
1131
+ " <td>0.484519</td>\n",
1132
+ " <td>3.250000</td>\n",
1133
+ " </tr>\n",
1134
+ " <tr>\n",
1135
+ " <th>7</th>\n",
1136
+ " <td>['Alternative Hip Hop', 'Contemporary Hip Hop'...</td>\n",
1137
+ " <td>20.365473</td>\n",
1138
+ " <td>0.527672</td>\n",
1139
+ " <td>0.604867</td>\n",
1140
+ " <td>5.311232</td>\n",
1141
+ " <td>0.193616</td>\n",
1142
+ " <td>0.007258</td>\n",
1143
+ " <td>175.793594</td>\n",
1144
+ " <td>129.943954</td>\n",
1145
+ " <td>129.943954</td>\n",
1146
+ " <td>110.702339</td>\n",
1147
+ " <td>-5.517988</td>\n",
1148
+ " <td>8.970278</td>\n",
1149
+ " <td>0.078429</td>\n",
1150
+ " <td>0.267</td>\n",
1151
+ " <td>-18.897171</td>\n",
1152
+ " <td>38.7</td>\n",
1153
+ " <td>0.221316</td>\n",
1154
+ " <td>0.408594</td>\n",
1155
+ " <td>0.419370</td>\n",
1156
+ " <td>2.500000</td>\n",
1157
+ " </tr>\n",
1158
+ " <tr>\n",
1159
+ " <th>8</th>\n",
1160
+ " <td>['Alternative Hip Hop', 'Boom Bap', 'Contempor...</td>\n",
1161
+ " <td>20.128469</td>\n",
1162
+ " <td>0.526556</td>\n",
1163
+ " <td>0.802125</td>\n",
1164
+ " <td>4.563691</td>\n",
1165
+ " <td>0.158051</td>\n",
1166
+ " <td>0.007390</td>\n",
1167
+ " <td>143.052185</td>\n",
1168
+ " <td>150.016129</td>\n",
1169
+ " <td>150.016129</td>\n",
1170
+ " <td>122.700783</td>\n",
1171
+ " <td>-31.691156</td>\n",
1172
+ " <td>4.626307</td>\n",
1173
+ " <td>0.060048</td>\n",
1174
+ " <td>0.261</td>\n",
1175
+ " <td>-15.986657</td>\n",
1176
+ " <td>2.2</td>\n",
1177
+ " <td>0.252100</td>\n",
1178
+ " <td>0.435974</td>\n",
1179
+ " <td>0.464947</td>\n",
1180
+ " <td>3.416667</td>\n",
1181
+ " </tr>\n",
1182
+ " <tr>\n",
1183
+ " <th>9</th>\n",
1184
+ " <td>['Boom Bap', 'Contemporary Hip Hop', 'Trap', '...</td>\n",
1185
+ " <td>20.410229</td>\n",
1186
+ " <td>0.432254</td>\n",
1187
+ " <td>0.613747</td>\n",
1188
+ " <td>4.785156</td>\n",
1189
+ " <td>0.215118</td>\n",
1190
+ " <td>0.007961</td>\n",
1191
+ " <td>127.890625</td>\n",
1192
+ " <td>116.976936</td>\n",
1193
+ " <td>116.976936</td>\n",
1194
+ " <td>94.988937</td>\n",
1195
+ " <td>-20.226351</td>\n",
1196
+ " <td>4.125075</td>\n",
1197
+ " <td>0.111702</td>\n",
1198
+ " <td>0.503</td>\n",
1199
+ " <td>-13.382388</td>\n",
1200
+ " <td>41.0</td>\n",
1201
+ " <td>0.335388</td>\n",
1202
+ " <td>0.531125</td>\n",
1203
+ " <td>0.549042</td>\n",
1204
+ " <td>2.833333</td>\n",
1205
+ " </tr>\n",
1206
+ " </tbody>\n",
1207
+ "</table>\n",
1208
+ "</div>"
1209
+ ]
1210
+ },
1211
+ "execution_count": 10,
1212
+ "metadata": {},
1213
+ "output_type": "execute_result"
1214
+ }
1215
+ ],
1216
+ "execution_count": 10
1217
+ },
1218
+ {
1219
+ "metadata": {
1220
+ "ExecuteTime": {
1221
+ "end_time": "2026-03-31T03:57:09.131100100Z",
1222
+ "start_time": "2026-03-31T03:57:07.403030400Z"
1223
+ }
1224
+ },
1225
+ "cell_type": "code",
1226
+ "source": "df['genre_subgenre'] = df['genre_subgenre'].apply(lambda x: ast.literal_eval(x) if isinstance(x, str) else x)\n",
1227
+ "id": "482a32be03dbe231",
1228
+ "outputs": [],
1229
+ "execution_count": 11
1230
+ },
1231
+ {
1232
+ "metadata": {
1233
+ "ExecuteTime": {
1234
+ "end_time": "2026-03-31T03:57:09.843702500Z",
1235
+ "start_time": "2026-03-31T03:57:09.739835200Z"
1236
+ }
1237
+ },
1238
+ "cell_type": "code",
1239
+ "source": "type(df['genre_subgenre'][0])",
1240
+ "id": "d6985abd006fac55",
1241
+ "outputs": [
1242
+ {
1243
+ "data": {
1244
+ "text/plain": [
1245
+ "list"
1246
+ ]
1247
+ },
1248
+ "execution_count": 12,
1249
+ "metadata": {},
1250
+ "output_type": "execute_result"
1251
+ }
1252
+ ],
1253
+ "execution_count": 12
1254
+ },
1255
+ {
1256
+ "metadata": {
1257
+ "ExecuteTime": {
1258
+ "end_time": "2026-03-31T04:27:54.232241400Z",
1259
+ "start_time": "2026-03-31T04:27:51.718031900Z"
1260
+ }
1261
+ },
1262
+ "cell_type": "code",
1263
+ "source": [
1264
+ "import pandas as pd\n",
1265
+ "from sklearn.model_selection import train_test_split\n",
1266
+ "from sklearn.preprocessing import LabelEncoder\n",
1267
+ "from sklearn.ensemble import RandomForestClassifier\n",
1268
+ "from sklearn.metrics import classification_report, f1_score\n",
1269
+ "data = pd.read_csv(\"final_clean_data.csv\")\n",
1270
+ "\n",
1271
+ "data['genre_subgenre'] = data['genre_subgenre'].apply(lambda x: ast.literal_eval(x) if isinstance(x, str) else x)\n",
1272
+ "\n",
1273
+ "X = data.drop(columns=[\"genre_subgenre\"])\n",
1274
+ "\n",
1275
+ "\n"
1276
+ ],
1277
+ "id": "735e631b1046e1c9",
1278
+ "outputs": [],
1279
+ "execution_count": 31
1280
+ },
1281
+ {
1282
+ "metadata": {
1283
+ "ExecuteTime": {
1284
+ "end_time": "2026-03-31T04:28:25.805903600Z",
1285
+ "start_time": "2026-03-31T04:28:25.687964300Z"
1286
+ }
1287
+ },
1288
+ "cell_type": "code",
1289
+ "source": "data[\"genre_subgenre\"].iloc[0:2,]",
1290
+ "id": "6cc878bce2e5d14",
1291
+ "outputs": [
1292
+ {
1293
+ "data": {
1294
+ "text/plain": [
1295
+ "0 [Alternative Hip Hop, Boom Bap, Contemporary H...\n",
1296
+ "1 [Americana, Contemporary Country, Bro Country,...\n",
1297
+ "Name: genre_subgenre, dtype: object"
1298
+ ]
1299
+ },
1300
+ "execution_count": 33,
1301
+ "metadata": {},
1302
+ "output_type": "execute_result"
1303
+ }
1304
+ ],
1305
+ "execution_count": 33
1306
+ },
1307
+ {
1308
+ "metadata": {},
1309
+ "cell_type": "code",
1310
+ "outputs": [],
1311
+ "execution_count": null,
1312
+ "source": "",
1313
+ "id": "702f5d9bc5c7bca7"
1314
+ },
1315
+ {
1316
+ "metadata": {
1317
+ "ExecuteTime": {
1318
+ "end_time": "2026-03-31T04:25:17.808781400Z",
1319
+ "start_time": "2026-03-31T04:25:17.719637100Z"
1320
+ }
1321
+ },
1322
+ "cell_type": "code",
1323
+ "source": "X.head(2)",
1324
+ "id": "4d9d2e079f5dbd52",
1325
+ "outputs": [
1326
+ {
1327
+ "data": {
1328
+ "text/plain": [
1329
+ " spectral_contrast_mean (mix) chroma_mean (mix) \\\n",
1330
+ "0 20.440557 0.464204 \n",
1331
+ "1 19.657228 0.424237 \n",
1332
+ "\n",
1333
+ " melody_variability (vocals) rhythm_onset_rate (mix) \\\n",
1334
+ "0 0.434021 3.250000 \n",
1335
+ "1 0.351001 2.425576 \n",
1336
+ "\n",
1337
+ " spectral_centroid_mean custom (mix) repetition_score custom (mix) \\\n",
1338
+ "0 0.132002 0.006988 \n",
1339
+ "1 0.139757 0.007367 \n",
1340
+ "\n",
1341
+ " pitch_std (mix) tempo_bpm_corrected (mix) tempo_bpm_original (mix) \\\n",
1342
+ "0 69.616264 152.006775 152.006775 \n",
1343
+ "1 156.358124 117.943665 117.943665 \n",
1344
+ "\n",
1345
+ " mfcc_mean_1 (mix) mfcc_mean_2 (mix) loudness_range_lu custom (mix) \\\n",
1346
+ "0 153.058243 -7.368185 1.143722 \n",
1347
+ "1 148.055832 -49.435444 4.708925 \n",
1348
+ "\n",
1349
+ " zero_crossing_rate (mix) vocab_richness \\\n",
1350
+ "0 0.045159 0.305 \n",
1351
+ "1 0.070352 0.352 \n",
1352
+ "\n",
1353
+ " loudness_integrated_lufs custom (mix) readability_score \\\n",
1354
+ "0 -12.104649 20.9 \n",
1355
+ "1 -11.814197 89.4 \n",
1356
+ "\n",
1357
+ " energy_essentia (mix) energy_librosa (mix) rms_energy_mean (mix) \\\n",
1358
+ "0 0.349783 0.576250 0.578454 \n",
1359
+ "1 0.429792 0.619931 0.632507 \n",
1360
+ "\n",
1361
+ " melody_complexity (vocals) \n",
1362
+ "0 2.250000 \n",
1363
+ "1 1.916667 "
1364
+ ],
1365
+ "text/html": [
1366
+ "<div>\n",
1367
+ "<style scoped>\n",
1368
+ " .dataframe tbody tr th:only-of-type {\n",
1369
+ " vertical-align: middle;\n",
1370
+ " }\n",
1371
+ "\n",
1372
+ " .dataframe tbody tr th {\n",
1373
+ " vertical-align: top;\n",
1374
+ " }\n",
1375
+ "\n",
1376
+ " .dataframe thead th {\n",
1377
+ " text-align: right;\n",
1378
+ " }\n",
1379
+ "</style>\n",
1380
+ "<table border=\"1\" class=\"dataframe\">\n",
1381
+ " <thead>\n",
1382
+ " <tr style=\"text-align: right;\">\n",
1383
+ " <th></th>\n",
1384
+ " <th>spectral_contrast_mean (mix)</th>\n",
1385
+ " <th>chroma_mean (mix)</th>\n",
1386
+ " <th>melody_variability (vocals)</th>\n",
1387
+ " <th>rhythm_onset_rate (mix)</th>\n",
1388
+ " <th>spectral_centroid_mean custom (mix)</th>\n",
1389
+ " <th>repetition_score custom (mix)</th>\n",
1390
+ " <th>pitch_std (mix)</th>\n",
1391
+ " <th>tempo_bpm_corrected (mix)</th>\n",
1392
+ " <th>tempo_bpm_original (mix)</th>\n",
1393
+ " <th>mfcc_mean_1 (mix)</th>\n",
1394
+ " <th>mfcc_mean_2 (mix)</th>\n",
1395
+ " <th>loudness_range_lu custom (mix)</th>\n",
1396
+ " <th>zero_crossing_rate (mix)</th>\n",
1397
+ " <th>vocab_richness</th>\n",
1398
+ " <th>loudness_integrated_lufs custom (mix)</th>\n",
1399
+ " <th>readability_score</th>\n",
1400
+ " <th>energy_essentia (mix)</th>\n",
1401
+ " <th>energy_librosa (mix)</th>\n",
1402
+ " <th>rms_energy_mean (mix)</th>\n",
1403
+ " <th>melody_complexity (vocals)</th>\n",
1404
+ " </tr>\n",
1405
+ " </thead>\n",
1406
+ " <tbody>\n",
1407
+ " <tr>\n",
1408
+ " <th>0</th>\n",
1409
+ " <td>20.440557</td>\n",
1410
+ " <td>0.464204</td>\n",
1411
+ " <td>0.434021</td>\n",
1412
+ " <td>3.250000</td>\n",
1413
+ " <td>0.132002</td>\n",
1414
+ " <td>0.006988</td>\n",
1415
+ " <td>69.616264</td>\n",
1416
+ " <td>152.006775</td>\n",
1417
+ " <td>152.006775</td>\n",
1418
+ " <td>153.058243</td>\n",
1419
+ " <td>-7.368185</td>\n",
1420
+ " <td>1.143722</td>\n",
1421
+ " <td>0.045159</td>\n",
1422
+ " <td>0.305</td>\n",
1423
+ " <td>-12.104649</td>\n",
1424
+ " <td>20.9</td>\n",
1425
+ " <td>0.349783</td>\n",
1426
+ " <td>0.576250</td>\n",
1427
+ " <td>0.578454</td>\n",
1428
+ " <td>2.250000</td>\n",
1429
+ " </tr>\n",
1430
+ " <tr>\n",
1431
+ " <th>1</th>\n",
1432
+ " <td>19.657228</td>\n",
1433
+ " <td>0.424237</td>\n",
1434
+ " <td>0.351001</td>\n",
1435
+ " <td>2.425576</td>\n",
1436
+ " <td>0.139757</td>\n",
1437
+ " <td>0.007367</td>\n",
1438
+ " <td>156.358124</td>\n",
1439
+ " <td>117.943665</td>\n",
1440
+ " <td>117.943665</td>\n",
1441
+ " <td>148.055832</td>\n",
1442
+ " <td>-49.435444</td>\n",
1443
+ " <td>4.708925</td>\n",
1444
+ " <td>0.070352</td>\n",
1445
+ " <td>0.352</td>\n",
1446
+ " <td>-11.814197</td>\n",
1447
+ " <td>89.4</td>\n",
1448
+ " <td>0.429792</td>\n",
1449
+ " <td>0.619931</td>\n",
1450
+ " <td>0.632507</td>\n",
1451
+ " <td>1.916667</td>\n",
1452
+ " </tr>\n",
1453
+ " </tbody>\n",
1454
+ "</table>\n",
1455
+ "</div>"
1456
+ ]
1457
+ },
1458
+ "execution_count": 28,
1459
+ "metadata": {},
1460
+ "output_type": "execute_result"
1461
+ }
1462
+ ],
1463
+ "execution_count": 28
1464
+ },
1465
+ {
1466
+ "metadata": {
1467
+ "ExecuteTime": {
1468
+ "end_time": "2026-03-31T04:25:36.595882500Z",
1469
+ "start_time": "2026-03-31T04:25:36.530983400Z"
1470
+ }
1471
+ },
1472
+ "cell_type": "code",
1473
+ "source": "y.iloc[0,]",
1474
+ "id": "926df9dd64132e50",
1475
+ "outputs": [
1476
+ {
1477
+ "data": {
1478
+ "text/plain": [
1479
+ "['Alternative Hip Hop',\n",
1480
+ " 'Boom Bap',\n",
1481
+ " 'Contemporary Hip Hop',\n",
1482
+ " 'Trap',\n",
1483
+ " 'Hip Hop Rap']"
1484
+ ]
1485
+ },
1486
+ "execution_count": 29,
1487
+ "metadata": {},
1488
+ "output_type": "execute_result"
1489
+ }
1490
+ ],
1491
+ "execution_count": 29
1492
+ },
1493
+ {
1494
+ "metadata": {},
1495
+ "cell_type": "code",
1496
+ "outputs": [],
1497
+ "execution_count": null,
1498
+ "source": "",
1499
+ "id": "64bb9319aa96eb18"
1500
+ }
1501
+ ],
1502
+ "metadata": {
1503
+ "kernelspec": {
1504
+ "display_name": "Python 3",
1505
+ "language": "python",
1506
+ "name": "python3"
1507
+ },
1508
+ "language_info": {
1509
+ "codemirror_mode": {
1510
+ "name": "ipython",
1511
+ "version": 2
1512
+ },
1513
+ "file_extension": ".py",
1514
+ "mimetype": "text/x-python",
1515
+ "name": "python",
1516
+ "nbconvert_exporter": "python",
1517
+ "pygments_lexer": "ipython2",
1518
+ "version": "2.7.6"
1519
+ }
1520
+ },
1521
+ "nbformat": 4,
1522
+ "nbformat_minor": 5
1523
+ }
genre_finder/test_some_codes/sample_test.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import joblib
3
+ nn_model = joblib.load("models/nn_model.pkl")
4
+ pca = joblib.load("models/pca.pkl")
5
+ scaler = joblib.load("models/scaler.pkl")
6
+ feature_cols = joblib.load("models/feature_cols.pkl")
7
+ meta = joblib.load("models/meta.pkl")
8
+ embeddings = np.load("models/embeddings.npy")
9
+
10
+
11
+ def recommend_song(input_song_dict, top_k=10):
12
+ input_vector = np.array([[input_song_dict[col] for col in feature_cols]])
13
+ input_vector = np.nan_to_num(input_vector)
14
+ input_scaled = scaler.transform(input_vector)
15
+ input_embedded = pca.transform(input_scaled)
16
+ distances, indices = nn_model.kneighbors(
17
+ input_embedded,
18
+ n_neighbors=top_k + 1
19
+ )
20
+ results = meta.iloc[indices[0]].copy()
21
+ results["similarity"] = 1 - distances[0]
22
+ results = results.sort_values("similarity", ascending=False)
23
+ output = [
24
+ {
25
+ "genre_and_sub_genre": row["genre_subgenre"],
26
+ "Score": float(row["similarity"])
27
+ }
28
+ for _, row in results.iterrows()
29
+ ]
30
+
31
+ return output
32
+
33
+
34
+ input_song = {'spectral_contrast_mean (mix)': 18.775835817338336,
35
+ 'chroma_mean (mix)': 0.4393191337585449,
36
+ 'melody_variability (vocals)': 0.7237541064882048,
37
+ 'rhythm_onset_rate (mix)': 4.769279513338826,
38
+ 'spectral_centroid_mean custom (mix)': 0.1423719443498439,
39
+ 'repetition_score custom (mix)': 0.0086769169570016,
40
+ 'pitch_std (mix)': 70.28816223144531,
41
+ 'tempo_bpm_corrected (mix)': 120.0334014892578,
42
+ 'tempo_bpm_original (mix)': 120.0334014892578,
43
+ 'mfcc_mean_1 (mix)': 139.3588104248047,
44
+ 'mfcc_mean_2 (mix)': -10.140735626220703,
45
+ 'loudness_range_lu custom (mix)': 11.643880844116213,
46
+ 'zero_crossing_rate (mix)': 0.0576565340161323,
47
+ 'vocab_richness': 0.47,
48
+ 'loudness_integrated_lufs custom (mix)': -17.81583023071289,
49
+ 'readability_score': 159.6,
50
+ 'energy_essentia (mix)': 0.1938344933977563,
51
+ 'energy_librosa (mix)': 0.3731466044114756,
52
+ 'rms_energy_mean (mix)': 0.3730348890104648,
53
+ 'melody_complexity (vocals)': 3.1666666666666665}
54
+
55
+
56
+ results = recommend_song(input_song, top_k=10)
57
+
58
+ print("\n🎧 Top Recommendations:\n")
59
+ print(results)
genre_finder/test_some_codes/test_file.ipynb ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "metadata": {
5
+ "ExecuteTime": {
6
+ "end_time": "2026-03-31T08:26:04.824074400Z",
7
+ "start_time": "2026-03-31T08:26:04.141901500Z"
8
+ }
9
+ },
10
+ "cell_type": "code",
11
+ "source": [
12
+ "import pandas as pd\n",
13
+ "import numpy as np\n",
14
+ "import joblib\n",
15
+ "\n",
16
+ "from sklearn.preprocessing import StandardScaler\n",
17
+ "from sklearn.decomposition import PCA\n",
18
+ "from sklearn.neighbors import NearestNeighbors\n",
19
+ "\n",
20
+ "df = pd.read_csv(\"final_clean_data.csv\")\n",
21
+ "\n",
22
+ "feature_cols = [\n",
23
+ " 'spectral_contrast_mean (mix)',\n",
24
+ " 'chroma_mean (mix)',\n",
25
+ " 'melody_variability (vocals)',\n",
26
+ " 'rhythm_onset_rate (mix)',\n",
27
+ " 'spectral_centroid_mean custom (mix)',\n",
28
+ " 'repetition_score custom (mix)',\n",
29
+ " 'pitch_std (mix)',\n",
30
+ " 'tempo_bpm_corrected (mix)',\n",
31
+ " 'mfcc_mean_1 (mix)',\n",
32
+ " 'mfcc_mean_2 (mix)',\n",
33
+ " 'loudness_range_lu custom (mix)',\n",
34
+ " 'zero_crossing_rate (mix)',\n",
35
+ " 'vocab_richness',\n",
36
+ " 'loudness_integrated_lufs custom (mix)',\n",
37
+ " 'readability_score',\n",
38
+ " 'energy_essentia (mix)',\n",
39
+ " 'energy_librosa (mix)',\n",
40
+ " 'rms_energy_mean (mix)',\n",
41
+ " 'melody_complexity (vocals)'\n",
42
+ "]\n",
43
+ "\n",
44
+ "\n",
45
+ "X = df[feature_cols].copy()\n",
46
+ "\n",
47
+ "X = X.fillna(X.mean())\n",
48
+ "\n",
49
+ "\n",
50
+ "scaler = StandardScaler()\n",
51
+ "X_scaled = scaler.fit_transform(X)\n",
52
+ "\n",
53
+ "pca = PCA(n_components=10, random_state=42)\n",
54
+ "embeddings = pca.fit_transform(X_scaled)\n",
55
+ "\n",
56
+ "nn_model = NearestNeighbors(\n",
57
+ " n_neighbors=11,\n",
58
+ " metric='cosine'\n",
59
+ ")\n",
60
+ "\n",
61
+ "nn_model.fit(embeddings)\n",
62
+ "\n",
63
+ "\n",
64
+ "joblib.dump(nn_model, \"nn_model.pkl\")\n",
65
+ "joblib.dump(pca, \"pca.pkl\")\n",
66
+ "joblib.dump(scaler, \"scaler.pkl\")\n",
67
+ "joblib.dump(feature_cols, \"feature_cols.pkl\")\n",
68
+ "np.save(\"embeddings.npy\", embeddings)\n",
69
+ "print(\"✅ Training complete. Model saved.\")"
70
+ ],
71
+ "id": "3cd6a6e15e46952d",
72
+ "outputs": [
73
+ {
74
+ "name": "stdout",
75
+ "output_type": "stream",
76
+ "text": [
77
+ "✅ Training complete. Model saved.\n"
78
+ ]
79
+ }
80
+ ],
81
+ "execution_count": 6
82
+ },
83
+ {
84
+ "metadata": {
85
+ "ExecuteTime": {
86
+ "end_time": "2026-03-31T08:26:06.210872Z",
87
+ "start_time": "2026-03-31T08:26:06.056664500Z"
88
+ }
89
+ },
90
+ "cell_type": "code",
91
+ "source": [
92
+ "import numpy as np\n",
93
+ "import pandas as pd\n",
94
+ "import joblib\n",
95
+ "\n",
96
+ "nn_model = joblib.load(\"nn_model.pkl\")\n",
97
+ "pca = joblib.load(\"pca.pkl\")\n",
98
+ "scaler = joblib.load(\"scaler.pkl\")\n",
99
+ "feature_cols = joblib.load(\"feature_cols.pkl\")\n",
100
+ "embeddings = np.load(\"embeddings.npy\")\n",
101
+ "\n",
102
+ "def recommend_song(input_song_dict, top_k=10):\n",
103
+ " input_vector = np.array([[input_song_dict[col] for col in feature_cols]])\n",
104
+ " input_vector = np.nan_to_num(input_vector)\n",
105
+ " input_scaled = scaler.transform(input_vector)\n",
106
+ " input_embedded = pca.transform(input_scaled)\n",
107
+ " distances, indices = nn_model.kneighbors(\n",
108
+ " input_embedded,\n",
109
+ " n_neighbors=top_k + 1\n",
110
+ " )\n",
111
+ " results = df.iloc[indices[0]].copy()\n",
112
+ " results[\"similarity\"] = 1 - distances[0]\n",
113
+ " results = results.sort_values(\"similarity\", ascending=False)\n",
114
+ " return results\n",
115
+ "\n",
116
+ "\n",
117
+ "input_song = {'spectral_contrast_mean (mix)': 21.826375772089914, 'chroma_mean (mix)': 0.3961135149002075, 'melody_variability (vocals)': 0.38250987027377, 'rhythm_onset_rate (mix)': 3.1277777777777778, 'spectral_centroid_mean custom (mix)': 0.15499075010897467, 'repetition_score custom (mix)': 0.0074139935621249506, 'pitch_std (mix)': 74.42411041259766, 'tempo_bpm_corrected (mix)': 128.70570373535156, 'mfcc_mean_1 (mix)': 131.99278259277344, 'mfcc_mean_2 (mix)': -21.035446166992188, 'loudness_range_lu custom (mix)': 5.404609680175781, 'zero_crossing_rate (mix)': 0.06825674325227737, 'vocab_richness': 0.455, 'loudness_integrated_lufs custom (mix)': -13.08819580078125, 'readability_score': 32.8, 'energy_essentia (mix)': 0.32994533436041884, 'energy_librosa (mix)': 0.5203621226467141, 'rms_energy_mean (mix)': 0.5467776892768835, 'melody_complexity (vocals)': 2.25}\n",
118
+ "\n",
119
+ "\n",
120
+ "results = recommend_song(input_song, top_k=10)\n",
121
+ "\n",
122
+ "print(\"\\n🎧 Top Recommendations:\\n\")\n",
123
+ "print(results[['genre_subgenre', 'similarity']])"
124
+ ],
125
+ "id": "ae2f751d6ce2b7b3",
126
+ "outputs": [
127
+ {
128
+ "name": "stdout",
129
+ "output_type": "stream",
130
+ "text": [
131
+ "\n",
132
+ "🎧 Top Recommendations:\n",
133
+ "\n",
134
+ " genre_subgenre similarity\n",
135
+ "101296 ['Dance Pop', 'Electro Pop', 'Mainstream Pop',... 0.951255\n",
136
+ "120870 ['Alternative RnB', 'Contemporary RnB', 'Soul'... 0.931561\n",
137
+ "42886 ['Americana', 'Rock'] 0.931080\n",
138
+ "61391 ['Contemporary Singer Songwriter', 'Indie Folk... 0.929570\n",
139
+ "61991 ['Indie Electronic', 'Indie Pop', 'Rock'] 0.928316\n",
140
+ "124708 ['Dance Pop', 'Electropop', 'Synth Pop', 'RnB ... 0.924446\n",
141
+ "86550 ['EDM'] 0.922230\n",
142
+ "101281 ['Dance Pop', 'Electro Pop', 'Indie Pop', 'Mai... 0.922185\n",
143
+ "120767 ['Alternative RnB', 'Contemporary RnB', 'Soul'... 0.919144\n",
144
+ "62959 ['Indie Electronic', 'Indie Pop', 'Rock'] 0.918303\n",
145
+ "64296 ['Pop Country', 'Contemporary Country', 'Count... 0.918228\n"
146
+ ]
147
+ },
148
+ {
149
+ "name": "stderr",
150
+ "output_type": "stream",
151
+ "text": [
152
+ "C:\\Users\\VigneshSubramani\\PycharmProjects\\recommedation-system\\.venv\\Lib\\site-packages\\sklearn\\utils\\validation.py:2691: UserWarning: X does not have valid feature names, but StandardScaler was fitted with feature names\n",
153
+ " warnings.warn(\n"
154
+ ]
155
+ }
156
+ ],
157
+ "execution_count": 7
158
+ },
159
+ {
160
+ "metadata": {},
161
+ "cell_type": "markdown",
162
+ "source": "2) Methods TWO",
163
+ "id": "e891fa93b34e27ff"
164
+ },
165
+ {
166
+ "metadata": {
167
+ "ExecuteTime": {
168
+ "end_time": "2026-03-31T07:40:19.349193500Z",
169
+ "start_time": "2026-03-31T07:40:19.038193100Z"
170
+ }
171
+ },
172
+ "cell_type": "code",
173
+ "source": [
174
+ "import pandas as pd\n",
175
+ "import numpy as np\n",
176
+ "import joblib\n",
177
+ "\n",
178
+ "from sklearn.preprocessing import StandardScaler\n",
179
+ "from sklearn.decomposition import PCA\n",
180
+ "from sklearn.neighbors import NearestNeighbors\n",
181
+ "\n",
182
+ "# Load dataset ONLY for training\n",
183
+ "df = pd.read_csv(\"final_clean_data.csv\")\n",
184
+ "\n",
185
+ "feature_cols = [\n",
186
+ " 'spectral_contrast_mean (mix)',\n",
187
+ " 'chroma_mean (mix)',\n",
188
+ " 'melody_variability (vocals)',\n",
189
+ " 'rhythm_onset_rate (mix)',\n",
190
+ " 'spectral_centroid_mean custom (mix)',\n",
191
+ " 'repetition_score custom (mix)',\n",
192
+ " 'pitch_std (mix)',\n",
193
+ " 'tempo_bpm_corrected (mix)',\n",
194
+ " 'mfcc_mean_1 (mix)',\n",
195
+ " 'mfcc_mean_2 (mix)',\n",
196
+ " 'loudness_range_lu custom (mix)',\n",
197
+ " 'zero_crossing_rate (mix)',\n",
198
+ " 'vocab_richness',\n",
199
+ " 'loudness_integrated_lufs custom (mix)',\n",
200
+ " 'readability_score',\n",
201
+ " 'energy_essentia (mix)',\n",
202
+ " 'energy_librosa (mix)',\n",
203
+ " 'rms_energy_mean (mix)',\n",
204
+ " 'melody_complexity (vocals)'\n",
205
+ "]\n",
206
+ "X = df[feature_cols].copy()\n",
207
+ "X.shape\n"
208
+ ],
209
+ "id": "ca229e8117826ebf",
210
+ "outputs": [
211
+ {
212
+ "data": {
213
+ "text/plain": [
214
+ "(125169, 19)"
215
+ ]
216
+ },
217
+ "execution_count": 30,
218
+ "metadata": {},
219
+ "output_type": "execute_result"
220
+ }
221
+ ],
222
+ "execution_count": 30
223
+ },
224
+ {
225
+ "metadata": {
226
+ "ExecuteTime": {
227
+ "end_time": "2026-03-31T07:40:28.563021800Z",
228
+ "start_time": "2026-03-31T07:40:28.521940600Z"
229
+ }
230
+ },
231
+ "cell_type": "code",
232
+ "source": "X.columns",
233
+ "id": "fd7fe702c6c3da52",
234
+ "outputs": [
235
+ {
236
+ "data": {
237
+ "text/plain": [
238
+ "Index(['spectral_contrast_mean (mix)', 'chroma_mean (mix)',\n",
239
+ " 'melody_variability (vocals)', 'rhythm_onset_rate (mix)',\n",
240
+ " 'spectral_centroid_mean custom (mix)', 'repetition_score custom (mix)',\n",
241
+ " 'pitch_std (mix)', 'tempo_bpm_corrected (mix)', 'mfcc_mean_1 (mix)',\n",
242
+ " 'mfcc_mean_2 (mix)', 'loudness_range_lu custom (mix)',\n",
243
+ " 'zero_crossing_rate (mix)', 'vocab_richness',\n",
244
+ " 'loudness_integrated_lufs custom (mix)', 'readability_score',\n",
245
+ " 'energy_essentia (mix)', 'energy_librosa (mix)',\n",
246
+ " 'rms_energy_mean (mix)', 'melody_complexity (vocals)'],\n",
247
+ " dtype='object')"
248
+ ]
249
+ },
250
+ "execution_count": 32,
251
+ "metadata": {},
252
+ "output_type": "execute_result"
253
+ }
254
+ ],
255
+ "execution_count": 32
256
+ },
257
+ {
258
+ "metadata": {
259
+ "ExecuteTime": {
260
+ "end_time": "2026-03-31T07:43:11.275221600Z",
261
+ "start_time": "2026-03-31T07:43:11.182964600Z"
262
+ }
263
+ },
264
+ "cell_type": "code",
265
+ "source": "X.isna().sum()",
266
+ "id": "d849dd3ee57a5c85",
267
+ "outputs": [
268
+ {
269
+ "data": {
270
+ "text/plain": [
271
+ "spectral_contrast_mean (mix) 0\n",
272
+ "chroma_mean (mix) 0\n",
273
+ "melody_variability (vocals) 0\n",
274
+ "rhythm_onset_rate (mix) 0\n",
275
+ "spectral_centroid_mean custom (mix) 0\n",
276
+ "repetition_score custom (mix) 0\n",
277
+ "pitch_std (mix) 0\n",
278
+ "tempo_bpm_corrected (mix) 0\n",
279
+ "mfcc_mean_1 (mix) 0\n",
280
+ "mfcc_mean_2 (mix) 0\n",
281
+ "loudness_range_lu custom (mix) 0\n",
282
+ "zero_crossing_rate (mix) 0\n",
283
+ "vocab_richness 0\n",
284
+ "loudness_integrated_lufs custom (mix) 0\n",
285
+ "readability_score 0\n",
286
+ "energy_essentia (mix) 0\n",
287
+ "energy_librosa (mix) 0\n",
288
+ "rms_energy_mean (mix) 0\n",
289
+ "melody_complexity (vocals) 0\n",
290
+ "dtype: int64"
291
+ ]
292
+ },
293
+ "execution_count": 33,
294
+ "metadata": {},
295
+ "output_type": "execute_result"
296
+ }
297
+ ],
298
+ "execution_count": 33
299
+ },
300
+ {
301
+ "metadata": {
302
+ "ExecuteTime": {
303
+ "end_time": "2026-03-31T07:43:52.008131400Z",
304
+ "start_time": "2026-03-31T07:43:51.856052100Z"
305
+ }
306
+ },
307
+ "cell_type": "code",
308
+ "source": [
309
+ "#X = X.fillna(X.mean())\n",
310
+ "\n",
311
+ "# Scale\n",
312
+ "scaler = StandardScaler()\n",
313
+ "X_scaled = scaler.fit_transform(X)\n",
314
+ "\n",
315
+ "# Reduce dimensions\n",
316
+ "pca = PCA(n_components=10, random_state=42)\n",
317
+ "embeddings = pca.fit_transform(X_scaled)\n",
318
+ "\n",
319
+ "# Nearest Neighbors model\n",
320
+ "nn_model = NearestNeighbors(\n",
321
+ " n_neighbors=11,\n",
322
+ " metric='cosine'\n",
323
+ ")\n",
324
+ "nn_model.fit(embeddings)\n",
325
+ "\n",
326
+ "# 🔥 ONLY SAVE WHAT IS NEEDED (NO CSV)\n",
327
+ "meta = df[['genre_subgenre']].copy() # add more columns if needed\n",
328
+ "\n",
329
+ "joblib.dump(nn_model, \"models/nn_model.pkl\")\n",
330
+ "joblib.dump(pca, \"models/pca.pkl\")\n",
331
+ "joblib.dump(scaler, \"models/scaler.pkl\")\n",
332
+ "joblib.dump(feature_cols, \"models/feature_cols.pkl\")\n",
333
+ "joblib.dump(meta, \"models/meta.pkl\")\n",
334
+ "\n",
335
+ "np.save(\"models/embeddings.npy\", embeddings)\n",
336
+ "\n",
337
+ "print(\"✅ Training complete. All artifacts saved. CSV no longer needed.\")"
338
+ ],
339
+ "id": "5c67fbababb8258a",
340
+ "outputs": [
341
+ {
342
+ "name": "stdout",
343
+ "output_type": "stream",
344
+ "text": [
345
+ "✅ Training complete. All artifacts saved. CSV no longer needed.\n"
346
+ ]
347
+ }
348
+ ],
349
+ "execution_count": 34
350
+ },
351
+ {
352
+ "metadata": {
353
+ "ExecuteTime": {
354
+ "end_time": "2026-03-31T07:44:09.070154500Z",
355
+ "start_time": "2026-03-31T07:44:08.952731900Z"
356
+ }
357
+ },
358
+ "cell_type": "code",
359
+ "source": [
360
+ "import numpy as np\n",
361
+ "import joblib\n",
362
+ "\n",
363
+ "# Load saved artifacts\n",
364
+ "nn_model = joblib.load(\"models/nn_model.pkl\")\n",
365
+ "pca = joblib.load(\"models/pca.pkl\")\n",
366
+ "scaler = joblib.load(\"models/scaler.pkl\")\n",
367
+ "feature_cols = joblib.load(\"models/feature_cols.pkl\")\n",
368
+ "meta = joblib.load(\"models/meta.pkl\")\n",
369
+ "embeddings = np.load(\"models/embeddings.npy\")\n",
370
+ "\n",
371
+ "\n",
372
+ "def recommend_song(input_song_dict, top_k=10):\n",
373
+ "\n",
374
+ " # Convert input to vector in correct order\n",
375
+ " input_vector = np.array([[input_song_dict[col] for col in feature_cols]])\n",
376
+ " input_vector = np.nan_to_num(input_vector)\n",
377
+ "\n",
378
+ " # Scale + PCA\n",
379
+ " input_scaled = scaler.transform(input_vector)\n",
380
+ " input_embedded = pca.transform(input_scaled)\n",
381
+ "\n",
382
+ " # Nearest neighbors search\n",
383
+ " distances, indices = nn_model.kneighbors(\n",
384
+ " input_embedded,\n",
385
+ " n_neighbors=top_k + 1\n",
386
+ " )\n",
387
+ "\n",
388
+ " # Get metadata instead of CSV\n",
389
+ " results = meta.iloc[indices[0]].copy()\n",
390
+ " results[\"similarity\"] = 1 - distances[0]\n",
391
+ "\n",
392
+ " results = results.sort_values(\"similarity\", ascending=False)\n",
393
+ "\n",
394
+ " return results\n",
395
+ "\n",
396
+ "\n",
397
+ "# Example input\n",
398
+ "input_song = {\n",
399
+ " 'spectral_contrast_mean (mix)': 21.82,\n",
400
+ " 'chroma_mean (mix)': 0.39,\n",
401
+ " 'melody_variability (vocals)': 0.38,\n",
402
+ " 'rhythm_onset_rate (mix)': 3.12,\n",
403
+ " 'spectral_centroid_mean custom (mix)': 0.15,\n",
404
+ " 'repetition_score custom (mix)': 0.007,\n",
405
+ " 'pitch_std (mix)': 74.42,\n",
406
+ " 'tempo_bpm_corrected (mix)': 128.70,\n",
407
+ " 'mfcc_mean_1 (mix)': 131.99,\n",
408
+ " 'mfcc_mean_2 (mix)': -21.03,\n",
409
+ " 'loudness_range_lu custom (mix)': 5.40,\n",
410
+ " 'zero_crossing_rate (mix)': 0.068,\n",
411
+ " 'vocab_richness': 0.455,\n",
412
+ " 'loudness_integrated_lufs custom (mix)': -13.08,\n",
413
+ " 'readability_score': 32.8,\n",
414
+ " 'energy_essentia (mix)': 0.329,\n",
415
+ " 'energy_librosa (mix)': 0.520,\n",
416
+ " 'rms_energy_mean (mix)': 0.546,\n",
417
+ " 'melody_complexity (vocals)': 2.25\n",
418
+ "}\n",
419
+ "\n",
420
+ "results = recommend_song(input_song, top_k=10)\n",
421
+ "\n",
422
+ "print(\"\\n🎧 Top Recommendations:\\n\")\n",
423
+ "print(results)"
424
+ ],
425
+ "id": "b00efe2d8a5714b4",
426
+ "outputs": [
427
+ {
428
+ "name": "stdout",
429
+ "output_type": "stream",
430
+ "text": [
431
+ "\n",
432
+ "🎧 Top Recommendations:\n",
433
+ "\n",
434
+ " genre_subgenre similarity\n",
435
+ "101296 ['Dance Pop', 'Electro Pop', 'Mainstream Pop',... 0.947162\n",
436
+ "42886 ['Americana', 'Rock'] 0.936663\n",
437
+ "120870 ['Alternative RnB', 'Contemporary RnB', 'Soul'... 0.928777\n",
438
+ "61391 ['Contemporary Singer Songwriter', 'Indie Folk... 0.922589\n",
439
+ "64296 ['Pop Country', 'Contemporary Country', 'Count... 0.921481\n",
440
+ "62959 ['Indie Electronic', 'Indie Pop', 'Rock'] 0.921080\n",
441
+ "101281 ['Dance Pop', 'Electro Pop', 'Indie Pop', 'Mai... 0.919901\n",
442
+ "123420 ['Contemporary RnB', 'Funk', 'Motown', 'Soul',... 0.918827\n",
443
+ "124708 ['Dance Pop', 'Electropop', 'Synth Pop', 'RnB ... 0.918593\n",
444
+ "61991 ['Indie Electronic', 'Indie Pop', 'Rock'] 0.918424\n",
445
+ "120767 ['Alternative RnB', 'Contemporary RnB', 'Soul'... 0.917478\n"
446
+ ]
447
+ }
448
+ ],
449
+ "execution_count": 35
450
+ },
451
+ {
452
+ "metadata": {},
453
+ "cell_type": "code",
454
+ "outputs": [],
455
+ "execution_count": null,
456
+ "source": "",
457
+ "id": "b095ca2a85128d25"
458
+ }
459
+ ],
460
+ "metadata": {
461
+ "kernelspec": {
462
+ "display_name": "Python 3",
463
+ "language": "python",
464
+ "name": "python3"
465
+ },
466
+ "language_info": {
467
+ "codemirror_mode": {
468
+ "name": "ipython",
469
+ "version": 2
470
+ },
471
+ "file_extension": ".py",
472
+ "mimetype": "text/x-python",
473
+ "name": "python",
474
+ "nbconvert_exporter": "python",
475
+ "pygments_lexer": "ipython2",
476
+ "version": "2.7.6"
477
+ }
478
+ },
479
+ "nbformat": 4,
480
+ "nbformat_minor": 5
481
+ }