{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from API import API\n",
"api = API()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## General checking functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"api.getPlaylists()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test Asaf's id\n",
"Asaf = \"21hrln7z7x7afddwq263yj34q\"\n",
"\n",
"# For testing purposes\n",
"def getPlaylistNames():\n",
" playlist_names = []\n",
" playlists = api.getPlaylists(Asaf)\n",
" for i in range(len(playlists)):\n",
" # print(playlists[i]['name'])\n",
" playlist_names.append(playlists[i]['name'])\n",
" return playlist_names\n",
"\n",
"playlist_names = getPlaylistNames()\n",
"playlist_names\n",
" # print(playlists[i]['uri'])\n",
" # print()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"playlist_uri = api.getPlaylistIdFromName(\"Dancey\", Asaf)\n",
"playlist_uri"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test adding 5 songs from my playlist to another one of Asaf's playlists (a test one)\n",
"if \"Dancey_copy\" not in playlist_names:\n",
" print(\"need to create this\")\n",
" api.createPlaylist(\"Dancey_copy\", Asaf)\n",
"\n",
"playlist_names = getPlaylistNames()\n",
"print(f\"Dancey_copy in playlist_names?\\n{'Dancey_copy' in playlist_names}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"new = api.generatePlaylistNames()\n",
"len(new) # 45 for 2 playlists per user"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get Recommendations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Check error messages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Error test, too many seeds\n",
"api.getRecommendations(seed_artists=['1', '2', '3'], seed_genres=['4'], seed_tracks=['5','6'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Error test, no seeds\n",
"api.getRecommendations()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run the thing"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"filepath /home/musashishi/Documents/DSS/dss-group-assignment/modules\n",
"implicit path /home/musashishi/Documents/DSS/dss-group-assignment/implicit\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 12:56:48,009 - INFO - \u001b[31m\u001b[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\u001b[0m\n",
" * Running on http://127.0.0.1:5000\n",
"2022-12-04 12:56:48,009 - INFO - \u001b[33mPress CTRL+C to quit\u001b[0m\n",
"2022-12-04 12:56:48,009 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 12:56:48,096 - WARNING - * Debugger is active!\n",
"2022-12-04 12:56:48,096 - INFO - * Debugger PIN: 128-058-343\n",
"2022-12-04 12:56:49,958 - INFO - 127.0.0.1 - - [04/Dec/2022 12:56:49] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 12:56:50,037 - INFO - 127.0.0.1 - - [04/Dec/2022 12:56:50] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 12:56:50,073 - INFO - 127.0.0.1 - - [04/Dec/2022 12:56:50] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 12:56:51,189 - INFO - 127.0.0.1 - - [04/Dec/2022 12:56:51] \"GET /callback HTTP/1.1\" 200 -\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2022-12-04 12:57:32,273 - INFO - * Detected change in '/home/musashishi/Documents/DSS/dss-group-assignment/modules/API.py', reloading\n",
"2022-12-04 12:57:32,296 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 12:57:32,380 - WARNING - * Debugger is active!\n",
"2022-12-04 12:57:32,381 - INFO - * Debugger PIN: 128-058-343\n",
"2022-12-04 13:06:37,788 - INFO - 127.0.0.1 - - [04/Dec/2022 13:06:37] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:06:37,869 - INFO - 127.0.0.1 - - [04/Dec/2022 13:06:37] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:06:37,892 - INFO - 127.0.0.1 - - [04/Dec/2022 13:06:37] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:06:39,035 - INFO - 127.0.0.1 - - [04/Dec/2022 13:06:39] \"GET /callback HTTP/1.1\" 200 -\n",
"2022-12-04 13:08:42,567 - INFO - * Detected change in '/home/musashishi/Documents/DSS/dss-group-assignment/modules/API.py', reloading\n",
"2022-12-04 13:08:42,595 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 13:08:42,680 - WARNING - * Debugger is active!\n",
"2022-12-04 13:08:42,680 - INFO - * Debugger PIN: 128-058-343\n",
"2022-12-04 13:10:08,411 - INFO - 127.0.0.1 - - [04/Dec/2022 13:10:08] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:10:08,506 - INFO - 127.0.0.1 - - [04/Dec/2022 13:10:08] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:10:08,529 - INFO - 127.0.0.1 - - [04/Dec/2022 13:10:08] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:10:09,700 - INFO - 127.0.0.1 - - [04/Dec/2022 13:10:09] \"GET /callback HTTP/1.1\" 200 -\n",
"2022-12-04 13:11:06,085 - INFO - * Detected change in '/home/musashishi/Documents/DSS/dss-group-assignment/modules/API.py', reloading\n",
"2022-12-04 13:11:06,114 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 13:11:06,198 - WARNING - * Debugger is active!\n",
"2022-12-04 13:11:06,198 - INFO - * Debugger PIN: 128-058-343\n",
"2022-12-04 13:11:13,443 - INFO - 127.0.0.1 - - [04/Dec/2022 13:11:13] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:11:13,515 - INFO - 127.0.0.1 - - [04/Dec/2022 13:11:13] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:11:13,549 - INFO - 127.0.0.1 - - [04/Dec/2022 13:11:13] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:11:14,602 - INFO - 127.0.0.1 - - [04/Dec/2022 13:11:14] \"GET /callback HTTP/1.1\" 200 -\n",
"2022-12-04 13:13:24,498 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:24] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:13:24,581 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:24] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:13:24,608 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:24] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:13:39,135 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:39] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:13:39,201 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:39] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:13:39,232 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:39] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:13:40,216 - INFO - 127.0.0.1 - - [04/Dec/2022 13:13:40] \"GET /callback HTTP/1.1\" 200 -\n",
"2022-12-04 13:13:55,778 - INFO - * Detected change in '/home/musashishi/Documents/DSS/dss-group-assignment/modules/API.py', reloading\n",
"2022-12-04 13:13:55,803 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 13:13:55,890 - WARNING - * Debugger is active!\n",
"2022-12-04 13:13:55,890 - INFO - * Debugger PIN: 128-058-343\n",
"2022-12-04 13:14:07,154 - INFO - 127.0.0.1 - - [04/Dec/2022 13:14:07] \"GET / HTTP/1.1\" 200 -\n",
"2022-12-04 13:14:07,205 - INFO - 127.0.0.1 - - [04/Dec/2022 13:14:07] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n",
"2022-12-04 13:14:07,229 - INFO - 127.0.0.1 - - [04/Dec/2022 13:14:07] \"\u001b[32mGET /auth HTTP/1.1\u001b[0m\" 302 -\n",
"2022-12-04 13:14:08,314 - INFO - 127.0.0.1 - - [04/Dec/2022 13:14:08] \"GET /callback HTTP/1.1\" 200 -\n",
"2022-12-04 13:35:10,625 - INFO - * Detected change in '/home/musashishi/Documents/DSS/dss-group-assignment/modules/API.py', reloading\n",
"2022-12-04 13:35:10,646 - INFO - * Restarting with stat\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.\n",
"2022-12-04 13:35:10,732 - WARNING - * Debugger is active!\n",
"2022-12-04 13:35:10,733 - INFO - * Debugger PIN: 128-058-343\n"
]
}
],
"source": [
"import pandas as pd\n",
"import sys\n",
"sys.path.append(\"./modules/\")\n",
"from API import API\n",
"\n",
"api = API()\n",
"# test_user = pd.read_csv('participant data/API_test_user.csv')\n",
"# seed_tracks=list(test_user.iloc[:5]['item'])\n",
"# res = api.getRecommendations(seed_tracks=seed_tracks)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def convertResponseToDf(res, user_id):\n",
" df = pd.DataFrame(res)\n",
" df['user_id'] = user_id\n",
" df.rename(columns={\"id\": \"song_id\"})\n",
" df['rank'] = range(1, len(df)+1) # make it nice by starting the rank at 1 instead of 0\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# This has song_id, user_id, all features, rank of the song for the user\n",
"# convertResponseToDf(res, list(test_user['user'])[0])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# test_user['user'].nunique() # checks out"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Df with the following columns\n",
"song_id, user_id, all features, rank_of_song_for_user"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Unnamed: 0 | \n",
" user_id | \n",
" track_seeds | \n",
" genre_seeds | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,... | \n",
" reggae,electronic | \n",
"
\n",
" \n",
" | 1 | \n",
" 1 | \n",
" 12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117... | \n",
" 6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,... | \n",
" jazz,funk | \n",
"
\n",
" \n",
" | 2 | \n",
" 2 | \n",
" 1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15... | \n",
" 1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,... | \n",
" classical,rnb | \n",
"
\n",
" \n",
" | 3 | \n",
" 3 | \n",
" ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21... | \n",
" 04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,... | \n",
" rockabilly,dubstep | \n",
"
\n",
" \n",
" | 4 | \n",
" 4 | \n",
" 1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900... | \n",
" 76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,... | \n",
" hard-rock,progressive-house | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Unnamed: 0 user_id \\\n",
"0 0 d28708a363b58062087293f779256fffa38fdd56c1f79d... \n",
"1 1 12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117... \n",
"2 2 1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15... \n",
"3 3 ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21... \n",
"4 4 1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900... \n",
"\n",
" track_seeds \\\n",
"0 2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,... \n",
"1 6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,... \n",
"2 1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,... \n",
"3 04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,... \n",
"4 76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,... \n",
"\n",
" genre_seeds \n",
"0 reggae,electronic \n",
"1 jazz,funk \n",
"2 classical,rnb \n",
"3 rockabilly,dubstep \n",
"4 hard-rock,progressive-house "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"seeds_diverse = pd.read_csv('./participant data/seeds_diverse.csv')\n",
"seeds_non_diverse = pd.read_csv('./participant data/seeds_non_diverse.csv')\n",
"seeds_diverse.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Unnamed: 0 | \n",
" user_id | \n",
" track_seeds | \n",
" genre_seeds | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,... | \n",
" reggae,electronic | \n",
"
\n",
" \n",
" | 1 | \n",
" 1 | \n",
" 12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117... | \n",
" 6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,... | \n",
" jazz,funk | \n",
"
\n",
" \n",
" | 2 | \n",
" 2 | \n",
" 1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15... | \n",
" 1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,... | \n",
" classical,rnb | \n",
"
\n",
" \n",
" | 3 | \n",
" 3 | \n",
" ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21... | \n",
" 04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,... | \n",
" rockabilly,dubstep | \n",
"
\n",
" \n",
" | 4 | \n",
" 4 | \n",
" 1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900... | \n",
" 76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,... | \n",
" hard-rock,progressive-house | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Unnamed: 0 user_id \\\n",
"0 0 d28708a363b58062087293f779256fffa38fdd56c1f79d... \n",
"1 1 12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117... \n",
"2 2 1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15... \n",
"3 3 ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21... \n",
"4 4 1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900... \n",
"\n",
" track_seeds \\\n",
"0 2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,... \n",
"1 6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,... \n",
"2 1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,... \n",
"3 04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,... \n",
"4 76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,... \n",
"\n",
" genre_seeds \n",
"0 reggae,electronic \n",
"1 jazz,funk \n",
"2 classical,rnb \n",
"3 rockabilly,dubstep \n",
"4 hard-rock,progressive-house "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"seeds_diverse = seeds_diverse.fillna('')\n",
"seeds_non_diverse = seeds_non_diverse.fillna('')\n",
"seeds_diverse.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 45/45 [07:44<00:00, 10.32s/it]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" danceability | \n",
" energy | \n",
" key | \n",
" loudness | \n",
" mode | \n",
" speechiness | \n",
" acousticness | \n",
" instrumentalness | \n",
" liveness | \n",
" valence | \n",
" tempo | \n",
" type | \n",
" id | \n",
" uri | \n",
" track_href | \n",
" analysis_url | \n",
" duration_ms | \n",
" time_signature | \n",
" user_id | \n",
" rank | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.658 | \n",
" 0.930 | \n",
" 5 | \n",
" -2.912 | \n",
" 0 | \n",
" 0.1410 | \n",
" 0.0236 | \n",
" 0.000000 | \n",
" 0.5780 | \n",
" 0.132 | \n",
" 104.018 | \n",
" audio_features | \n",
" 1RJZLVGpBG9nNZiHRQSWTp | \n",
" spotify:track:1RJZLVGpBG9nNZiHRQSWTp | \n",
" https://api.spotify.com/v1/tracks/1RJZLVGpBG9n... | \n",
" https://api.spotify.com/v1/audio-analysis/1RJZ... | \n",
" 237680 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 1 | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.377 | \n",
" 0.182 | \n",
" 6 | \n",
" -10.896 | \n",
" 1 | \n",
" 0.0303 | \n",
" 0.6900 | \n",
" 0.000000 | \n",
" 0.1100 | \n",
" 0.324 | \n",
" 151.630 | \n",
" audio_features | \n",
" 3Y315h4E3Oc1rGdpr6Mxr9 | \n",
" spotify:track:3Y315h4E3Oc1rGdpr6Mxr9 | \n",
" https://api.spotify.com/v1/tracks/3Y315h4E3Oc1... | \n",
" https://api.spotify.com/v1/audio-analysis/3Y31... | \n",
" 245987 | \n",
" 3 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 2 | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.638 | \n",
" 0.441 | \n",
" 8 | \n",
" -6.909 | \n",
" 0 | \n",
" 0.0290 | \n",
" 0.4150 | \n",
" 0.000079 | \n",
" 0.1100 | \n",
" 0.150 | \n",
" 117.933 | \n",
" audio_features | \n",
" 68tZwwRuo9ip5gRQFG1XWF | \n",
" spotify:track:68tZwwRuo9ip5gRQFG1XWF | \n",
" https://api.spotify.com/v1/tracks/68tZwwRuo9ip... | \n",
" https://api.spotify.com/v1/audio-analysis/68tZ... | \n",
" 271493 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 3 | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.696 | \n",
" 0.837 | \n",
" 0 | \n",
" -5.034 | \n",
" 0 | \n",
" 0.1180 | \n",
" 0.0647 | \n",
" 0.000000 | \n",
" 0.1130 | \n",
" 0.916 | \n",
" 153.294 | \n",
" audio_features | \n",
" 53a8WmHKKrxhDiBRGqDlgV | \n",
" spotify:track:53a8WmHKKrxhDiBRGqDlgV | \n",
" https://api.spotify.com/v1/tracks/53a8WmHKKrxh... | \n",
" https://api.spotify.com/v1/audio-analysis/53a8... | \n",
" 246453 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 4 | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.429 | \n",
" 0.345 | \n",
" 9 | \n",
" -9.724 | \n",
" 0 | \n",
" 0.0371 | \n",
" 0.8580 | \n",
" 0.000000 | \n",
" 0.2680 | \n",
" 0.317 | \n",
" 133.139 | \n",
" audio_features | \n",
" 1GWsEPe6pIYlqrNFEMExdX | \n",
" spotify:track:1GWsEPe6pIYlqrNFEMExdX | \n",
" https://api.spotify.com/v1/tracks/1GWsEPe6pIYl... | \n",
" https://api.spotify.com/v1/audio-analysis/1GWs... | \n",
" 268625 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 5 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 95 | \n",
" 0.540 | \n",
" 0.521 | \n",
" 2 | \n",
" -5.676 | \n",
" 1 | \n",
" 0.0308 | \n",
" 0.5380 | \n",
" 0.000000 | \n",
" 0.1610 | \n",
" 0.193 | \n",
" 119.828 | \n",
" audio_features | \n",
" 7J7bVfhuxXjpLvvp3DijiX | \n",
" spotify:track:7J7bVfhuxXjpLvvp3DijiX | \n",
" https://api.spotify.com/v1/tracks/7J7bVfhuxXjp... | \n",
" https://api.spotify.com/v1/audio-analysis/7J7b... | \n",
" 256000 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 96 | \n",
"
\n",
" \n",
" | 96 | \n",
" 0.808 | \n",
" 0.620 | \n",
" 7 | \n",
" -7.229 | \n",
" 1 | \n",
" 0.1150 | \n",
" 0.0728 | \n",
" 0.000000 | \n",
" 0.0695 | \n",
" 0.921 | \n",
" 129.954 | \n",
" audio_features | \n",
" 4XysPaqDJfL0T6iFJuSNMo | \n",
" spotify:track:4XysPaqDJfL0T6iFJuSNMo | \n",
" https://api.spotify.com/v1/tracks/4XysPaqDJfL0... | \n",
" https://api.spotify.com/v1/audio-analysis/4Xys... | \n",
" 225853 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 97 | \n",
"
\n",
" \n",
" | 97 | \n",
" 0.569 | \n",
" 0.785 | \n",
" 1 | \n",
" -4.057 | \n",
" 0 | \n",
" 0.0457 | \n",
" 0.0505 | \n",
" 0.000001 | \n",
" 0.0860 | \n",
" 0.303 | \n",
" 128.031 | \n",
" audio_features | \n",
" 0xIVvRmjztR1AwuHrkhH41 | \n",
" spotify:track:0xIVvRmjztR1AwuHrkhH41 | \n",
" https://api.spotify.com/v1/tracks/0xIVvRmjztR1... | \n",
" https://api.spotify.com/v1/audio-analysis/0xIV... | \n",
" 148387 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 98 | \n",
"
\n",
" \n",
" | 98 | \n",
" 0.799 | \n",
" 0.610 | \n",
" 10 | \n",
" -6.298 | \n",
" 0 | \n",
" 0.1940 | \n",
" 0.3020 | \n",
" 0.000000 | \n",
" 0.0824 | \n",
" 0.871 | \n",
" 170.037 | \n",
" audio_features | \n",
" 67sEGnjlCAoDRWqNejM0XY | \n",
" spotify:track:67sEGnjlCAoDRWqNejM0XY | \n",
" https://api.spotify.com/v1/tracks/67sEGnjlCAoD... | \n",
" https://api.spotify.com/v1/audio-analysis/67sE... | \n",
" 207219 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 99 | \n",
"
\n",
" \n",
" | 99 | \n",
" 0.508 | \n",
" 0.607 | \n",
" 6 | \n",
" -6.844 | \n",
" 1 | \n",
" 0.0287 | \n",
" 0.4420 | \n",
" 0.000000 | \n",
" 0.0894 | \n",
" 0.389 | \n",
" 143.505 | \n",
" audio_features | \n",
" 1SFVITPd1k2W6ZqZ2muaHD | \n",
" spotify:track:1SFVITPd1k2W6ZqZ2muaHD | \n",
" https://api.spotify.com/v1/tracks/1SFVITPd1k2W... | \n",
" https://api.spotify.com/v1/audio-analysis/1SFV... | \n",
" 282640 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 100 | \n",
"
\n",
" \n",
"
\n",
"
100 rows × 20 columns
\n",
"
"
],
"text/plain": [
" danceability energy key loudness mode speechiness acousticness \\\n",
"0 0.658 0.930 5 -2.912 0 0.1410 0.0236 \n",
"1 0.377 0.182 6 -10.896 1 0.0303 0.6900 \n",
"2 0.638 0.441 8 -6.909 0 0.0290 0.4150 \n",
"3 0.696 0.837 0 -5.034 0 0.1180 0.0647 \n",
"4 0.429 0.345 9 -9.724 0 0.0371 0.8580 \n",
".. ... ... ... ... ... ... ... \n",
"95 0.540 0.521 2 -5.676 1 0.0308 0.5380 \n",
"96 0.808 0.620 7 -7.229 1 0.1150 0.0728 \n",
"97 0.569 0.785 1 -4.057 0 0.0457 0.0505 \n",
"98 0.799 0.610 10 -6.298 0 0.1940 0.3020 \n",
"99 0.508 0.607 6 -6.844 1 0.0287 0.4420 \n",
"\n",
" instrumentalness liveness valence tempo type \\\n",
"0 0.000000 0.5780 0.132 104.018 audio_features \n",
"1 0.000000 0.1100 0.324 151.630 audio_features \n",
"2 0.000079 0.1100 0.150 117.933 audio_features \n",
"3 0.000000 0.1130 0.916 153.294 audio_features \n",
"4 0.000000 0.2680 0.317 133.139 audio_features \n",
".. ... ... ... ... ... \n",
"95 0.000000 0.1610 0.193 119.828 audio_features \n",
"96 0.000000 0.0695 0.921 129.954 audio_features \n",
"97 0.000001 0.0860 0.303 128.031 audio_features \n",
"98 0.000000 0.0824 0.871 170.037 audio_features \n",
"99 0.000000 0.0894 0.389 143.505 audio_features \n",
"\n",
" id uri \\\n",
"0 1RJZLVGpBG9nNZiHRQSWTp spotify:track:1RJZLVGpBG9nNZiHRQSWTp \n",
"1 3Y315h4E3Oc1rGdpr6Mxr9 spotify:track:3Y315h4E3Oc1rGdpr6Mxr9 \n",
"2 68tZwwRuo9ip5gRQFG1XWF spotify:track:68tZwwRuo9ip5gRQFG1XWF \n",
"3 53a8WmHKKrxhDiBRGqDlgV spotify:track:53a8WmHKKrxhDiBRGqDlgV \n",
"4 1GWsEPe6pIYlqrNFEMExdX spotify:track:1GWsEPe6pIYlqrNFEMExdX \n",
".. ... ... \n",
"95 7J7bVfhuxXjpLvvp3DijiX spotify:track:7J7bVfhuxXjpLvvp3DijiX \n",
"96 4XysPaqDJfL0T6iFJuSNMo spotify:track:4XysPaqDJfL0T6iFJuSNMo \n",
"97 0xIVvRmjztR1AwuHrkhH41 spotify:track:0xIVvRmjztR1AwuHrkhH41 \n",
"98 67sEGnjlCAoDRWqNejM0XY spotify:track:67sEGnjlCAoDRWqNejM0XY \n",
"99 1SFVITPd1k2W6ZqZ2muaHD spotify:track:1SFVITPd1k2W6ZqZ2muaHD \n",
"\n",
" track_href \\\n",
"0 https://api.spotify.com/v1/tracks/1RJZLVGpBG9n... \n",
"1 https://api.spotify.com/v1/tracks/3Y315h4E3Oc1... \n",
"2 https://api.spotify.com/v1/tracks/68tZwwRuo9ip... \n",
"3 https://api.spotify.com/v1/tracks/53a8WmHKKrxh... \n",
"4 https://api.spotify.com/v1/tracks/1GWsEPe6pIYl... \n",
".. ... \n",
"95 https://api.spotify.com/v1/tracks/7J7bVfhuxXjp... \n",
"96 https://api.spotify.com/v1/tracks/4XysPaqDJfL0... \n",
"97 https://api.spotify.com/v1/tracks/0xIVvRmjztR1... \n",
"98 https://api.spotify.com/v1/tracks/67sEGnjlCAoD... \n",
"99 https://api.spotify.com/v1/tracks/1SFVITPd1k2W... \n",
"\n",
" analysis_url duration_ms \\\n",
"0 https://api.spotify.com/v1/audio-analysis/1RJZ... 237680 \n",
"1 https://api.spotify.com/v1/audio-analysis/3Y31... 245987 \n",
"2 https://api.spotify.com/v1/audio-analysis/68tZ... 271493 \n",
"3 https://api.spotify.com/v1/audio-analysis/53a8... 246453 \n",
"4 https://api.spotify.com/v1/audio-analysis/1GWs... 268625 \n",
".. ... ... \n",
"95 https://api.spotify.com/v1/audio-analysis/7J7b... 256000 \n",
"96 https://api.spotify.com/v1/audio-analysis/4Xys... 225853 \n",
"97 https://api.spotify.com/v1/audio-analysis/0xIV... 148387 \n",
"98 https://api.spotify.com/v1/audio-analysis/67sE... 207219 \n",
"99 https://api.spotify.com/v1/audio-analysis/1SFV... 282640 \n",
"\n",
" time_signature user_id rank \n",
"0 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 1 \n",
"1 3 d28708a363b58062087293f779256fffa38fdd56c1f79d... 2 \n",
"2 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 3 \n",
"3 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 4 \n",
"4 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 5 \n",
".. ... ... ... \n",
"95 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 96 \n",
"96 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 97 \n",
"97 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 98 \n",
"98 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 99 \n",
"99 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 100 \n",
"\n",
"[100 rows x 20 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tqdm import tqdm\n",
"diverse_recs = []\n",
"for index, row in tqdm(seeds_diverse.iterrows(), total= len(seeds_diverse)):\n",
" recs = api.getRecommendations(seed_tracks=row['track_seeds'], seed_genres=row['genre_seeds'], limit=100)\n",
" if recs != 'Error':\n",
" diverse_recs.append(convertResponseToDf(recs, row['user_id']))\n",
"diverse_recs[0]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 45/45 [07:37<00:00, 10.17s/it]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" danceability | \n",
" energy | \n",
" key | \n",
" loudness | \n",
" mode | \n",
" speechiness | \n",
" acousticness | \n",
" instrumentalness | \n",
" liveness | \n",
" valence | \n",
" tempo | \n",
" type | \n",
" id | \n",
" uri | \n",
" track_href | \n",
" analysis_url | \n",
" duration_ms | \n",
" time_signature | \n",
" user_id | \n",
" rank | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 0.376 | \n",
" 0.809 | \n",
" 5 | \n",
" -3.905 | \n",
" 1 | \n",
" 0.1680 | \n",
" 0.03390 | \n",
" 0.096500 | \n",
" 0.6880 | \n",
" 0.147 | \n",
" 121.887 | \n",
" audio_features | \n",
" 3ZbmDl4M9O587VmD9IqyIj | \n",
" spotify:track:3ZbmDl4M9O587VmD9IqyIj | \n",
" https://api.spotify.com/v1/tracks/3ZbmDl4M9O58... | \n",
" https://api.spotify.com/v1/audio-analysis/3Zbm... | \n",
" 269040 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 1 | \n",
"
\n",
" \n",
" | 1 | \n",
" 0.725 | \n",
" 0.394 | \n",
" 8 | \n",
" -7.120 | \n",
" 1 | \n",
" 0.1640 | \n",
" 0.11400 | \n",
" 0.000000 | \n",
" 0.0794 | \n",
" 0.399 | \n",
" 81.176 | \n",
" audio_features | \n",
" 7FA2oxGAfveiECwzeUqOja | \n",
" spotify:track:7FA2oxGAfveiECwzeUqOja | \n",
" https://api.spotify.com/v1/tracks/7FA2oxGAfvei... | \n",
" https://api.spotify.com/v1/audio-analysis/7FA2... | \n",
" 215720 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 2 | \n",
"
\n",
" \n",
" | 2 | \n",
" 0.438 | \n",
" 0.894 | \n",
" 8 | \n",
" -4.247 | \n",
" 0 | \n",
" 0.1080 | \n",
" 0.00300 | \n",
" 0.000000 | \n",
" 0.2990 | \n",
" 0.212 | \n",
" 126.958 | \n",
" audio_features | \n",
" 3eunKmoXb7y9D5xmbGbfW5 | \n",
" spotify:track:3eunKmoXb7y9D5xmbGbfW5 | \n",
" https://api.spotify.com/v1/tracks/3eunKmoXb7y9... | \n",
" https://api.spotify.com/v1/audio-analysis/3eun... | \n",
" 162040 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 3 | \n",
"
\n",
" \n",
" | 3 | \n",
" 0.715 | \n",
" 0.350 | \n",
" 11 | \n",
" -13.846 | \n",
" 1 | \n",
" 0.1210 | \n",
" 0.04690 | \n",
" 0.000000 | \n",
" 0.0724 | \n",
" 0.752 | \n",
" 81.682 | \n",
" audio_features | \n",
" 0j2hYbbYeadrfJgII5bhea | \n",
" spotify:track:0j2hYbbYeadrfJgII5bhea | \n",
" https://api.spotify.com/v1/tracks/0j2hYbbYeadr... | \n",
" https://api.spotify.com/v1/audio-analysis/0j2h... | \n",
" 213360 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 4 | \n",
"
\n",
" \n",
" | 4 | \n",
" 0.766 | \n",
" 0.427 | \n",
" 4 | \n",
" -10.959 | \n",
" 0 | \n",
" 0.3360 | \n",
" 0.73100 | \n",
" 0.000572 | \n",
" 0.1840 | \n",
" 0.823 | \n",
" 74.063 | \n",
" audio_features | \n",
" 2p6WDr28CJXYNglfrneMLL | \n",
" spotify:track:2p6WDr28CJXYNglfrneMLL | \n",
" https://api.spotify.com/v1/tracks/2p6WDr28CJXY... | \n",
" https://api.spotify.com/v1/audio-analysis/2p6W... | \n",
" 206200 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 5 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 95 | \n",
" 0.421 | \n",
" 0.806 | \n",
" 10 | \n",
" -4.104 | \n",
" 1 | \n",
" 0.1620 | \n",
" 0.06650 | \n",
" 0.000000 | \n",
" 0.0966 | \n",
" 0.400 | \n",
" 102.031 | \n",
" audio_features | \n",
" 2dVPrA2SRVlDqgSjTgCMiJ | \n",
" spotify:track:2dVPrA2SRVlDqgSjTgCMiJ | \n",
" https://api.spotify.com/v1/tracks/2dVPrA2SRVlD... | \n",
" https://api.spotify.com/v1/audio-analysis/2dVP... | \n",
" 162400 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 96 | \n",
"
\n",
" \n",
" | 96 | \n",
" 0.714 | \n",
" 0.480 | \n",
" 7 | \n",
" -6.643 | \n",
" 0 | \n",
" 0.2680 | \n",
" 0.02590 | \n",
" 0.000000 | \n",
" 0.0912 | \n",
" 0.756 | \n",
" 75.875 | \n",
" audio_features | \n",
" 5zqqkvoeXhgab0ALShNeyn | \n",
" spotify:track:5zqqkvoeXhgab0ALShNeyn | \n",
" https://api.spotify.com/v1/tracks/5zqqkvoeXhga... | \n",
" https://api.spotify.com/v1/audio-analysis/5zqq... | \n",
" 233973 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 97 | \n",
"
\n",
" \n",
" | 97 | \n",
" 0.499 | \n",
" 0.826 | \n",
" 9 | \n",
" -7.082 | \n",
" 0 | \n",
" 0.0534 | \n",
" 0.00095 | \n",
" 0.029000 | \n",
" 0.1220 | \n",
" 0.427 | \n",
" 140.007 | \n",
" audio_features | \n",
" 5OJ8hNTKYU2dCvdgnOarLU | \n",
" spotify:track:5OJ8hNTKYU2dCvdgnOarLU | \n",
" https://api.spotify.com/v1/tracks/5OJ8hNTKYU2d... | \n",
" https://api.spotify.com/v1/audio-analysis/5OJ8... | \n",
" 281083 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 98 | \n",
"
\n",
" \n",
" | 98 | \n",
" 0.703 | \n",
" 0.777 | \n",
" 1 | \n",
" -4.760 | \n",
" 1 | \n",
" 0.1430 | \n",
" 0.03150 | \n",
" 0.000066 | \n",
" 0.0485 | \n",
" 0.586 | \n",
" 160.112 | \n",
" audio_features | \n",
" 2rK7knZC1komGjPscuEXV5 | \n",
" spotify:track:2rK7knZC1komGjPscuEXV5 | \n",
" https://api.spotify.com/v1/tracks/2rK7knZC1kom... | \n",
" https://api.spotify.com/v1/audio-analysis/2rK7... | \n",
" 319920 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 99 | \n",
"
\n",
" \n",
" | 99 | \n",
" 0.694 | \n",
" 0.751 | \n",
" 0 | \n",
" -5.344 | \n",
" 1 | \n",
" 0.0302 | \n",
" 0.04590 | \n",
" 0.000013 | \n",
" 0.1460 | \n",
" 0.479 | \n",
" 130.010 | \n",
" audio_features | \n",
" 00Hht4IVIdQUSxJBf4BK9U | \n",
" spotify:track:00Hht4IVIdQUSxJBf4BK9U | \n",
" https://api.spotify.com/v1/tracks/00Hht4IVIdQU... | \n",
" https://api.spotify.com/v1/audio-analysis/00Hh... | \n",
" 245344 | \n",
" 4 | \n",
" d28708a363b58062087293f779256fffa38fdd56c1f79d... | \n",
" 100 | \n",
"
\n",
" \n",
"
\n",
"
100 rows × 20 columns
\n",
"
"
],
"text/plain": [
" danceability energy key loudness mode speechiness acousticness \\\n",
"0 0.376 0.809 5 -3.905 1 0.1680 0.03390 \n",
"1 0.725 0.394 8 -7.120 1 0.1640 0.11400 \n",
"2 0.438 0.894 8 -4.247 0 0.1080 0.00300 \n",
"3 0.715 0.350 11 -13.846 1 0.1210 0.04690 \n",
"4 0.766 0.427 4 -10.959 0 0.3360 0.73100 \n",
".. ... ... ... ... ... ... ... \n",
"95 0.421 0.806 10 -4.104 1 0.1620 0.06650 \n",
"96 0.714 0.480 7 -6.643 0 0.2680 0.02590 \n",
"97 0.499 0.826 9 -7.082 0 0.0534 0.00095 \n",
"98 0.703 0.777 1 -4.760 1 0.1430 0.03150 \n",
"99 0.694 0.751 0 -5.344 1 0.0302 0.04590 \n",
"\n",
" instrumentalness liveness valence tempo type \\\n",
"0 0.096500 0.6880 0.147 121.887 audio_features \n",
"1 0.000000 0.0794 0.399 81.176 audio_features \n",
"2 0.000000 0.2990 0.212 126.958 audio_features \n",
"3 0.000000 0.0724 0.752 81.682 audio_features \n",
"4 0.000572 0.1840 0.823 74.063 audio_features \n",
".. ... ... ... ... ... \n",
"95 0.000000 0.0966 0.400 102.031 audio_features \n",
"96 0.000000 0.0912 0.756 75.875 audio_features \n",
"97 0.029000 0.1220 0.427 140.007 audio_features \n",
"98 0.000066 0.0485 0.586 160.112 audio_features \n",
"99 0.000013 0.1460 0.479 130.010 audio_features \n",
"\n",
" id uri \\\n",
"0 3ZbmDl4M9O587VmD9IqyIj spotify:track:3ZbmDl4M9O587VmD9IqyIj \n",
"1 7FA2oxGAfveiECwzeUqOja spotify:track:7FA2oxGAfveiECwzeUqOja \n",
"2 3eunKmoXb7y9D5xmbGbfW5 spotify:track:3eunKmoXb7y9D5xmbGbfW5 \n",
"3 0j2hYbbYeadrfJgII5bhea spotify:track:0j2hYbbYeadrfJgII5bhea \n",
"4 2p6WDr28CJXYNglfrneMLL spotify:track:2p6WDr28CJXYNglfrneMLL \n",
".. ... ... \n",
"95 2dVPrA2SRVlDqgSjTgCMiJ spotify:track:2dVPrA2SRVlDqgSjTgCMiJ \n",
"96 5zqqkvoeXhgab0ALShNeyn spotify:track:5zqqkvoeXhgab0ALShNeyn \n",
"97 5OJ8hNTKYU2dCvdgnOarLU spotify:track:5OJ8hNTKYU2dCvdgnOarLU \n",
"98 2rK7knZC1komGjPscuEXV5 spotify:track:2rK7knZC1komGjPscuEXV5 \n",
"99 00Hht4IVIdQUSxJBf4BK9U spotify:track:00Hht4IVIdQUSxJBf4BK9U \n",
"\n",
" track_href \\\n",
"0 https://api.spotify.com/v1/tracks/3ZbmDl4M9O58... \n",
"1 https://api.spotify.com/v1/tracks/7FA2oxGAfvei... \n",
"2 https://api.spotify.com/v1/tracks/3eunKmoXb7y9... \n",
"3 https://api.spotify.com/v1/tracks/0j2hYbbYeadr... \n",
"4 https://api.spotify.com/v1/tracks/2p6WDr28CJXY... \n",
".. ... \n",
"95 https://api.spotify.com/v1/tracks/2dVPrA2SRVlD... \n",
"96 https://api.spotify.com/v1/tracks/5zqqkvoeXhga... \n",
"97 https://api.spotify.com/v1/tracks/5OJ8hNTKYU2d... \n",
"98 https://api.spotify.com/v1/tracks/2rK7knZC1kom... \n",
"99 https://api.spotify.com/v1/tracks/00Hht4IVIdQU... \n",
"\n",
" analysis_url duration_ms \\\n",
"0 https://api.spotify.com/v1/audio-analysis/3Zbm... 269040 \n",
"1 https://api.spotify.com/v1/audio-analysis/7FA2... 215720 \n",
"2 https://api.spotify.com/v1/audio-analysis/3eun... 162040 \n",
"3 https://api.spotify.com/v1/audio-analysis/0j2h... 213360 \n",
"4 https://api.spotify.com/v1/audio-analysis/2p6W... 206200 \n",
".. ... ... \n",
"95 https://api.spotify.com/v1/audio-analysis/2dVP... 162400 \n",
"96 https://api.spotify.com/v1/audio-analysis/5zqq... 233973 \n",
"97 https://api.spotify.com/v1/audio-analysis/5OJ8... 281083 \n",
"98 https://api.spotify.com/v1/audio-analysis/2rK7... 319920 \n",
"99 https://api.spotify.com/v1/audio-analysis/00Hh... 245344 \n",
"\n",
" time_signature user_id rank \n",
"0 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 1 \n",
"1 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 2 \n",
"2 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 3 \n",
"3 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 4 \n",
"4 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 5 \n",
".. ... ... ... \n",
"95 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 96 \n",
"96 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 97 \n",
"97 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 98 \n",
"98 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 99 \n",
"99 4 d28708a363b58062087293f779256fffa38fdd56c1f79d... 100 \n",
"\n",
"[100 rows x 20 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# TODO handle 0 seeds\n",
"from tqdm import tqdm\n",
"non_diverse_recs = []\n",
"for index, row in tqdm(seeds_non_diverse.iterrows(), total= len(seeds_non_diverse)):\n",
" recs = api.getRecommendations(seed_tracks=row['track_seeds'], seed_genres=row['genre_seeds'], limit=100)\n",
" if recs != 'Error':\n",
" non_diverse_recs.append(convertResponseToDf(recs, row['user_id']))\n",
"non_diverse_recs[0]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"45\n",
"45\n"
]
}
],
"source": [
"print(len(diverse_recs))\n",
"print(len(non_diverse_recs))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Save it all!\n",
"diverse_df = pd.concat(diverse_recs)\n",
"non_diverse_df = pd.concat(non_diverse_recs)\n",
"\n",
"diverse_df.to_csv('participant data/recommendations_diverse.csv')\n",
"non_diverse_df.to_csv('participant data/recommendations_non_diverse.csv')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# genres = api.getAvailableGenres()\n",
"# genres = genres['genres']\n",
"# genres"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.6 ('venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "a5f6721cff687d3080de9329c3bd8bdd11a992611b372cba762cc6d8bb8ccdc5"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}