workshops_recommender_systems/P5. Graph-based.ipynb

1572 lines
576 KiB
Plaintext
Raw Normal View History

2020-06-13 22:14:04 +02:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Self made RP3-beta"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import helpers\n",
"import pandas as pd\n",
"import numpy as np\n",
"import scipy.sparse as sparse\n",
"from collections import defaultdict\n",
"from itertools import chain\n",
"import random\n",
"import time\n",
"import matplotlib.pyplot as plt\n",
"\n",
"train_read=pd.read_csv('./Datasets/ml-100k/train.csv', sep='\\t', header=None)\n",
"test_read=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
"train_ui, test_ui, user_code_id, user_id_code, item_code_id, item_id_code = helpers.data_to_csr(train_read, test_read)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"class RP3Beta():\n",
" def fit(self, train_ui, alpha, beta):\n",
" \"\"\"We weight our edges by user's explicit ratings so if user rated movie high we'll follow that path\n",
" with higher probability.\"\"\"\n",
" self.train_ui=train_ui\n",
" self.train_iu=train_ui.transpose()\n",
" \n",
" self.alpha = alpha\n",
" self.beta = beta\n",
" \n",
" # Define Pui \n",
" Pui=sparse.csr_matrix(self.train_ui/self.train_ui.sum(axis=1))\n",
" \n",
" # Define Piu\n",
" to_divide=np.vectorize(lambda x: x if x>0 else 1)(self.train_iu.sum(axis=1)) # to avoid dividing by zero\n",
" Piu=sparse.csr_matrix(self.train_iu/to_divide)\n",
" item_orders=(self.train_ui>0).sum(axis=0)\n",
" \n",
" Pui = Pui.power(self.alpha)\n",
" Piu = Piu.power(self.alpha)\n",
"\n",
" P3=Pui*Piu*Pui\n",
" \n",
" P3/=np.power(np.vectorize(lambda x: x if x>0 else 1)(item_orders), self.beta)\n",
" \n",
" self.estimations=np.array(P3)\n",
" \n",
" def recommend(self, user_code_id, item_code_id, topK=10):\n",
" \n",
" top_k = defaultdict(list)\n",
" for nb_user, user in enumerate(self.estimations):\n",
" \n",
" user_rated=self.train_ui.indices[self.train_ui.indptr[nb_user]:self.train_ui.indptr[nb_user+1]]\n",
" for item, score in enumerate(user):\n",
" if item not in user_rated and not np.isnan(score):\n",
" top_k[user_code_id[nb_user]].append((item_code_id[item], score))\n",
" result=[]\n",
" # Let's choose k best items in the format: (user, item1, score1, item2, score2, ...)\n",
" for uid, item_scores in top_k.items():\n",
" item_scores.sort(key=lambda x: x[1], reverse=True)\n",
" result.append([uid]+list(chain(*item_scores[:topK])))\n",
" return result\n",
" \n",
" def estimate(self, user_code_id, item_code_id, test_ui):\n",
" result=[]\n",
" for user, item in zip(*test_ui.nonzero()):\n",
" result.append([user_code_id[user], item_code_id[item], \n",
" self.estimations[user,item] if not np.isnan(self.estimations[user,item]) else 1])\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"model=RP3Beta()\n",
"model.fit(train_ui, alpha=1, beta=0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"top_n=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
"\n",
"top_n.to_csv('Recommendations generated/ml-100k/Self_P3_reco.csv', index=False, header=False)\n",
"\n",
"estimations=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
"estimations.to_csv('Recommendations generated/ml-100k/Self_P3_estimations.csv', index=False, header=False)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"943it [00:00, 2167.43it/s]\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>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>HR2</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.21698</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>0.685048</td>\n",
" <td>1.0</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision recall F_1 F_05 \\\n",
"0 3.702446 3.527273 0.282185 0.192092 0.186749 0.21698 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.204185 0.240096 0.339114 0.204905 0.572157 0.593544 \n",
"\n",
" HR HR2 Reco in test Test coverage Shannon Gini \n",
"0 0.875928 0.685048 1.0 0.077201 3.875892 0.974947 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import evaluation_measures as ev\n",
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Self_P3_estimations.csv', header=None)\n",
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_P3_reco.csv', delimiter=',')\n",
"\n",
"ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=reco,\n",
" super_reactions=[4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Let's check hiperparameters"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Alpha"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/8 [00:00<?, ?it/s]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"280it [00:00, 2775.23it/s]\u001b[A\n",
"526it [00:00, 2666.15it/s]\u001b[A\n",
"943it [00:00, 2520.30it/s]\u001b[A\n",
" 12%|██████████▌ | 1/8 [00:24<02:50, 24.33s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"247it [00:00, 2452.10it/s]\u001b[A\n",
"494it [00:00, 2452.09it/s]\u001b[A\n",
"943it [00:00, 2484.84it/s]\u001b[A\n",
" 25%|█████████████████████ | 2/8 [00:49<02:28, 24.72s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"159it [00:00, 1578.44it/s]\u001b[A\n",
"413it [00:00, 1777.94it/s]\u001b[A\n",
"584it [00:00, 1756.96it/s]\u001b[A\n",
"712it [00:00, 1389.14it/s]\u001b[A\n",
"943it [00:00, 1570.48it/s]\u001b[A\n",
" 38%|███████████████████████████████▌ | 3/8 [01:15<02:04, 24.87s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"229it [00:00, 2273.39it/s]\u001b[A\n",
"544it [00:00, 2476.21it/s]\u001b[A\n",
"943it [00:00, 2626.45it/s]\u001b[A\n",
" 50%|██████████████████████████████████████████ | 4/8 [01:39<01:38, 24.58s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"232it [00:00, 2303.19it/s]\u001b[A\n",
"472it [00:00, 2244.92it/s]\u001b[A\n",
"618it [00:00, 1927.54it/s]\u001b[A\n",
"943it [00:00, 2102.99it/s]\u001b[A\n",
" 62%|████████████████████████████████████████████████████▌ | 5/8 [02:02<01:12, 24.22s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"187it [00:00, 1856.41it/s]\u001b[A\n",
"347it [00:00, 1766.98it/s]\u001b[A\n",
"473it [00:00, 1572.31it/s]\u001b[A\n",
"633it [00:00, 1577.13it/s]\u001b[A\n",
"943it [00:00, 1719.13it/s]\u001b[A\n",
" 75%|███████████████████████████████████████████████████████████████ | 6/8 [02:24<00:47, 23.62s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"268it [00:00, 2660.58it/s]\u001b[A\n",
"534it [00:00, 2658.40it/s]\u001b[A\n",
"943it [00:00, 2583.15it/s]\u001b[A\n",
" 88%|█████████████████████████████████████████████████████████████████████████▌ | 7/8 [02:49<00:23, 23.99s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"167it [00:00, 1657.84it/s]\u001b[A\n",
"276it [00:00, 1413.02it/s]\u001b[A\n",
"368it [00:00, 1213.79it/s]\u001b[A\n",
"489it [00:00, 1206.38it/s]\u001b[A\n",
"672it [00:00, 1342.97it/s]\u001b[A\n",
"943it [00:00, 1444.56it/s]\u001b[A\n",
"100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [03:13<00:00, 24.16s/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>Alpha</th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>HR2</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.2</td>\n",
" <td>268.177832</td>\n",
" <td>211.732649</td>\n",
" <td>0.262672</td>\n",
" <td>0.166858</td>\n",
" <td>0.166277</td>\n",
" <td>0.197184</td>\n",
" <td>0.187661</td>\n",
" <td>0.203252</td>\n",
" <td>0.320910</td>\n",
" <td>0.196132</td>\n",
" <td>0.563378</td>\n",
" <td>0.580866</td>\n",
" <td>0.850477</td>\n",
" <td>0.629905</td>\n",
" <td>1.000000</td>\n",
" <td>0.060606</td>\n",
" <td>3.669627</td>\n",
" <td>0.979636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.4</td>\n",
" <td>10.546689</td>\n",
" <td>7.792373</td>\n",
" <td>0.268505</td>\n",
" <td>0.172669</td>\n",
" <td>0.171569</td>\n",
" <td>0.202643</td>\n",
" <td>0.192489</td>\n",
" <td>0.212653</td>\n",
" <td>0.326760</td>\n",
" <td>0.200172</td>\n",
" <td>0.565148</td>\n",
" <td>0.583801</td>\n",
" <td>0.854719</td>\n",
" <td>0.644751</td>\n",
" <td>1.000000</td>\n",
" <td>0.064214</td>\n",
" <td>3.726996</td>\n",
" <td>0.978426</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.6</td>\n",
" <td>3.143988</td>\n",
" <td>2.948790</td>\n",
" <td>0.274655</td>\n",
" <td>0.180502</td>\n",
" <td>0.177820</td>\n",
" <td>0.208730</td>\n",
" <td>0.198176</td>\n",
" <td>0.222746</td>\n",
" <td>0.332872</td>\n",
" <td>0.203290</td>\n",
" <td>0.568872</td>\n",
" <td>0.587738</td>\n",
" <td>0.870626</td>\n",
" <td>0.657476</td>\n",
" <td>1.000000</td>\n",
" <td>0.065657</td>\n",
" <td>3.785282</td>\n",
" <td>0.977090</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.8</td>\n",
" <td>3.670728</td>\n",
" <td>3.495735</td>\n",
" <td>0.281972</td>\n",
" <td>0.189868</td>\n",
" <td>0.185300</td>\n",
" <td>0.216071</td>\n",
" <td>0.203541</td>\n",
" <td>0.236751</td>\n",
" <td>0.339867</td>\n",
" <td>0.206688</td>\n",
" <td>0.573729</td>\n",
" <td>0.592432</td>\n",
" <td>0.874867</td>\n",
" <td>0.685048</td>\n",
" <td>1.000000</td>\n",
" <td>0.070707</td>\n",
" <td>3.832415</td>\n",
" <td>0.975998</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.216980</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>0.685048</td>\n",
" <td>1.000000</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.2</td>\n",
" <td>3.704441</td>\n",
" <td>3.529251</td>\n",
" <td>0.280912</td>\n",
" <td>0.193633</td>\n",
" <td>0.187311</td>\n",
" <td>0.216872</td>\n",
" <td>0.203004</td>\n",
" <td>0.240588</td>\n",
" <td>0.338049</td>\n",
" <td>0.203453</td>\n",
" <td>0.571830</td>\n",
" <td>0.594313</td>\n",
" <td>0.883351</td>\n",
" <td>0.681866</td>\n",
" <td>1.000000</td>\n",
" <td>0.085859</td>\n",
" <td>3.910718</td>\n",
" <td>0.974073</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.4</td>\n",
" <td>3.704580</td>\n",
" <td>3.529388</td>\n",
" <td>0.273595</td>\n",
" <td>0.190651</td>\n",
" <td>0.183874</td>\n",
" <td>0.212183</td>\n",
" <td>0.199464</td>\n",
" <td>0.239118</td>\n",
" <td>0.329550</td>\n",
" <td>0.195433</td>\n",
" <td>0.566171</td>\n",
" <td>0.592793</td>\n",
" <td>0.871686</td>\n",
" <td>0.675504</td>\n",
" <td>1.000000</td>\n",
" <td>0.107504</td>\n",
" <td>3.961915</td>\n",
" <td>0.972674</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.6</td>\n",
" <td>3.704591</td>\n",
" <td>3.529399</td>\n",
" <td>0.263097</td>\n",
" <td>0.186255</td>\n",
" <td>0.178709</td>\n",
" <td>0.205170</td>\n",
" <td>0.191094</td>\n",
" <td>0.232920</td>\n",
" <td>0.317439</td>\n",
" <td>0.184917</td>\n",
" <td>0.552349</td>\n",
" <td>0.590545</td>\n",
" <td>0.868505</td>\n",
" <td>0.669141</td>\n",
" <td>0.999576</td>\n",
" <td>0.156566</td>\n",
" <td>4.060156</td>\n",
" <td>0.969203</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Alpha RMSE MAE precision recall F_1 F_05 \\\n",
"0 0.2 268.177832 211.732649 0.262672 0.166858 0.166277 0.197184 \n",
"0 0.4 10.546689 7.792373 0.268505 0.172669 0.171569 0.202643 \n",
"0 0.6 3.143988 2.948790 0.274655 0.180502 0.177820 0.208730 \n",
"0 0.8 3.670728 3.495735 0.281972 0.189868 0.185300 0.216071 \n",
"0 1.0 3.702446 3.527273 0.282185 0.192092 0.186749 0.216980 \n",
"0 1.2 3.704441 3.529251 0.280912 0.193633 0.187311 0.216872 \n",
"0 1.4 3.704580 3.529388 0.273595 0.190651 0.183874 0.212183 \n",
"0 1.6 3.704591 3.529399 0.263097 0.186255 0.178709 0.205170 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.187661 0.203252 0.320910 0.196132 0.563378 0.580866 \n",
"0 0.192489 0.212653 0.326760 0.200172 0.565148 0.583801 \n",
"0 0.198176 0.222746 0.332872 0.203290 0.568872 0.587738 \n",
"0 0.203541 0.236751 0.339867 0.206688 0.573729 0.592432 \n",
"0 0.204185 0.240096 0.339114 0.204905 0.572157 0.593544 \n",
"0 0.203004 0.240588 0.338049 0.203453 0.571830 0.594313 \n",
"0 0.199464 0.239118 0.329550 0.195433 0.566171 0.592793 \n",
"0 0.191094 0.232920 0.317439 0.184917 0.552349 0.590545 \n",
"\n",
" HR HR2 Reco in test Test coverage Shannon Gini \n",
"0 0.850477 0.629905 1.000000 0.060606 3.669627 0.979636 \n",
"0 0.854719 0.644751 1.000000 0.064214 3.726996 0.978426 \n",
"0 0.870626 0.657476 1.000000 0.065657 3.785282 0.977090 \n",
"0 0.874867 0.685048 1.000000 0.070707 3.832415 0.975998 \n",
"0 0.875928 0.685048 1.000000 0.077201 3.875892 0.974947 \n",
"0 0.883351 0.681866 1.000000 0.085859 3.910718 0.974073 \n",
"0 0.871686 0.675504 1.000000 0.107504 3.961915 0.972674 \n",
"0 0.868505 0.669141 0.999576 0.156566 4.060156 0.969203 "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tqdm import tqdm\n",
"result=[]\n",
"for alpha in tqdm([round(i,1) for i in np.arange(0.2,1.6001,0.2)]):\n",
" model=RP3Beta()\n",
" model.fit(train_ui, alpha=alpha, beta=0)\n",
" reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
" estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=np.array(reco),\n",
" super_reactions=[4,5])\n",
" to_append.insert(0, \"Alpha\", alpha)\n",
" result.append(to_append)\n",
" \n",
"result=pd.concat(result)\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCQAAAkoCAYAAACzg26yAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzde3xV5Zn3/8+Vc3Y47hAgIYmgAnJKsEXE8wFRsATaPj3gWB9H7c+xoz3Yzkx1ptP2aevzTM+dzuj05bQzOlOLh9p2iPXsiNXxiEoiCCgIhJAAIZwh5Hj9/tgruAnhFJK9kr2/79drv9jrXmvtfS1eeLv2te77us3dERERERERERFJpLSwAxARERERERGR1KOEhIiIiIiIiIgknBISIiIiIiIiIpJwSkiIiIiIiIiISMIpISEiIiIiIiIiCaeEhIiIiIiIiIgknBISIiIiIiIicoiZ/cLM/v4EjltpZpcmICRJUkpISNIxsw1m1mRm+8xsi5ndZ2aDgn33mZmb2YIu5/wsaP/zYDvLzH5sZrXB56w3s58e5Ts6X/+c0AsVERlAgn6zxcxGdGlfHvS/Y+Pavh20zexy7J+bWXuXvnefmRUl5ipERFKDu9/i7t89geOmuPvSBIQkSUoJCUlWFe4+CJgOnA3cGbfvPeD6zg0zywA+DayLO+ZOYAYwExgMXAa83d13xL1u6/3LEBFJKuuBazo3zGwakBt/gJkZcB2wg7i+Os4rXfreQe5e15dBi4gMRME9rki/poSEJDV33wI8RSwx0akSuMDMhgfbc4FqYEvcMecAv3f3Oo/Z4O7/kZCgRUSS138C/ztu+3qga996EVAEfBlYZGZZCYpNRGRACEac3Wlm75rZTjP7dzPLMbNLg9G9XzezLcC/m1mamd1hZuvMrNHMHjazaNxnXWhmL5vZLjPbFDda+D4z+17wfoSZPRYcs8PMXjSztLhYr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D9B/D3Xdp3uPtzR5kD1wT8mNjKG9uBW4H/5e4fxB1TaWb74l6/76NLEBFJKu6+zt2XdWm+CFju7k+7+5bOF7HkcZmZTQ2OO69L37vPzM5J6AWIiITvN8DTwAfB63tHOe4fiRVzfzqor/YqcC6Au9cQG632NWJLLS8nlgjuajzwLLGaD68A97j70m6O+x6x2mvVwDvAW8eISwQA6/63mIiIiIiIiPQ3ZrYB+Ly7Pxt2LCKnSiMkRERERERERCThlJAQERERERERkYTTlA0RERERERERSTiNkBARERERERGRhFNCQkREREREREQSLiPsAHrDiBEjfOzYsWGHISJyhDfffHO7uxeEHUciqC8Wkf5I/bCISPiO1hcnRUJi7NixLFvWdTlzEZHwmdnGsGNIFPXFItIfqR8WEQnf0fpiTdkQERERERERkYRTQkJEREREREREEk4JCRERERERERFJuKSoISEi/UNrayu1tbUcPHgw7FASLicnh+LiYjIzM8MORUTkCKnQP6sfFpHekAr9ZV862b5YCQkR6TW1tbUMHjyYsWPHYmZhh5Mw7k5jYyO1tbWMGzcu7HBERI6Q7P1zovphM5sL/COQDvzS3f+hy/5rga8Hm/uAL7h7VbDvduDzgAPvADe4+0Ez+yFQAbQA64L2XWY2FlgFrAk+71V3v6XPLk5EgOTvL/tST/piTdkQkV5z8OBB8vPzU67zNjPy8/OVSReRfivZ++dE9MNmlg7cDcwDJgPXmNnkLoetBy5x9zLgu8C9wbljgC8BM9x9KrGExqLgnGeAqcE57wF3xn3eOnefHryUjBBJgGTvL/tST/piJSREpFelauedqtctIgNHsvdTCbi+mcBad//A3VuAB4GF8Qe4+8vuvjPYfBUojtudAeSaWQYQAeqCc55297ajnCMiIUj2/rIvnezfnRISIpJU0tPTmT59OlOnTqWiooJdu3YBsGHDBsyMv//7vz907Pbt28nMzOS2224DYM2aNVx66aVMnz6dSZMmcfPNNwOwdOlShg4dyvTp0w+9nn322cRfnIjIAGZmXHfddYe229raKCgoYP78+Ycdt3DhQs4777zD2r797W8zZsyYw/rhzv49gcYAm+K2a4O2o7kJeALA3TcDPwJqgHpgt7s/3c05N3aeExhnZm+b2QtmdtGpBC8iqWvZsmV86UtfOur+uro6PvWpTyUwog8pISEiSSU3N5fly5ezYsUKotEod99996F9p59+Oo899tih7UceeYQpU6Yc2v7Sl77E7bffzvLly1m1ahVf/OIXD+276KKLWL58+aHXFVdckZgLEhFJEnl5eaxYsYKmpiYAnnnmGcaMOfz3/K5du3jrrbfYtWsX69evP2xfZ//c+Ro2bFjCYg9099jPuz3Q7DJiCYmvB9vDiY2mGAcUAXlm9rku5/wd0AY8EDTVA6XufjbwVeA3Zjakm++62cyWmdmyhoaGHl2YiAws7e3tJ3X8jBkz+PnPf37U/UVFRfz2t7891bB6RAkJEUla5513Hps3bz60nZuby6RJk1i2bBkADz30EJ/5zGcO7a+vr6e4+MORstOmTUtcsCIiKWDevHn88Y9/BGDx4sVcc801h+1/9NFHqaioYNGiRTz44INhhHgstUBJ3HYxwbSLeGZWBvwSWOjujUHzFcB6d29w91bgd8D5cedcD8wHrnV3B3D35s7z3f1NYgUvJ3T9Pne/191nuPuMgoKCXrhMEQnThg0bOOuss7j++uspKyvjU5/6FAcOHGDs2LF85zvf4cILL+SRRx7h6aef5rzzzuMjH/kIn/70p9m3bx8Ab7zxBueffz7l5eXMnDmTvXv3snTp0kOj0V544YVDI83OPvts9u7dy4YNG5g6dSoQq6Fxww03MG3aNM4++2yef/55AO677z4++clPMnfuXMaPH8/f/M3f9Mr1apUNEekT/6dyJe/W7enVz5xcNIRvVUw5/oHEMsfPPfccN91002HtnTe5o0ePJj09naKiIurqYve
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"metrics=list(result.columns[[i not in ['Alpha'] for i in result.columns]])\n",
"\n",
"charts_per_row=6\n",
"charts_per_column=3\n",
"\n",
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
"import itertools\n",
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
"\n",
"for i in range(len(metrics)):\n",
" df=result[['Alpha', metrics[i]]]\n",
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Beta"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/10 [00:00<?, ?it/s]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"289it [00:00, 2869.05it/s]\u001b[A\n",
"943it [00:00, 3796.57it/s]\u001b[A\n",
" 10%|████████▎ | 1/10 [00:13<02:03, 13.71s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"462it [00:00, 4605.96it/s]\u001b[A\n",
"943it [00:00, 3601.05it/s]\u001b[A\n",
" 20%|████████████████▌ | 2/10 [00:35<02:09, 16.14s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 5872.90it/s]\u001b[A\n",
" 30%|████████████████████████▉ | 3/10 [00:50<01:50, 15.73s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"351it [00:00, 3484.49it/s]\u001b[A\n",
"943it [00:00, 3341.08it/s]\u001b[A\n",
" 40%|█████████████████████████████████▏ | 4/10 [01:05<01:33, 15.65s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"485it [00:00, 4812.21it/s]\u001b[A\n",
"943it [00:00, 4202.34it/s]\u001b[A\n",
" 50%|█████████████████████████████████████████▌ | 5/10 [01:23<01:21, 16.34s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 4873.77it/s]\u001b[A\n",
" 60%|█████████████████████████████████████████████████▊ | 6/10 [01:38<01:04, 16.00s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"258it [00:00, 2561.22it/s]\u001b[A\n",
"555it [00:00, 2666.26it/s]\u001b[A\n",
"943it [00:00, 2693.80it/s]\u001b[A\n",
" 70%|██████████████████████████████████████████████████████████ | 7/10 [01:57<00:50, 16.73s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 5416.39it/s]\u001b[A\n",
" 80%|██████████████████████████████████████████████████████████████████▍ | 8/10 [02:17<00:35, 17.72s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"158it [00:00, 1568.57it/s]\u001b[A\n",
"295it [00:00, 1499.58it/s]\u001b[A\n",
"943it [00:00, 2565.22it/s]\u001b[A\n",
" 90%|██████████████████████████████████████████████████████████████████████████▋ | 9/10 [02:33<00:17, 17.21s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"262it [00:00, 2600.87it/s]\u001b[A\n",
"572it [00:00, 2728.34it/s]\u001b[A\n",
"943it [00:00, 2883.56it/s]\u001b[A\n",
"100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [02:51<00:00, 17.16s/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>Beta</th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>HR2</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.216980</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>0.685048</td>\n",
" <td>1.000000</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.1</td>\n",
" <td>3.703312</td>\n",
" <td>3.528128</td>\n",
" <td>0.290138</td>\n",
" <td>0.197597</td>\n",
" <td>0.192259</td>\n",
" <td>0.223336</td>\n",
" <td>0.210944</td>\n",
" <td>0.246153</td>\n",
" <td>0.347768</td>\n",
" <td>0.212034</td>\n",
" <td>0.581038</td>\n",
" <td>0.596328</td>\n",
" <td>0.884411</td>\n",
" <td>0.695652</td>\n",
" <td>1.000000</td>\n",
" <td>0.085137</td>\n",
" <td>3.957416</td>\n",
" <td>0.972784</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.2</td>\n",
" <td>3.703825</td>\n",
" <td>3.528636</td>\n",
" <td>0.297137</td>\n",
" <td>0.201202</td>\n",
" <td>0.196067</td>\n",
" <td>0.228169</td>\n",
" <td>0.218026</td>\n",
" <td>0.252767</td>\n",
" <td>0.355655</td>\n",
" <td>0.219909</td>\n",
" <td>0.588904</td>\n",
" <td>0.598160</td>\n",
" <td>0.886532</td>\n",
" <td>0.697773</td>\n",
" <td>1.000000</td>\n",
" <td>0.094517</td>\n",
" <td>4.053212</td>\n",
" <td>0.969980</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.3</td>\n",
" <td>3.704130</td>\n",
" <td>3.528939</td>\n",
" <td>0.303499</td>\n",
" <td>0.204749</td>\n",
" <td>0.199901</td>\n",
" <td>0.232829</td>\n",
" <td>0.225107</td>\n",
" <td>0.260797</td>\n",
" <td>0.363757</td>\n",
" <td>0.226825</td>\n",
" <td>0.599969</td>\n",
" <td>0.599964</td>\n",
" <td>0.888653</td>\n",
" <td>0.707317</td>\n",
" <td>1.000000</td>\n",
" <td>0.105339</td>\n",
" <td>4.147779</td>\n",
" <td>0.966948</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.4</td>\n",
" <td>3.704313</td>\n",
" <td>3.529120</td>\n",
" <td>0.308908</td>\n",
" <td>0.208811</td>\n",
" <td>0.203854</td>\n",
" <td>0.237241</td>\n",
" <td>0.229614</td>\n",
" <td>0.266918</td>\n",
" <td>0.370758</td>\n",
" <td>0.232673</td>\n",
" <td>0.609385</td>\n",
" <td>0.602014</td>\n",
" <td>0.895016</td>\n",
" <td>0.718982</td>\n",
" <td>0.999894</td>\n",
" <td>0.132035</td>\n",
" <td>4.259682</td>\n",
" <td>0.962989</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.5</td>\n",
" <td>3.704422</td>\n",
" <td>3.529229</td>\n",
" <td>0.314316</td>\n",
" <td>0.211411</td>\n",
" <td>0.206768</td>\n",
" <td>0.240986</td>\n",
" <td>0.237124</td>\n",
" <td>0.273416</td>\n",
" <td>0.378307</td>\n",
" <td>0.239297</td>\n",
" <td>0.622792</td>\n",
" <td>0.603327</td>\n",
" <td>0.903499</td>\n",
" <td>0.724284</td>\n",
" <td>0.999046</td>\n",
" <td>0.168831</td>\n",
" <td>4.411281</td>\n",
" <td>0.956648</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.6</td>\n",
" <td>3.704488</td>\n",
" <td>3.529295</td>\n",
" <td>0.314634</td>\n",
" <td>0.206209</td>\n",
" <td>0.204818</td>\n",
" <td>0.240159</td>\n",
" <td>0.242489</td>\n",
" <td>0.273850</td>\n",
" <td>0.376438</td>\n",
" <td>0.238428</td>\n",
" <td>0.622042</td>\n",
" <td>0.600721</td>\n",
" <td>0.897137</td>\n",
" <td>0.720042</td>\n",
" <td>0.996394</td>\n",
" <td>0.212843</td>\n",
" <td>4.621938</td>\n",
" <td>0.945932</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.7</td>\n",
" <td>3.704528</td>\n",
" <td>3.529335</td>\n",
" <td>0.304136</td>\n",
" <td>0.187298</td>\n",
" <td>0.191990</td>\n",
" <td>0.228749</td>\n",
" <td>0.238305</td>\n",
" <td>0.256201</td>\n",
" <td>0.358807</td>\n",
" <td>0.226808</td>\n",
" <td>0.593897</td>\n",
" <td>0.591207</td>\n",
" <td>0.868505</td>\n",
" <td>0.693531</td>\n",
" <td>0.983033</td>\n",
" <td>0.256854</td>\n",
" <td>4.898568</td>\n",
" <td>0.928065</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.8</td>\n",
" <td>3.704552</td>\n",
" <td>3.529360</td>\n",
" <td>0.266384</td>\n",
" <td>0.147571</td>\n",
" <td>0.158660</td>\n",
" <td>0.194838</td>\n",
" <td>0.214485</td>\n",
" <td>0.209336</td>\n",
" <td>0.299850</td>\n",
" <td>0.184356</td>\n",
" <td>0.492852</td>\n",
" <td>0.571152</td>\n",
" <td>0.803818</td>\n",
" <td>0.604454</td>\n",
" <td>0.936373</td>\n",
" <td>0.341270</td>\n",
" <td>5.257397</td>\n",
" <td>0.895882</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.9</td>\n",
" <td>3.704567</td>\n",
" <td>3.529375</td>\n",
" <td>0.162354</td>\n",
" <td>0.076967</td>\n",
" <td>0.089233</td>\n",
" <td>0.114583</td>\n",
" <td>0.134657</td>\n",
" <td>0.113253</td>\n",
" <td>0.160868</td>\n",
" <td>0.085486</td>\n",
" <td>0.243590</td>\n",
" <td>0.535405</td>\n",
" <td>0.580064</td>\n",
" <td>0.400848</td>\n",
" <td>0.800106</td>\n",
" <td>0.415584</td>\n",
" <td>5.563910</td>\n",
" <td>0.857396</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Beta RMSE MAE precision recall F_1 F_05 \\\n",
"0 0.0 3.702446 3.527273 0.282185 0.192092 0.186749 0.216980 \n",
"0 0.1 3.703312 3.528128 0.290138 0.197597 0.192259 0.223336 \n",
"0 0.2 3.703825 3.528636 0.297137 0.201202 0.196067 0.228169 \n",
"0 0.3 3.704130 3.528939 0.303499 0.204749 0.199901 0.232829 \n",
"0 0.4 3.704313 3.529120 0.308908 0.208811 0.203854 0.237241 \n",
"0 0.5 3.704422 3.529229 0.314316 0.211411 0.206768 0.240986 \n",
"0 0.6 3.704488 3.529295 0.314634 0.206209 0.204818 0.240159 \n",
"0 0.7 3.704528 3.529335 0.304136 0.187298 0.191990 0.228749 \n",
"0 0.8 3.704552 3.529360 0.266384 0.147571 0.158660 0.194838 \n",
"0 0.9 3.704567 3.529375 0.162354 0.076967 0.089233 0.114583 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.204185 0.240096 0.339114 0.204905 0.572157 0.593544 \n",
"0 0.210944 0.246153 0.347768 0.212034 0.581038 0.596328 \n",
"0 0.218026 0.252767 0.355655 0.219909 0.588904 0.598160 \n",
"0 0.225107 0.260797 0.363757 0.226825 0.599969 0.599964 \n",
"0 0.229614 0.266918 0.370758 0.232673 0.609385 0.602014 \n",
"0 0.237124 0.273416 0.378307 0.239297 0.622792 0.603327 \n",
"0 0.242489 0.273850 0.376438 0.238428 0.622042 0.600721 \n",
"0 0.238305 0.256201 0.358807 0.226808 0.593897 0.591207 \n",
"0 0.214485 0.209336 0.299850 0.184356 0.492852 0.571152 \n",
"0 0.134657 0.113253 0.160868 0.085486 0.243590 0.535405 \n",
"\n",
" HR HR2 Reco in test Test coverage Shannon Gini \n",
"0 0.875928 0.685048 1.000000 0.077201 3.875892 0.974947 \n",
"0 0.884411 0.695652 1.000000 0.085137 3.957416 0.972784 \n",
"0 0.886532 0.697773 1.000000 0.094517 4.053212 0.969980 \n",
"0 0.888653 0.707317 1.000000 0.105339 4.147779 0.966948 \n",
"0 0.895016 0.718982 0.999894 0.132035 4.259682 0.962989 \n",
"0 0.903499 0.724284 0.999046 0.168831 4.411281 0.956648 \n",
"0 0.897137 0.720042 0.996394 0.212843 4.621938 0.945932 \n",
"0 0.868505 0.693531 0.983033 0.256854 4.898568 0.928065 \n",
"0 0.803818 0.604454 0.936373 0.341270 5.257397 0.895882 \n",
"0 0.580064 0.400848 0.800106 0.415584 5.563910 0.857396 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tqdm import tqdm\n",
"result=[]\n",
"for beta in tqdm([round(i,1) for i in np.arange(0,1,0.1)]):\n",
" model=RP3Beta()\n",
" model.fit(train_ui, alpha=1, beta=beta)\n",
" reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
" estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=np.array(reco),\n",
" super_reactions=[4,5])\n",
" to_append.insert(0, \"Beta\", beta)\n",
" result.append(to_append)\n",
" \n",
"result=pd.concat(result)\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCQAAAkoCAYAAACzg26yAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzdd3yW1f3/8dfJHmSQEEIGSRhhhBWUKSAqQ1QUq6BQnFit1km1rbZardVfa9229muptVhFwL0HoKKgsoSwwpARQkgIEMgiOzm/P+47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o6tq3skIiINBAcHs2HDBkpLSwFYuHAhcXFHFrnPz89n9erV5Ofns3PnziPaasfi2ld4eLjHYhcRERFpqLq6+oT6Dxo0iGeeeeao7bGxsbz++usnG9ZPooSEhwwfPpw9e/bUHQcGBtK7d29WrVoFwPz587nsssvq2nNycoiPj6877tevn+eCFRFpZc477zw++OADAObOncu0adOOaH/jjTe48MILmTp1KvPmzXMiRBEREREyMjLo1asXV199Nf3792fy5MmUlJSQlJTEgw8+yMiRI3nttddYsGABw4cP57TTTmPKlCkUFxcDsHLlSs444wwGDBjAkCFDKCoqYvHixXUzQ7/44ou6WZ8DBw6kqKiIjIwM+vbtC7hqaFx77bX069ePgQMH8vnnnwMwe/ZsLrnkEiZMmEBycjK//e1vT8n9tuoaErX
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"### import matplotlib.pyplot as plt\n",
"\n",
"metrics=list(result.columns[[i not in ['Beta'] for i in result.columns]])\n",
"\n",
"charts_per_row=6\n",
"charts_per_column=3\n",
"\n",
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
"import itertools\n",
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
"\n",
"for i in range(len(metrics)):\n",
" df=result[['Beta', metrics[i]]]\n",
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Check sample recommendations"
]
},
{
"cell_type": "code",
"execution_count": 10,
"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>user</th>\n",
" <th>rating</th>\n",
" <th>title</th>\n",
" <th>genres</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Toy Story (1995)</td>\n",
" <td>Animation, Children's, Comedy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22169</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Groundhog Day (1993)</td>\n",
" <td>Comedy, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41229</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Star Trek: Generations (1994)</td>\n",
" <td>Action, Adventure, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40846</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Miracle on 34th Street (1994)</td>\n",
" <td>Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38062</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Beauty and the Beast (1991)</td>\n",
" <td>Animation, Children's, Musical</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37534</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Aladdin (1992)</td>\n",
" <td>Animation, Children's, Comedy, Musical</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36306</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Silence of the Lambs, The (1991)</td>\n",
" <td>Drama, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33862</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Independence Day (ID4) (1996)</td>\n",
" <td>Action, Sci-Fi, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32487</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Phenomenon (1996)</td>\n",
" <td>Drama, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32420</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Spawn (1997)</td>\n",
" <td>Action, Adventure, Sci-Fi, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31448</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Seven (Se7en) (1995)</td>\n",
" <td>Crime, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30214</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Star Trek: First Contact (1996)</td>\n",
" <td>Action, Adventure, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27813</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Day the Earth Stood Still, The (1951)</td>\n",
" <td>Drama, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27483</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Young Frankenstein (1974)</td>\n",
" <td>Comedy, Horror</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27366</th>\n",
" <td>200</td>\n",
" <td>5</td>\n",
" <td>Empire Strikes Back, The (1980)</td>\n",
" <td>Action, Adventure, Drama, Romance, Sci-Fi, War</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user rating title \\\n",
"82 200 5 Toy Story (1995) \n",
"22169 200 5 Groundhog Day (1993) \n",
"41229 200 5 Star Trek: Generations (1994) \n",
"40846 200 5 Miracle on 34th Street (1994) \n",
"38062 200 5 Beauty and the Beast (1991) \n",
"37534 200 5 Aladdin (1992) \n",
"36306 200 5 Silence of the Lambs, The (1991) \n",
"33862 200 5 Independence Day (ID4) (1996) \n",
"32487 200 5 Phenomenon (1996) \n",
"32420 200 5 Spawn (1997) \n",
"31448 200 5 Seven (Se7en) (1995) \n",
"30214 200 5 Star Trek: First Contact (1996) \n",
"27813 200 5 Day the Earth Stood Still, The (1951) \n",
"27483 200 5 Young Frankenstein (1974) \n",
"27366 200 5 Empire Strikes Back, The (1980) \n",
"\n",
" genres \n",
"82 Animation, Children's, Comedy \n",
"22169 Comedy, Romance \n",
"41229 Action, Adventure, Sci-Fi \n",
"40846 Drama \n",
"38062 Animation, Children's, Musical \n",
"37534 Animation, Children's, Comedy, Musical \n",
"36306 Drama, Thriller \n",
"33862 Action, Sci-Fi, War \n",
"32487 Drama, Romance \n",
"32420 Action, Adventure, Sci-Fi, Thriller \n",
"31448 Crime, Thriller \n",
"30214 Action, Adventure, Sci-Fi \n",
"27813 Drama, Sci-Fi \n",
"27483 Comedy, Horror \n",
"27366 Action, Adventure, Drama, Romance, Sci-Fi, War "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>user</th>\n",
" <th>rec_nb</th>\n",
" <th>title</th>\n",
" <th>genres</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2710</th>\n",
" <td>200.0</td>\n",
" <td>1</td>\n",
" <td>Return of the Jedi (1983)</td>\n",
" <td>Action, Adventure, Romance, Sci-Fi, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7001</th>\n",
" <td>200.0</td>\n",
" <td>2</td>\n",
" <td>Fargo (1996)</td>\n",
" <td>Crime, Drama, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2272</th>\n",
" <td>200.0</td>\n",
" <td>3</td>\n",
" <td>Godfather, The (1972)</td>\n",
" <td>Action, Crime, Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6393</th>\n",
" <td>200.0</td>\n",
" <td>4</td>\n",
" <td>Pulp Fiction (1994)</td>\n",
" <td>Crime, Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7714</th>\n",
" <td>200.0</td>\n",
" <td>5</td>\n",
" <td>Princess Bride, The (1987)</td>\n",
" <td>Action, Adventure, Comedy, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3434</th>\n",
" <td>200.0</td>\n",
" <td>6</td>\n",
" <td>Jerry Maguire (1996)</td>\n",
" <td>Drama, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9101</th>\n",
" <td>200.0</td>\n",
" <td>7</td>\n",
" <td>Mission: Impossible (1996)</td>\n",
" <td>Action, Adventure, Mystery</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4491</th>\n",
" <td>200.0</td>\n",
" <td>8</td>\n",
" <td>Air Force One (1997)</td>\n",
" <td>Action, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2026</th>\n",
" <td>200.0</td>\n",
" <td>9</td>\n",
" <td>Back to the Future (1985)</td>\n",
" <td>Comedy, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8048</th>\n",
" <td>200.0</td>\n",
" <td>10</td>\n",
" <td>Monty Python and the Holy Grail (1974)</td>\n",
" <td>Comedy</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user rec_nb title \\\n",
"2710 200.0 1 Return of the Jedi (1983) \n",
"7001 200.0 2 Fargo (1996) \n",
"2272 200.0 3 Godfather, The (1972) \n",
"6393 200.0 4 Pulp Fiction (1994) \n",
"7714 200.0 5 Princess Bride, The (1987) \n",
"3434 200.0 6 Jerry Maguire (1996) \n",
"9101 200.0 7 Mission: Impossible (1996) \n",
"4491 200.0 8 Air Force One (1997) \n",
"2026 200.0 9 Back to the Future (1985) \n",
"8048 200.0 10 Monty Python and the Holy Grail (1974) \n",
"\n",
" genres \n",
"2710 Action, Adventure, Romance, Sci-Fi, War \n",
"7001 Crime, Drama, Thriller \n",
"2272 Action, Crime, Drama \n",
"6393 Crime, Drama \n",
"7714 Action, Adventure, Comedy, Romance \n",
"3434 Drama, Romance \n",
"9101 Action, Adventure, Mystery \n",
"4491 Action, Thriller \n",
"2026 Comedy, Sci-Fi \n",
"8048 Comedy "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train=pd.read_csv('./Datasets/ml-100k/train.csv', sep='\\t', header=None, names=['user', 'item', 'rating', 'timestamp'])\n",
"items=pd.read_csv('./Datasets/ml-100k/movies.csv')\n",
"\n",
"user=random.choice(list(set(train['user'])))\n",
"\n",
"train_content=pd.merge(train, items, left_on='item', right_on='id')\n",
"display(train_content[train_content['user']==user][['user', 'rating', 'title', 'genres']]\\\n",
" .sort_values(by='rating', ascending=False)[:15])\n",
"\n",
"reco = np.loadtxt('Recommendations generated/ml-100k/Self_P3_reco.csv', delimiter=',')\n",
"items=pd.read_csv('./Datasets/ml-100k/movies.csv')\n",
"\n",
"# Let's ignore scores - they are not used in evaluation: \n",
"reco_users=reco[:,:1]\n",
"reco_items=reco[:,1::2]\n",
"# Let's put them into one array\n",
"reco=np.concatenate((reco_users, reco_items), axis=1)\n",
"\n",
"# Let's rebuild it user-item dataframe\n",
"recommended=[]\n",
"for row in reco:\n",
" for rec_nb, entry in enumerate(row[1:]):\n",
" recommended.append((row[0], rec_nb+1, entry))\n",
"recommended=pd.DataFrame(recommended, columns=['user','rec_nb', 'item'])\n",
"\n",
"recommended_content=pd.merge(recommended, items, left_on='item', right_on='id')\n",
"recommended_content[recommended_content['user']==user][['user', 'rec_nb', 'title', 'genres']].sort_values(by='rec_nb')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# project task 6: generate recommendations of RP3Beta for hiperparameters found to optimize recall"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# use better values than (1,0) for alpha and beta\n",
"# if you want you can also modify the model to consider different weights (we took as weights user ratings, maybe take ones or squares of ratings instead)\n",
"# save the outptut in 'Recommendations generated/ml-100k/Self_RP3Beta_estimations.csv'\n",
"# and 'Recommendations generated/ml-100k/Self_RP3Beta_reco.csv'"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"model=RP3Beta()\n",
"model.fit(train_ui, alpha=1.2, beta=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"top_n=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
"\n",
"top_n.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_reco.csv', index=False, header=False)\n",
"\n",
"estimations=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
"estimations.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_estimations.csv', index=False, header=False)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"943it [00:00, 3493.16it/s]\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>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>HR2</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.70458</td>\n",
" <td>3.529388</td>\n",
" <td>0.302969</td>\n",
" <td>0.199894</td>\n",
" <td>0.197705</td>\n",
" <td>0.231449</td>\n",
" <td>0.231438</td>\n",
" <td>0.263787</td>\n",
" <td>0.362426</td>\n",
" <td>0.226406</td>\n",
" <td>0.601293</td>\n",
" <td>0.597526</td>\n",
" <td>0.889714</td>\n",
" <td>0.700954</td>\n",
" <td>0.996819</td>\n",
" <td>0.212121</td>\n",
" <td>4.509878</td>\n",
" <td>0.951344</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision recall F_1 F_05 \\\n",
"0 3.70458 3.529388 0.302969 0.199894 0.197705 0.231449 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.231438 0.263787 0.362426 0.226406 0.601293 0.597526 \n",
"\n",
" HR HR2 Reco in test Test coverage Shannon Gini \n",
"0 0.889714 0.700954 0.996819 0.212121 4.509878 0.951344 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import evaluation_measures as ev\n",
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Self_RP3Beta_estimations.csv', header=None)\n",
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_RP3Beta_reco.csv', delimiter=',')\n",
"\n",
"ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=reco,\n",
" super_reactions=[4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# project task 7 (optional): implement graph-based model of your choice "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# for example change length of paths in RP3beta\n",
"# save the outptut in 'Recommendations generated/ml-100k/Self_GraphTask_estimations.csv'\n",
"# and 'Recommendations generated/ml-100k/Self_GraphTask_reco.csv'"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}