Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/agbocsardi/dss-group-assignment.
Something went wrong. Try again.
dss-group-assignment API_Testing_Ground.ipynb
58 kB · 1396 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397{ "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": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>Unnamed: 0</th>\n", " <th>user_id</th>\n", " <th>track_seeds</th>\n", " <th>genre_seeds</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>0</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,...</td>\n", " <td>reggae,electronic</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>1</td>\n", " <td>12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117...</td>\n", " <td>6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,...</td>\n", " <td>jazz,funk</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>2</td>\n", " <td>1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15...</td>\n", " <td>1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,...</td>\n", " <td>classical,rnb</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>3</td>\n", " <td>ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21...</td>\n", " <td>04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,...</td>\n", " <td>rockabilly,dubstep</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>4</td>\n", " <td>1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900...</td>\n", " <td>76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,...</td>\n", " <td>hard-rock,progressive-house</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "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": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>Unnamed: 0</th>\n", " <th>user_id</th>\n", " <th>track_seeds</th>\n", " <th>genre_seeds</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>0</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>2LfyBCqm9JlARHp22qWMxt,6VcRonz2dMc0xgbi5R14HF,...</td>\n", " <td>reggae,electronic</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>1</td>\n", " <td>12f2e84ef897c8e32d9919871acbe861b4ac4b5ef26117...</td>\n", " <td>6SQLk9HSNketfgs2AyIiMs,1rRwwqteLePmi70PGaC8ah,...</td>\n", " <td>jazz,funk</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>2</td>\n", " <td>1dbfdf95b6c701b8852fd90799cc45ddba10435d8e9e15...</td>\n", " <td>1HNkqx9Ahdgi1Ixy2xkKkL,6Ed1q0X8oSKSm4IIhiQbYg,...</td>\n", " <td>classical,rnb</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>3</td>\n", " <td>ed56810fb3ca5f82385492151b3d37f9f2d21eabebef21...</td>\n", " <td>04colE4oJt50AHwFhrT57v,7bzaIsOrDQRomB7dzbILaD,...</td>\n", " <td>rockabilly,dubstep</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>4</td>\n", " <td>1418fcc80d2e4febb58f44fcd93ff755df16b64edfa900...</td>\n", " <td>76voC75r72iKgNsmEMkDBX,15O3cEqfhnudkoMfZcJ7XV,...</td>\n", " <td>hard-rock,progressive-house</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "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": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>danceability</th>\n", " <th>energy</th>\n", " <th>key</th>\n", " <th>loudness</th>\n", " <th>mode</th>\n", " <th>speechiness</th>\n", " <th>acousticness</th>\n", " <th>instrumentalness</th>\n", " <th>liveness</th>\n", " <th>valence</th>\n", " <th>tempo</th>\n", " <th>type</th>\n", " <th>id</th>\n", " <th>uri</th>\n", " <th>track_href</th>\n", " <th>analysis_url</th>\n", " <th>duration_ms</th>\n", " <th>time_signature</th>\n", " <th>user_id</th>\n", " <th>rank</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>0.658</td>\n", " <td>0.930</td>\n", " <td>5</td>\n", " <td>-2.912</td>\n", " <td>0</td>\n", " <td>0.1410</td>\n", " <td>0.0236</td>\n", " <td>0.000000</td>\n", " <td>0.5780</td>\n", " <td>0.132</td>\n", " <td>104.018</td>\n", " <td>audio_features</td>\n", " <td>1RJZLVGpBG9nNZiHRQSWTp</td>\n", " <td>spotify:track:1RJZLVGpBG9nNZiHRQSWTp</td>\n", " <td>https://api.spotify.com/v1/tracks/1RJZLVGpBG9n...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/1RJZ...</td>\n", " <td>237680</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>0.377</td>\n", " <td>0.182</td>\n", " <td>6</td>\n", " <td>-10.896</td>\n", " <td>1</td>\n", " <td>0.0303</td>\n", " <td>0.6900</td>\n", " <td>0.000000</td>\n", " <td>0.1100</td>\n", " <td>0.324</td>\n", " <td>151.630</td>\n", " <td>audio_features</td>\n", " <td>3Y315h4E3Oc1rGdpr6Mxr9</td>\n", " <td>spotify:track:3Y315h4E3Oc1rGdpr6Mxr9</td>\n", " <td>https://api.spotify.com/v1/tracks/3Y315h4E3Oc1...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/3Y31...</td>\n", " <td>245987</td>\n", " <td>3</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>0.638</td>\n", " <td>0.441</td>\n", " <td>8</td>\n", " <td>-6.909</td>\n", " <td>0</td>\n", " <td>0.0290</td>\n", " <td>0.4150</td>\n", " <td>0.000079</td>\n", " <td>0.1100</td>\n", " <td>0.150</td>\n", " <td>117.933</td>\n", " <td>audio_features</td>\n", " <td>68tZwwRuo9ip5gRQFG1XWF</td>\n", " <td>spotify:track:68tZwwRuo9ip5gRQFG1XWF</td>\n", " <td>https://api.spotify.com/v1/tracks/68tZwwRuo9ip...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/68tZ...</td>\n", " <td>271493</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>3</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>0.696</td>\n", " <td>0.837</td>\n", " <td>0</td>\n", " <td>-5.034</td>\n", " <td>0</td>\n", " <td>0.1180</td>\n", " <td>0.0647</td>\n", " <td>0.000000</td>\n", " <td>0.1130</td>\n", " <td>0.916</td>\n", " <td>153.294</td>\n", " <td>audio_features</td>\n", " <td>53a8WmHKKrxhDiBRGqDlgV</td>\n", " <td>spotify:track:53a8WmHKKrxhDiBRGqDlgV</td>\n", " <td>https://api.spotify.com/v1/tracks/53a8WmHKKrxh...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/53a8...</td>\n", " <td>246453</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>4</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>0.429</td>\n", " <td>0.345</td>\n", " <td>9</td>\n", " <td>-9.724</td>\n", " <td>0</td>\n", " <td>0.0371</td>\n", " <td>0.8580</td>\n", " <td>0.000000</td>\n", " <td>0.2680</td>\n", " <td>0.317</td>\n", " <td>133.139</td>\n", " <td>audio_features</td>\n", " <td>1GWsEPe6pIYlqrNFEMExdX</td>\n", " <td>spotify:track:1GWsEPe6pIYlqrNFEMExdX</td>\n", " <td>https://api.spotify.com/v1/tracks/1GWsEPe6pIYl...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/1GWs...</td>\n", " <td>268625</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>5</td>\n", " </tr>\n", " <tr>\n", " <th>...</th>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " </tr>\n", " <tr>\n", " <th>95</th>\n", " <td>0.540</td>\n", " <td>0.521</td>\n", " <td>2</td>\n", " <td>-5.676</td>\n", " <td>1</td>\n", " <td>0.0308</td>\n", " <td>0.5380</td>\n", " <td>0.000000</td>\n", " <td>0.1610</td>\n", " <td>0.193</td>\n", " <td>119.828</td>\n", " <td>audio_features</td>\n", " <td>7J7bVfhuxXjpLvvp3DijiX</td>\n", " <td>spotify:track:7J7bVfhuxXjpLvvp3DijiX</td>\n", " <td>https://api.spotify.com/v1/tracks/7J7bVfhuxXjp...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/7J7b...</td>\n", " <td>256000</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>96</td>\n", " </tr>\n", " <tr>\n", " <th>96</th>\n", " <td>0.808</td>\n", " <td>0.620</td>\n", " <td>7</td>\n", " <td>-7.229</td>\n", " <td>1</td>\n", " <td>0.1150</td>\n", " <td>0.0728</td>\n", " <td>0.000000</td>\n", " <td>0.0695</td>\n", " <td>0.921</td>\n", " <td>129.954</td>\n", " <td>audio_features</td>\n", " <td>4XysPaqDJfL0T6iFJuSNMo</td>\n", " <td>spotify:track:4XysPaqDJfL0T6iFJuSNMo</td>\n", " <td>https://api.spotify.com/v1/tracks/4XysPaqDJfL0...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/4Xys...</td>\n", " <td>225853</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>97</td>\n", " </tr>\n", " <tr>\n", " <th>97</th>\n", " <td>0.569</td>\n", " <td>0.785</td>\n", " <td>1</td>\n", " <td>-4.057</td>\n", " <td>0</td>\n", " <td>0.0457</td>\n", " <td>0.0505</td>\n", " <td>0.000001</td>\n", " <td>0.0860</td>\n", " <td>0.303</td>\n", " <td>128.031</td>\n", " <td>audio_features</td>\n", " <td>0xIVvRmjztR1AwuHrkhH41</td>\n", " <td>spotify:track:0xIVvRmjztR1AwuHrkhH41</td>\n", " <td>https://api.spotify.com/v1/tracks/0xIVvRmjztR1...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/0xIV...</td>\n", " <td>148387</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>98</td>\n", " </tr>\n", " <tr>\n", " <th>98</th>\n", " <td>0.799</td>\n", " <td>0.610</td>\n", " <td>10</td>\n", " <td>-6.298</td>\n", " <td>0</td>\n", " <td>0.1940</td>\n", " <td>0.3020</td>\n", " <td>0.000000</td>\n", " <td>0.0824</td>\n", " <td>0.871</td>\n", " <td>170.037</td>\n", " <td>audio_features</td>\n", " <td>67sEGnjlCAoDRWqNejM0XY</td>\n", " <td>spotify:track:67sEGnjlCAoDRWqNejM0XY</td>\n", " <td>https://api.spotify.com/v1/tracks/67sEGnjlCAoD...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/67sE...</td>\n", " <td>207219</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>99</td>\n", " </tr>\n", " <tr>\n", " <th>99</th>\n", " <td>0.508</td>\n", " <td>0.607</td>\n", " <td>6</td>\n", " <td>-6.844</td>\n", " <td>1</td>\n", " <td>0.0287</td>\n", " <td>0.4420</td>\n", " <td>0.000000</td>\n", " <td>0.0894</td>\n", " <td>0.389</td>\n", " <td>143.505</td>\n", " <td>audio_features</td>\n", " <td>1SFVITPd1k2W6ZqZ2muaHD</td>\n", " <td>spotify:track:1SFVITPd1k2W6ZqZ2muaHD</td>\n", " <td>https://api.spotify.com/v1/tracks/1SFVITPd1k2W...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/1SFV...</td>\n", " <td>282640</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>100</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>100 rows × 20 columns</p>\n", "</div>" ], "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": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>danceability</th>\n", " <th>energy</th>\n", " <th>key</th>\n", " <th>loudness</th>\n", " <th>mode</th>\n", " <th>speechiness</th>\n", " <th>acousticness</th>\n", " <th>instrumentalness</th>\n", " <th>liveness</th>\n", " <th>valence</th>\n", " <th>tempo</th>\n", " <th>type</th>\n", " <th>id</th>\n", " <th>uri</th>\n", " <th>track_href</th>\n", " <th>analysis_url</th>\n", " <th>duration_ms</th>\n", " <th>time_signature</th>\n", " <th>user_id</th>\n", " <th>rank</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>0.376</td>\n", " <td>0.809</td>\n", " <td>5</td>\n", " <td>-3.905</td>\n", " <td>1</td>\n", " <td>0.1680</td>\n", " <td>0.03390</td>\n", " <td>0.096500</td>\n", " <td>0.6880</td>\n", " <td>0.147</td>\n", " <td>121.887</td>\n", " <td>audio_features</td>\n", " <td>3ZbmDl4M9O587VmD9IqyIj</td>\n", " <td>spotify:track:3ZbmDl4M9O587VmD9IqyIj</td>\n", " <td>https://api.spotify.com/v1/tracks/3ZbmDl4M9O58...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/3Zbm...</td>\n", " <td>269040</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>1</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>0.725</td>\n", " <td>0.394</td>\n", " <td>8</td>\n", " <td>-7.120</td>\n", " <td>1</td>\n", " <td>0.1640</td>\n", " <td>0.11400</td>\n", " <td>0.000000</td>\n", " <td>0.0794</td>\n", " <td>0.399</td>\n", " <td>81.176</td>\n", " <td>audio_features</td>\n", " <td>7FA2oxGAfveiECwzeUqOja</td>\n", " <td>spotify:track:7FA2oxGAfveiECwzeUqOja</td>\n", " <td>https://api.spotify.com/v1/tracks/7FA2oxGAfvei...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/7FA2...</td>\n", " <td>215720</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>2</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>0.438</td>\n", " <td>0.894</td>\n", " <td>8</td>\n", " <td>-4.247</td>\n", " <td>0</td>\n", " <td>0.1080</td>\n", " <td>0.00300</td>\n", " <td>0.000000</td>\n", " <td>0.2990</td>\n", " <td>0.212</td>\n", " <td>126.958</td>\n", " <td>audio_features</td>\n", " <td>3eunKmoXb7y9D5xmbGbfW5</td>\n", " <td>spotify:track:3eunKmoXb7y9D5xmbGbfW5</td>\n", " <td>https://api.spotify.com/v1/tracks/3eunKmoXb7y9...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/3eun...</td>\n", " <td>162040</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>3</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>0.715</td>\n", " <td>0.350</td>\n", " <td>11</td>\n", " <td>-13.846</td>\n", " <td>1</td>\n", " <td>0.1210</td>\n", " <td>0.04690</td>\n", " <td>0.000000</td>\n", " <td>0.0724</td>\n", " <td>0.752</td>\n", " <td>81.682</td>\n", " <td>audio_features</td>\n", " <td>0j2hYbbYeadrfJgII5bhea</td>\n", " <td>spotify:track:0j2hYbbYeadrfJgII5bhea</td>\n", " <td>https://api.spotify.com/v1/tracks/0j2hYbbYeadr...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/0j2h...</td>\n", " <td>213360</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>4</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>0.766</td>\n", " <td>0.427</td>\n", " <td>4</td>\n", " <td>-10.959</td>\n", " <td>0</td>\n", " <td>0.3360</td>\n", " <td>0.73100</td>\n", " <td>0.000572</td>\n", " <td>0.1840</td>\n", " <td>0.823</td>\n", " <td>74.063</td>\n", " <td>audio_features</td>\n", " <td>2p6WDr28CJXYNglfrneMLL</td>\n", " <td>spotify:track:2p6WDr28CJXYNglfrneMLL</td>\n", " <td>https://api.spotify.com/v1/tracks/2p6WDr28CJXY...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/2p6W...</td>\n", " <td>206200</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>5</td>\n", " </tr>\n", " <tr>\n", " <th>...</th>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " </tr>\n", " <tr>\n", " <th>95</th>\n", " <td>0.421</td>\n", " <td>0.806</td>\n", " <td>10</td>\n", " <td>-4.104</td>\n", " <td>1</td>\n", " <td>0.1620</td>\n", " <td>0.06650</td>\n", " <td>0.000000</td>\n", " <td>0.0966</td>\n", " <td>0.400</td>\n", " <td>102.031</td>\n", " <td>audio_features</td>\n", " <td>2dVPrA2SRVlDqgSjTgCMiJ</td>\n", " <td>spotify:track:2dVPrA2SRVlDqgSjTgCMiJ</td>\n", " <td>https://api.spotify.com/v1/tracks/2dVPrA2SRVlD...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/2dVP...</td>\n", " <td>162400</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>96</td>\n", " </tr>\n", " <tr>\n", " <th>96</th>\n", " <td>0.714</td>\n", " <td>0.480</td>\n", " <td>7</td>\n", " <td>-6.643</td>\n", " <td>0</td>\n", " <td>0.2680</td>\n", " <td>0.02590</td>\n", " <td>0.000000</td>\n", " <td>0.0912</td>\n", " <td>0.756</td>\n", " <td>75.875</td>\n", " <td>audio_features</td>\n", " <td>5zqqkvoeXhgab0ALShNeyn</td>\n", " <td>spotify:track:5zqqkvoeXhgab0ALShNeyn</td>\n", " <td>https://api.spotify.com/v1/tracks/5zqqkvoeXhga...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/5zqq...</td>\n", " <td>233973</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>97</td>\n", " </tr>\n", " <tr>\n", " <th>97</th>\n", " <td>0.499</td>\n", " <td>0.826</td>\n", " <td>9</td>\n", " <td>-7.082</td>\n", " <td>0</td>\n", " <td>0.0534</td>\n", " <td>0.00095</td>\n", " <td>0.029000</td>\n", " <td>0.1220</td>\n", " <td>0.427</td>\n", " <td>140.007</td>\n", " <td>audio_features</td>\n", " <td>5OJ8hNTKYU2dCvdgnOarLU</td>\n", " <td>spotify:track:5OJ8hNTKYU2dCvdgnOarLU</td>\n", " <td>https://api.spotify.com/v1/tracks/5OJ8hNTKYU2d...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/5OJ8...</td>\n", " <td>281083</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>98</td>\n", " </tr>\n", " <tr>\n", " <th>98</th>\n", " <td>0.703</td>\n", " <td>0.777</td>\n", " <td>1</td>\n", " <td>-4.760</td>\n", " <td>1</td>\n", " <td>0.1430</td>\n", " <td>0.03150</td>\n", " <td>0.000066</td>\n", " <td>0.0485</td>\n", " <td>0.586</td>\n", " <td>160.112</td>\n", " <td>audio_features</td>\n", " <td>2rK7knZC1komGjPscuEXV5</td>\n", " <td>spotify:track:2rK7knZC1komGjPscuEXV5</td>\n", " <td>https://api.spotify.com/v1/tracks/2rK7knZC1kom...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/2rK7...</td>\n", " <td>319920</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>99</td>\n", " </tr>\n", " <tr>\n", " <th>99</th>\n", " <td>0.694</td>\n", " <td>0.751</td>\n", " <td>0</td>\n", " <td>-5.344</td>\n", " <td>1</td>\n", " <td>0.0302</td>\n", " <td>0.04590</td>\n", " <td>0.000013</td>\n", " <td>0.1460</td>\n", " <td>0.479</td>\n", " <td>130.010</td>\n", " <td>audio_features</td>\n", " <td>00Hht4IVIdQUSxJBf4BK9U</td>\n", " <td>spotify:track:00Hht4IVIdQUSxJBf4BK9U</td>\n", " <td>https://api.spotify.com/v1/tracks/00Hht4IVIdQU...</td>\n", " <td>https://api.spotify.com/v1/audio-analysis/00Hh...</td>\n", " <td>245344</td>\n", " <td>4</td>\n", " <td>d28708a363b58062087293f779256fffa38fdd56c1f79d...</td>\n", " <td>100</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>100 rows × 20 columns</p>\n", "</div>" ], "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}