1482 lines
555 KiB
Plaintext
1482 lines
555 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Self made RP3-beta"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"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": 2,
|
||
|
"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, 9220.23it/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>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>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 Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.875928 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",
|
||
|
"943it [00:00, 9951.34it/s]\n",
|
||
|
" 12%|█▎ | 1/8 [00:08<01:00, 8.59s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 9002.19it/s]\u001b[A\n",
|
||
|
" 25%|██▌ | 2/8 [00:17<00:51, 8.55s/it]\n",
|
||
|
"943it [00:00, 9650.83it/s]\n",
|
||
|
" 38%|███▊ | 3/8 [00:25<00:42, 8.59s/it]\n",
|
||
|
"943it [00:00, 9645.16it/s]\n",
|
||
|
" 50%|█████ | 4/8 [00:34<00:34, 8.56s/it]\n",
|
||
|
"943it [00:00, 9747.61it/s]\n",
|
||
|
" 62%|██████▎ | 5/8 [00:42<00:25, 8.56s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8754.83it/s]\u001b[A\n",
|
||
|
" 75%|███████▌ | 6/8 [00:51<00:17, 8.55s/it]\n",
|
||
|
"943it [00:00, 9849.34it/s]\n",
|
||
|
" 88%|████████▊ | 7/8 [01:00<00:08, 8.60s/it]\n",
|
||
|
"943it [00:00, 9550.72it/s]\n",
|
||
|
"100%|██████████| 8/8 [01:08<00:00, 8.57s/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>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>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>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>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>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>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>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>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.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 Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.850477 1.000000 0.060606 3.669627 0.979636 \n",
|
||
|
"0 0.854719 1.000000 0.064214 3.726996 0.978426 \n",
|
||
|
"0 0.870626 1.000000 0.065657 3.785282 0.977090 \n",
|
||
|
"0 0.874867 1.000000 0.070707 3.832415 0.975998 \n",
|
||
|
"0 0.875928 1.000000 0.077201 3.875892 0.974947 \n",
|
||
|
"0 0.883351 1.000000 0.085859 3.910718 0.974073 \n",
|
||
|
"0 0.871686 1.000000 0.107504 3.961915 0.972674 \n",
|
||
|
"0 0.868505 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": [],
|
||
|
"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",
|
||
|
"943it [00:00, 8518.16it/s]\u001b[A\n",
|
||
|
" 10%|█ | 1/10 [00:08<01:20, 8.89s/it]\n",
|
||
|
"943it [00:00, 9548.16it/s]\n",
|
||
|
" 20%|██ | 2/10 [00:18<01:11, 8.98s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8836.58it/s]\u001b[A\n",
|
||
|
" 30%|███ | 3/10 [00:26<01:02, 8.87s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8920.03it/s]\u001b[A\n",
|
||
|
" 40%|████ | 4/10 [00:35<00:52, 8.80s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 9269.76it/s]\u001b[A\n",
|
||
|
" 50%|█████ | 5/10 [00:44<00:44, 8.87s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8958.45it/s]\u001b[A\n",
|
||
|
" 60%|██████ | 6/10 [00:53<00:35, 8.80s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8674.45it/s]\u001b[A\n",
|
||
|
" 70%|███████ | 7/10 [01:01<00:26, 8.79s/it]\n",
|
||
|
"943it [00:00, 9648.17it/s]\n",
|
||
|
" 80%|████████ | 8/10 [01:10<00:17, 8.77s/it]\n",
|
||
|
"943it [00:00, 9457.86it/s]\n",
|
||
|
" 90%|█████████ | 9/10 [01:19<00:08, 8.73s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 8711.65it/s]\u001b[A\n",
|
||
|
"100%|██████████| 10/10 [01:27<00:00, 8.79s/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>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>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>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>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>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.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.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.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.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.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.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 Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.875928 1.000000 0.077201 3.875892 0.974947 \n",
|
||
|
"0 0.884411 1.000000 0.085137 3.957416 0.972784 \n",
|
||
|
"0 0.886532 1.000000 0.094517 4.053212 0.969980 \n",
|
||
|
"0 0.888653 1.000000 0.105339 4.147779 0.966948 \n",
|
||
|
"0 0.895016 0.999894 0.132035 4.259682 0.962989 \n",
|
||
|
"0 0.903499 0.999046 0.168831 4.411281 0.956648 \n",
|
||
|
"0 0.897137 0.996394 0.212843 4.621938 0.945932 \n",
|
||
|
"0 0.868505 0.983033 0.256854 4.898568 0.928065 \n",
|
||
|
"0 0.803818 0.936373 0.341270 5.257397 0.895882 \n",
|
||
|
"0 0.580064 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": [],
|
||
|
"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>28480</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Right Stuff, The (1983)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>50423</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Conan the Barbarian (1981)</td>\n",
|
||
|
" <td>Action, Adventure</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>18188</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Clockwork Orange, A (1971)</td>\n",
|
||
|
" <td>Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>22286</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Groundhog Day (1993)</td>\n",
|
||
|
" <td>Comedy, Romance</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>23943</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Apocalypse Now (1979)</td>\n",
|
||
|
" <td>Drama, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>51726</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Star Trek VI: The Undiscovered Country (1991)</td>\n",
|
||
|
" <td>Action, Adventure, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>16714</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Man Who Would Be King, The (1975)</td>\n",
|
||
|
" <td>Adventure</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>42312</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Treasure of the Sierra Madre, The (1948)</td>\n",
|
||
|
" <td>Adventure</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>37594</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Nightmare on Elm Street, A (1984)</td>\n",
|
||
|
" <td>Horror</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>16066</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Godfather, The (1972)</td>\n",
|
||
|
" <td>Action, Crime, Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>62624</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Highlander (1986)</td>\n",
|
||
|
" <td>Action, Adventure</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3611</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Aliens (1986)</td>\n",
|
||
|
" <td>Action, Sci-Fi, Thriller, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>57765</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Killing Fields, The (1984)</td>\n",
|
||
|
" <td>Drama, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>54287</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>12 Angry Men (1957)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>47568</th>\n",
|
||
|
" <td>774</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Alien (1979)</td>\n",
|
||
|
" <td>Action, Horror, Sci-Fi, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" user rating title \\\n",
|
||
|
"28480 774 5 Right Stuff, The (1983) \n",
|
||
|
"50423 774 5 Conan the Barbarian (1981) \n",
|
||
|
"18188 774 5 Clockwork Orange, A (1971) \n",
|
||
|
"22286 774 5 Groundhog Day (1993) \n",
|
||
|
"23943 774 5 Apocalypse Now (1979) \n",
|
||
|
"51726 774 5 Star Trek VI: The Undiscovered Country (1991) \n",
|
||
|
"16714 774 5 Man Who Would Be King, The (1975) \n",
|
||
|
"42312 774 5 Treasure of the Sierra Madre, The (1948) \n",
|
||
|
"37594 774 4 Nightmare on Elm Street, A (1984) \n",
|
||
|
"16066 774 4 Godfather, The (1972) \n",
|
||
|
"62624 774 4 Highlander (1986) \n",
|
||
|
"3611 774 4 Aliens (1986) \n",
|
||
|
"57765 774 4 Killing Fields, The (1984) \n",
|
||
|
"54287 774 4 12 Angry Men (1957) \n",
|
||
|
"47568 774 4 Alien (1979) \n",
|
||
|
"\n",
|
||
|
" genres \n",
|
||
|
"28480 Drama \n",
|
||
|
"50423 Action, Adventure \n",
|
||
|
"18188 Sci-Fi \n",
|
||
|
"22286 Comedy, Romance \n",
|
||
|
"23943 Drama, War \n",
|
||
|
"51726 Action, Adventure, Sci-Fi \n",
|
||
|
"16714 Adventure \n",
|
||
|
"42312 Adventure \n",
|
||
|
"37594 Horror \n",
|
||
|
"16066 Action, Crime, Drama \n",
|
||
|
"62624 Action, Adventure \n",
|
||
|
"3611 Action, Sci-Fi, Thriller, War \n",
|
||
|
"57765 Drama, War \n",
|
||
|
"54287 Drama \n",
|
||
|
"47568 Action, Horror, Sci-Fi, Thriller "
|
||
|
]
|
||
|
},
|
||
|
"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>900</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>1</td>\n",
|
||
|
" <td>Silence of the Lambs, The (1991)</td>\n",
|
||
|
" <td>Drama, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3335</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>2</td>\n",
|
||
|
" <td>Toy Story (1995)</td>\n",
|
||
|
" <td>Animation, Children's, Comedy</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>7822</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Princess Bride, The (1987)</td>\n",
|
||
|
" <td>Action, Adventure, Comedy, Romance</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4301</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Twelve Monkeys (1995)</td>\n",
|
||
|
" <td>Drama, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>8426</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Indiana Jones and the Last Crusade (1989)</td>\n",
|
||
|
" <td>Action, Adventure</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>8752</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>6</td>\n",
|
||
|
" <td>Terminator, The (1984)</td>\n",
|
||
|
" <td>Action, Sci-Fi, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2075</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>7</td>\n",
|
||
|
" <td>Back to the Future (1985)</td>\n",
|
||
|
" <td>Comedy, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>8681</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>8</td>\n",
|
||
|
" <td>Forrest Gump (1994)</td>\n",
|
||
|
" <td>Comedy, Romance, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>7507</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>9</td>\n",
|
||
|
" <td>Star Trek: First Contact (1996)</td>\n",
|
||
|
" <td>Action, Adventure, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>7942</th>\n",
|
||
|
" <td>774.0</td>\n",
|
||
|
" <td>10</td>\n",
|
||
|
" <td>Amadeus (1984)</td>\n",
|
||
|
" <td>Drama, Mystery</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" user rec_nb title \\\n",
|
||
|
"900 774.0 1 Silence of the Lambs, The (1991) \n",
|
||
|
"3335 774.0 2 Toy Story (1995) \n",
|
||
|
"7822 774.0 3 Princess Bride, The (1987) \n",
|
||
|
"4301 774.0 4 Twelve Monkeys (1995) \n",
|
||
|
"8426 774.0 5 Indiana Jones and the Last Crusade (1989) \n",
|
||
|
"8752 774.0 6 Terminator, The (1984) \n",
|
||
|
"2075 774.0 7 Back to the Future (1985) \n",
|
||
|
"8681 774.0 8 Forrest Gump (1994) \n",
|
||
|
"7507 774.0 9 Star Trek: First Contact (1996) \n",
|
||
|
"7942 774.0 10 Amadeus (1984) \n",
|
||
|
"\n",
|
||
|
" genres \n",
|
||
|
"900 Drama, Thriller \n",
|
||
|
"3335 Animation, Children's, Comedy \n",
|
||
|
"7822 Action, Adventure, Comedy, Romance \n",
|
||
|
"4301 Drama, Sci-Fi \n",
|
||
|
"8426 Action, Adventure \n",
|
||
|
"8752 Action, Sci-Fi, Thriller \n",
|
||
|
"2075 Comedy, Sci-Fi \n",
|
||
|
"8681 Comedy, Romance, War \n",
|
||
|
"7507 Action, Adventure, Sci-Fi \n",
|
||
|
"7942 Drama, Mystery "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCwAAAkoCAYAAACgVC5GAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzde3xV9ZX//9fKPSdcTwiQkERQAbkl2CLi/YIoWAJtv73gWL+O2p9jR3uxnZnqTKftt63f7/Te6YxOH047ozO1eKlth1jvjlgdr6gkgoCCQAgJEMIdQq7r98fZwUMIt5CcfZLzfj4e5+HZn733OevwkM05a6/P+pi7IyIiIiIiIiKSTNLCDkBEREREREREpCslLEREREREREQk6ShhISIiIiIiIiJJRwkLEREREREREUk6SliIiIiIiIiISNJRwkJEREREREREko4SFiIiIiIiInKImf3CzP7+BI5baWaXJiAkSVFKWMiAY2YbzKzJzPaZ2RYzu8/MBgX77jMzN7MFXc75WTD+58F2lpn92Mxqg9dZb2Y/Pcp7dD7+OaEfVESkHwmumy1mNqLL+PLg+js2buzbwdjMLsf+uZm1d7n27jOzosR8ChGR1ODut7j7d0/guCnuvjQBIUmKUsJCBqoKdx8ETAfOBu6M2/cecH3nhpllAJ8G1sUdcycwA5gJDAYuA97u7j3iHrf1/scQERlQ1gPXdG6Y2TQgN/4AMzPgOmAHcdfqOK90ufYOcve6vgxaRKQ/Cr7jivRrSljIgObuW4CniCUuOlUCF5jZ8GB7LlANbIk75hzg9+5e5zEb3P0/EhK0iMjA9Z/A/47bvh7oem29CCgCvgwsMrOsBMUmItIvBBVrd5rZu2a208z+3cxyzOzSoDr462a2Bfh3M0szszvMbJ2ZNZrZw2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2ziP5yISD9mZlx33XWHttva2igoKGD+/PmHHbdw4ULOO++8w8a+/e1vM2bMmMOuw53X9wQaA2yK264Nxo7mJuAJAHffDPwIqAHqgd3u/nQ359zYeU5gnJm9bWYvmNlFpxK8iKSuZcuW8aUvfemo++vq6vjUpz6VwIhOnBIWIjKg5Obmsnz5clasWEE0GuXuu+8+tO/000/nscceO7T9yCOPMGXKlEPbX/rSl7j99ttZvnw5q1at4otf/OKhfRdddBHLly8/9LjiiisS84FERAaIvLw8VqxYQVNTEwDPPPMMY8Yc/nt/165dvPXWW+zatYv169cftq/z+tz5GDZsWMJiD3R329C7PdDsMmIJi68H28OJVWOMA4qAPDP7XJdz/g5oAx4IhuqBUnc/G/gq8BszG9LNe91sZsvMbFlDQ0OPPpiI9C/t7e0ndfyMGTP4+c9/ftT9RUVF/Pa3vz3VsPqEEhYiMmCdd955bN68+dB2bm4ukyZNYtmyZQA89NBDfOYznzm0v76+nuLiDytxp02blrhgRURSwLx58/jjH/8IwOLFi7nmmmsO2//oo49SUVHBokWLePDBB8MI8VhqgZK47WKCaR3xzKwM+CWw0N0bg+ErgPXu3uDurcDvgPPjzrkemA9c6+4O4O7Nnee7+5vEGnJO6Pp+7n6vu89w9xkFBQW98DFFJEwbNmzgrLPO4vrrr6esrIxPfepTHDhwgLFjx/Kd73yHCy+8kEceeYSnn36a8847j4985CN8+tOfZt++fQC88cYbnH/++ZSXlzNz5kz27t3L0qVLD1WzvfDCC4cq1c4++2z27t3Lhg0bmDp1KhDr4XHDDTcwbdo0zj77bJ5//nkA7rvvPj75yU8yd+5cxo8fz9/8zd8k5M9Dq4SISJ/4P5UrebduT6++5uSiIXyrYsrxDySWeX7uuee46aabDhvv/BI8evR
|
||
|
"text/plain": [
|
||
|
"<Figure size 1296x3024 with 18 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
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nYi0LfrZfvJO9d9dq51h0Rx4e3uTmppK3759ufDCC8nPzwcgIyMDYwz33XdfXd8DBw7g6+vLLbfcAsCWLVs466yzSE1NpXfv3txwww0ALF68mLCwMFJTU+teixYt8vzNiYi0EMYYrrzyyrrjqqoqoqKimDhx4hH9Jk2axPDhw48498ADDxAXF3fEmFs7louIHA9r7YfW2h7W2m7W2ofd555zJyuw1j5ire1jrU211g631i51n19qrTXW2v7utlQlK0TkZKxatYrbbrvtqO3Z2dlMnjzZgxEdPyUsmlBgYCBpaWls2LCBiIgInn322bq2rl278v7779cdv/baa/Tp06fu+LbbbmPmzJmkpaWxadMmbr311rq2UaNGkZaWVvcaO7auLpOIiDQQHBzMhg0bKC0tBWDhwoXExR1ZpD8/P5/Vq1eTn5/Pzp07j2irHYtrX+Hh4R6LXURERKSh6urqE+o/aNAgnnnmmaO2x8bG8vrrr//UsJqEEhYeMnz4cPbs2VN3HBgYSO/evVm1ahUA8+fP57LLLqtrz8nJIT4+vu64X79+ngtWRKSVOe+88/jggw8AmDt3LtOmTTui/Y033uDCCy9k6tSpzJs3z4kQRURERMjIyKBXr15cffXV9O/fn8mTJ1NSUkJSUhIPPvggI0eO5LXXXmPBggUMHz6c0047jSlTplBcXAzAypUrOeOMMxgwYABDhgyhqKiIxYsX180s/eKLL+pmjQ4cOJCioiIyMjLo27cv4Krhce2119KvXz8GDhzI559/DsDs2bO55JJLmDBhAsnJyfz2t7/1yN9
|
||
|
"text/plain": [
|
||
|
"<Figure size 1296x3024 with 18 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"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": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 9215.29it/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>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.704589</td>\n",
|
||
|
" <td>3.529397</td>\n",
|
||
|
" <td>0.286744</td>\n",
|
||
|
" <td>0.196524</td>\n",
|
||
|
" <td>0.191117</td>\n",
|
||
|
" <td>0.221375</td>\n",
|
||
|
" <td>0.213948</td>\n",
|
||
|
" <td>0.251263</td>\n",
|
||
|
" <td>0.344598</td>\n",
|
||
|
" <td>0.207836</td>\n",
|
||
|
" <td>0.587953</td>\n",
|
||
|
" <td>0.59577</td>\n",
|
||
|
" <td>0.885472</td>\n",
|
||
|
" <td>0.998197</td>\n",
|
||
|
" <td>0.193362</td>\n",
|
||
|
" <td>4.291821</td>\n",
|
||
|
" <td>0.960775</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 3.704589 3.529397 0.286744 0.196524 0.191117 0.221375 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.213948 0.251263 0.344598 0.207836 0.587953 0.59577 \n",
|
||
|
"\n",
|
||
|
" HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.885472 0.998197 0.193362 4.291821 0.960775 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"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'model=RP3Beta()\n",
|
||
|
"model.fit(train_ui, alpha=1.4, beta=0.3)\n",
|
||
|
"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)\n",
|
||
|
"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), estimations_df=estimations_df, reco=reco, 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'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"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.8.3"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|