1642 lines
82 KiB
Plaintext
1642 lines
82 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Self made SVD"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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",
|
||
|
"\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": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Done similarly to https://github.com/albertauyeung/matrix-factorization-in-python\n",
|
||
|
"from tqdm import tqdm\n",
|
||
|
"\n",
|
||
|
"class SVD():\n",
|
||
|
" \n",
|
||
|
" def __init__(self, train_ui, learning_rate, regularization, nb_factors, iterations):\n",
|
||
|
" self.train_ui=train_ui\n",
|
||
|
" self.uir=list(zip(*[train_ui.nonzero()[0],train_ui.nonzero()[1], train_ui.data]))\n",
|
||
|
" \n",
|
||
|
" self.learning_rate=learning_rate\n",
|
||
|
" self.regularization=regularization\n",
|
||
|
" self.iterations=iterations\n",
|
||
|
" self.nb_users, self.nb_items=train_ui.shape\n",
|
||
|
" self.nb_ratings=train_ui.nnz\n",
|
||
|
" self.nb_factors=nb_factors\n",
|
||
|
" \n",
|
||
|
" self.Pu=np.random.normal(loc=0, scale=1./self.nb_factors, size=(self.nb_users, self.nb_factors))\n",
|
||
|
" self.Qi=np.random.normal(loc=0, scale=1./self.nb_factors, size=(self.nb_items, self.nb_factors))\n",
|
||
|
"\n",
|
||
|
" def train(self, test_ui=None):\n",
|
||
|
" if test_ui!=None:\n",
|
||
|
" self.test_uir=list(zip(*[test_ui.nonzero()[0],test_ui.nonzero()[1], test_ui.data]))\n",
|
||
|
" \n",
|
||
|
" self.learning_process=[]\n",
|
||
|
" pbar = tqdm(range(self.iterations))\n",
|
||
|
" for i in pbar:\n",
|
||
|
" pbar.set_description(f'Epoch {i} RMSE: {self.learning_process[-1][1] if i>0 else 0}. Training epoch {i+1}...')\n",
|
||
|
" np.random.shuffle(self.uir)\n",
|
||
|
" self.sgd(self.uir)\n",
|
||
|
" if test_ui==None:\n",
|
||
|
" self.learning_process.append([i+1, self.RMSE_total(self.uir)])\n",
|
||
|
" else:\n",
|
||
|
" self.learning_process.append([i+1, self.RMSE_total(self.uir), self.RMSE_total(self.test_uir)])\n",
|
||
|
" \n",
|
||
|
" def sgd(self, uir):\n",
|
||
|
" \n",
|
||
|
" for u, i, score in uir:\n",
|
||
|
" # Computer prediction and error\n",
|
||
|
" prediction = self.get_rating(u,i)\n",
|
||
|
" e = (score - prediction)\n",
|
||
|
" \n",
|
||
|
" # Update user and item latent feature matrices\n",
|
||
|
" Pu_update=self.learning_rate * (e * self.Qi[i] - self.regularization * self.Pu[u])\n",
|
||
|
" Qi_update=self.learning_rate * (e * self.Pu[u] - self.regularization * self.Qi[i])\n",
|
||
|
" \n",
|
||
|
" self.Pu[u] += Pu_update\n",
|
||
|
" self.Qi[i] += Qi_update\n",
|
||
|
" \n",
|
||
|
" def get_rating(self, u, i):\n",
|
||
|
" prediction = self.Pu[u].dot(self.Qi[i].T)\n",
|
||
|
" return prediction\n",
|
||
|
" \n",
|
||
|
" def RMSE_total(self, uir):\n",
|
||
|
" RMSE=0\n",
|
||
|
" for u,i, score in uir:\n",
|
||
|
" prediction = self.get_rating(u,i)\n",
|
||
|
" RMSE+=(score - prediction)**2\n",
|
||
|
" return np.sqrt(RMSE/len(uir))\n",
|
||
|
" \n",
|
||
|
" def estimations(self):\n",
|
||
|
" self.estimations=\\\n",
|
||
|
" np.dot(self.Pu,self.Qi.T)\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": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Epoch 39 RMSE: 0.7493723517098142. Training epoch 40...: 100%|██████████| 40/40 [02:06<00:00, 3.16s/it]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"model=SVD(train_ui, learning_rate=0.005, regularization=0.02, nb_factors=100, iterations=40)\n",
|
||
|
"model.train(test_ui)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x7f39a01f7c50>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAb4klEQVR4nO3de3RV9Z338feXEAkBNCREyxARsY7SogaJji5pF8hqBetUan0sTtdU23mKq8WirfqMWi+to1Mty6q0tZSOVp1xRDuiosvqYwuO492AAUEQtKAE0cTEBLByCXznj70POQknyUk4yT7Z+/Na67fOvp1zvuxFPnvv374cc3dERKT/GxB1ASIikhsKdBGRmFCgi4jEhAJdRCQmFOgiIjExMKovHjFihI8ZMyaqrxcR6ZeWLVv2kbuXZ5oXWaCPGTOG6urqqL5eRKRfMrN3O5qnLhcRkZhQoIuIxIQCXUQkJiLrQxeR/mf37t3U1tayY8eOqEuJvaKiIioqKigsLMz6PQp0EclabW0tw4YNY8yYMZhZ1OXElrvT0NBAbW0tRx55ZNbvU5eLiGRtx44dlJWVKcx7mZlRVlbW7SMhBbqIdIvCvG/0ZD33u0CvrYVLL4Xdu6OuREQkv/S7QK+uhjvugH/916grERHJL/0u0GfMgG9+E268EZYvj7oaEelLTU1N3Hnnnd1+35lnnklTU1O333fhhRdy5JFHUllZyQknnMCf//znffMmT57M6NGjSf+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SQ
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"df=pd.DataFrame(model.learning_process).iloc[:,:2]\n",
|
||
|
"df.columns=['epoch', 'train_RMSE']\n",
|
||
|
"plt.plot('epoch', 'train_RMSE', data=df, color='blue')\n",
|
||
|
"plt.legend()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x7f399be5f518>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de5yOdf7H8dfHIYeUxNTKOCUd5DBqqH4ppHLISich20nZLVZt2NLarbTbKrXJLpVKRUXnTSelKLWpjOMi5xwGG0s6Uivf3x+fa7hpcBszcx/m/Xw8rsfc93Xdh+/lHp/7mu/38/18LYSAiIikr1KJboCIiBQtBXoRkTSnQC8ikuYU6EVE0pwCvYhImiuT6Absrlq1aqFOnTqJboaISEqZMWPGf0MIGfkd22egN7PRQEdgfQihYT7HDXgA6AB8D1wZQpgZHbsCGBQ99M8hhCf39X516tQhJydnXw8TEZEYZrZyT8fi6b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WIARo8ezYwZM8jJyWH48OFs3LjxZ6+xZMkSevfuzfz58znssMN48cUX43rviRMn0rlz5132tWnThqlTp/LTTz8xfvx4Lr300h3HunTpwquvvkpWVhb9+vVj1qxZuzy3devWO7pu7r///v39p8hXml7R56cVsBx4DBiCl91pCnxClC0qIoVgb1fexaV58+a7TCgaPnw4L7/8MgCrV69myZIlVK1adZfn5PW5A5x88smsWLFir+8xYMAAbr31VnJzc5k2bdoux0qXLk2LFi0YP348W7ZsIbb0emZmJosWLWLy5MlMnjyZNm3a8Pzzz9OmTRugaLpu0vyKfnfl8UzQpXhRzvPYGeSfBNYnplkiUqhi+7zfe+893nnnHaZNm8acOXNo2rRpvhOOypUrt+N26dKl2bZt217fY+jQoSxevJi7776bq6+++mfHu3btSt++fenSpUu+79W+fXuGDh3Krbfeyj//+c/9Ob39VsICfZ5ywBXAndH9lfg8r1p45s68BLVLRArikEMO4Ztvvsn32FdffUWVKlWoWLEiCxcu5OOPCzcTr0+fPmzfvp233tp14v8ZZ5zBwIED6dZt16lIM2fOZO3atYBn4MydO5fatWsXapt2V4K6bvamNrAAXz/lSbx751w8c6deAtslIvGoWrUqp59+Og0bNqRChQoceeSRO461a9eOhx56iBNOOIHjjjuOU089tVDf28wYNGgQ99xzD23btt1lf//+/X/2+PXr13Pttdfyww8/AN7N1KdPnx3HW7duTenSpQFo3LgxY8aMOfA2xuZ6JoPs7OyQ2BWmNgIP4107nwBVgGV4heXyiWuWSBL77LPPOOGEExLdjBIjv39vM5sRQsjO7/EltOtmb6riufeL8CAfgEvw7J272PsaLCIiyUeBfo9i8+yH4hk6f8ArMvcFPk9Eo0SkGPXu3XtHqmPe9vjjjye6WftNffT7ZECbaPs3cB9eU6cJ0BPYjr4vRdLTiBEjEt2EQqEItV8a4X33nwM9on3D8Zm2r+JBX0QkuSjQF0gNPEUTvB//c6ATcDS+ImLR5sSKiOwPBfoDdgWelfM03p3zLJ61k+defG2Wb4u/aSIiqI++kJQFukfbNjxFE+AbvJrmVv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etZu3YtFStWpEePHgwYMICZM2f+7Ln7UqZMGYYNG8aYMWPYtGnXAodXX301t912G40aNdpl/+TJk3cM9n7zzTcsW7aMWrVqHdD57i913aSMavhat3nOAtbh6ZsLgNn4xKw60fHRwIfA+cA5+J/LIukpth59+/bt6d69O6eddhoAlSpV4qmnnmLp0qUMGDCAUqVKUbZsWR588EEAevXqRbt27Xb01e9L9erV6da
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"df=pd.DataFrame(model.learning_process[10:], columns=['epoch', 'train_RMSE', 'test_RMSE'])\n",
|
||
|
"plt.plot('epoch', 'train_RMSE', data=df, color='blue')\n",
|
||
|
"plt.plot('epoch', 'test_RMSE', data=df, color='yellow', linestyle='dashed')\n",
|
||
|
"plt.legend()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"#### Saving and evaluating recommendations"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"model.estimations()\n",
|
||
|
"\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_SVD_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_SVD_estimations.csv', index=False, header=False)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 4912.25it/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>0.9144</td>\n",
|
||
|
" <td>0.718047</td>\n",
|
||
|
" <td>0.103393</td>\n",
|
||
|
" <td>0.043404</td>\n",
|
||
|
" <td>0.05292</td>\n",
|
||
|
" <td>0.070119</td>\n",
|
||
|
" <td>0.093455</td>\n",
|
||
|
" <td>0.074901</td>\n",
|
||
|
" <td>0.107441</td>\n",
|
||
|
" <td>0.05077</td>\n",
|
||
|
" <td>0.200719</td>\n",
|
||
|
" <td>0.518433</td>\n",
|
||
|
" <td>0.4772</td>\n",
|
||
|
" <td>0.866384</td>\n",
|
||
|
" <td>0.145743</td>\n",
|
||
|
" <td>3.860721</td>\n",
|
||
|
" <td>0.972299</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE precision recall F_1 F_05 precision_super \\\n",
|
||
|
"0 0.9144 0.718047 0.103393 0.043404 0.05292 0.070119 0.093455 \n",
|
||
|
"\n",
|
||
|
" recall_super NDCG mAP MRR LAUC HR Reco in test \\\n",
|
||
|
"0 0.074901 0.107441 0.05077 0.200719 0.518433 0.4772 0.866384 \n",
|
||
|
"\n",
|
||
|
" Test coverage Shannon Gini \n",
|
||
|
"0 0.145743 3.860721 0.972299 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 18,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"\n",
|
||
|
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Self_SVD_estimations.csv', header=None)\n",
|
||
|
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_SVD_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": "code",
|
||
|
"execution_count": 37,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 4816.30it/s]\n",
|
||
|
"943it [00:00, 4733.95it/s]\n",
|
||
|
"943it [00:00, 4623.19it/s]\n",
|
||
|
"943it [00:00, 5099.59it/s]\n",
|
||
|
"943it [00:00, 4968.40it/s]\n",
|
||
|
"943it [00:00, 5056.01it/s]\n",
|
||
|
"943it [00:00, 5009.35it/s]\n",
|
||
|
"943it [00:00, 3610.70it/s]\n",
|
||
|
"943it [00:00, 4280.45it/s]\n",
|
||
|
"943it [00:00, 4473.91it/s]\n",
|
||
|
"943it [00:00, 4438.83it/s]\n",
|
||
|
"943it [00:00, 5165.96it/s]\n",
|
||
|
"943it [00:00, 5259.28it/s]\n",
|
||
|
"943it [00:00, 4607.07it/s]\n",
|
||
|
"943it [00:00, 4329.45it/s]\n",
|
||
|
"943it [00:00, 4693.81it/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>Model</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>Self_RP3Beta</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>Self_TopPop</td>\n",
|
||
|
" <td>2.508258</td>\n",
|
||
|
" <td>2.217909</td>\n",
|
||
|
" <td>0.188865</td>\n",
|
||
|
" <td>0.116919</td>\n",
|
||
|
" <td>0.118732</td>\n",
|
||
|
" <td>0.141584</td>\n",
|
||
|
" <td>0.130472</td>\n",
|
||
|
" <td>0.137473</td>\n",
|
||
|
" <td>0.214651</td>\n",
|
||
|
" <td>0.111707</td>\n",
|
||
|
" <td>0.400939</td>\n",
|
||
|
" <td>0.555546</td>\n",
|
||
|
" <td>0.765642</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.038961</td>\n",
|
||
|
" <td>3.159079</td>\n",
|
||
|
" <td>0.987317</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVD</td>\n",
|
||
|
" <td>0.952784</td>\n",
|
||
|
" <td>0.750597</td>\n",
|
||
|
" <td>0.095228</td>\n",
|
||
|
" <td>0.047497</td>\n",
|
||
|
" <td>0.053142</td>\n",
|
||
|
" <td>0.067082</td>\n",
|
||
|
" <td>0.084871</td>\n",
|
||
|
" <td>0.076457</td>\n",
|
||
|
" <td>0.109075</td>\n",
|
||
|
" <td>0.050124</td>\n",
|
||
|
" <td>0.241366</td>\n",
|
||
|
" <td>0.520459</td>\n",
|
||
|
" <td>0.499470</td>\n",
|
||
|
" <td>0.992047</td>\n",
|
||
|
" <td>0.217893</td>\n",
|
||
|
" <td>4.405246</td>\n",
|
||
|
" <td>0.953484</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVDBaseline</td>\n",
|
||
|
" <td>0.913380</td>\n",
|
||
|
" <td>0.719974</td>\n",
|
||
|
" <td>0.105726</td>\n",
|
||
|
" <td>0.045055</td>\n",
|
||
|
" <td>0.054233</td>\n",
|
||
|
" <td>0.071579</td>\n",
|
||
|
" <td>0.096674</td>\n",
|
||
|
" <td>0.075899</td>\n",
|
||
|
" <td>0.119979</td>\n",
|
||
|
" <td>0.059709</td>\n",
|
||
|
" <td>0.251389</td>\n",
|
||
|
" <td>0.519270</td>\n",
|
||
|
" <td>0.476140</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.115440</td>\n",
|
||
|
" <td>3.578129</td>\n",
|
||
|
" <td>0.980463</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVD</td>\n",
|
||
|
" <td>0.914400</td>\n",
|
||
|
" <td>0.718047</td>\n",
|
||
|
" <td>0.103393</td>\n",
|
||
|
" <td>0.043404</td>\n",
|
||
|
" <td>0.052920</td>\n",
|
||
|
" <td>0.070119</td>\n",
|
||
|
" <td>0.093455</td>\n",
|
||
|
" <td>0.074901</td>\n",
|
||
|
" <td>0.107441</td>\n",
|
||
|
" <td>0.050770</td>\n",
|
||
|
" <td>0.200719</td>\n",
|
||
|
" <td>0.518433</td>\n",
|
||
|
" <td>0.477200</td>\n",
|
||
|
" <td>0.866384</td>\n",
|
||
|
" <td>0.145743</td>\n",
|
||
|
" <td>3.860721</td>\n",
|
||
|
" <td>0.972299</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVDBiased</td>\n",
|
||
|
" <td>0.940375</td>\n",
|
||
|
" <td>0.742264</td>\n",
|
||
|
" <td>0.092153</td>\n",
|
||
|
" <td>0.039645</td>\n",
|
||
|
" <td>0.046804</td>\n",
|
||
|
" <td>0.061886</td>\n",
|
||
|
" <td>0.079399</td>\n",
|
||
|
" <td>0.055967</td>\n",
|
||
|
" <td>0.102017</td>\n",
|
||
|
" <td>0.047972</td>\n",
|
||
|
" <td>0.216876</td>\n",
|
||
|
" <td>0.516515</td>\n",
|
||
|
" <td>0.441145</td>\n",
|
||
|
" <td>0.997455</td>\n",
|
||
|
" <td>0.167388</td>\n",
|
||
|
" <td>4.235348</td>\n",
|
||
|
" <td>0.962085</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_Baseline</td>\n",
|
||
|
" <td>0.949459</td>\n",
|
||
|
" <td>0.752487</td>\n",
|
||
|
" <td>0.091410</td>\n",
|
||
|
" <td>0.037652</td>\n",
|
||
|
" <td>0.046030</td>\n",
|
||
|
" <td>0.061286</td>\n",
|
||
|
" <td>0.079614</td>\n",
|
||
|
" <td>0.056463</td>\n",
|
||
|
" <td>0.095957</td>\n",
|
||
|
" <td>0.043178</td>\n",
|
||
|
" <td>0.198193</td>\n",
|
||
|
" <td>0.515501</td>\n",
|
||
|
" <td>0.437964</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.033911</td>\n",
|
||
|
" <td>2.836513</td>\n",
|
||
|
" <td>0.991139</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_GlobalAvg</td>\n",
|
||
|
" <td>1.125760</td>\n",
|
||
|
" <td>0.943534</td>\n",
|
||
|
" <td>0.061188</td>\n",
|
||
|
" <td>0.025968</td>\n",
|
||
|
" <td>0.031383</td>\n",
|
||
|
" <td>0.041343</td>\n",
|
||
|
" <td>0.040558</td>\n",
|
||
|
" <td>0.032107</td>\n",
|
||
|
" <td>0.067695</td>\n",
|
||
|
" <td>0.027470</td>\n",
|
||
|
" <td>0.171187</td>\n",
|
||
|
" <td>0.509546</td>\n",
|
||
|
" <td>0.384942</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.025974</td>\n",
|
||
|
" <td>2.711772</td>\n",
|
||
|
" <td>0.992003</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_Random</td>\n",
|
||
|
" <td>1.518551</td>\n",
|
||
|
" <td>1.218784</td>\n",
|
||
|
" <td>0.050583</td>\n",
|
||
|
" <td>0.024085</td>\n",
|
||
|
" <td>0.027323</td>\n",
|
||
|
" <td>0.034826</td>\n",
|
||
|
" <td>0.031223</td>\n",
|
||
|
" <td>0.026436</td>\n",
|
||
|
" <td>0.054902</td>\n",
|
||
|
" <td>0.020652</td>\n",
|
||
|
" <td>0.137928</td>\n",
|
||
|
" <td>0.508570</td>\n",
|
||
|
" <td>0.353128</td>\n",
|
||
|
" <td>0.987699</td>\n",
|
||
|
" <td>0.183261</td>\n",
|
||
|
" <td>5.093805</td>\n",
|
||
|
" <td>0.908215</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_I-KNN</td>\n",
|
||
|
" <td>1.030386</td>\n",
|
||
|
" <td>0.813067</td>\n",
|
||
|
" <td>0.026087</td>\n",
|
||
|
" <td>0.006908</td>\n",
|
||
|
" <td>0.010593</td>\n",
|
||
|
" <td>0.016046</td>\n",
|
||
|
" <td>0.021137</td>\n",
|
||
|
" <td>0.009522</td>\n",
|
||
|
" <td>0.024214</td>\n",
|
||
|
" <td>0.008958</td>\n",
|
||
|
" <td>0.048068</td>\n",
|
||
|
" <td>0.499885</td>\n",
|
||
|
" <td>0.154825</td>\n",
|
||
|
" <td>0.402333</td>\n",
|
||
|
" <td>0.434343</td>\n",
|
||
|
" <td>5.133650</td>\n",
|
||
|
" <td>0.877999</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_U-KNNBaseline</td>\n",
|
||
|
" <td>0.935327</td>\n",
|
||
|
" <td>0.737424</td>\n",
|
||
|
" <td>0.002545</td>\n",
|
||
|
" <td>0.000755</td>\n",
|
||
|
" <td>0.001105</td>\n",
|
||
|
" <td>0.001602</td>\n",
|
||
|
" <td>0.002253</td>\n",
|
||
|
" <td>0.000930</td>\n",
|
||
|
" <td>0.003444</td>\n",
|
||
|
" <td>0.001362</td>\n",
|
||
|
" <td>0.011760</td>\n",
|
||
|
" <td>0.496724</td>\n",
|
||
|
" <td>0.021209</td>\n",
|
||
|
" <td>0.482821</td>\n",
|
||
|
" <td>0.059885</td>\n",
|
||
|
" <td>2.232578</td>\n",
|
||
|
" <td>0.994487</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_I-KNNBaseline</td>\n",
|
||
|
" <td>0.935327</td>\n",
|
||
|
" <td>0.737424</td>\n",
|
||
|
" <td>0.002545</td>\n",
|
||
|
" <td>0.000755</td>\n",
|
||
|
" <td>0.001105</td>\n",
|
||
|
" <td>0.001602</td>\n",
|
||
|
" <td>0.002253</td>\n",
|
||
|
" <td>0.000930</td>\n",
|
||
|
" <td>0.003444</td>\n",
|
||
|
" <td>0.001362</td>\n",
|
||
|
" <td>0.011760</td>\n",
|
||
|
" <td>0.496724</td>\n",
|
||
|
" <td>0.021209</td>\n",
|
||
|
" <td>0.482821</td>\n",
|
||
|
" <td>0.059885</td>\n",
|
||
|
" <td>2.232578</td>\n",
|
||
|
" <td>0.994487</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_U-KNN</td>\n",
|
||
|
" <td>1.023495</td>\n",
|
||
|
" <td>0.807913</td>\n",
|
||
|
" <td>0.000742</td>\n",
|
||
|
" <td>0.000205</td>\n",
|
||
|
" <td>0.000305</td>\n",
|
||
|
" <td>0.000449</td>\n",
|
||
|
" <td>0.000536</td>\n",
|
||
|
" <td>0.000198</td>\n",
|
||
|
" <td>0.000845</td>\n",
|
||
|
" <td>0.000274</td>\n",
|
||
|
" <td>0.002744</td>\n",
|
||
|
" <td>0.496441</td>\n",
|
||
|
" <td>0.007423</td>\n",
|
||
|
" <td>0.602121</td>\n",
|
||
|
" <td>0.010823</td>\n",
|
||
|
" <td>2.089186</td>\n",
|
||
|
" <td>0.995706</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_TopRated</td>\n",
|
||
|
" <td>1.033085</td>\n",
|
||
|
" <td>0.822057</td>\n",
|
||
|
" <td>0.000954</td>\n",
|
||
|
" <td>0.000188</td>\n",
|
||
|
" <td>0.000298</td>\n",
|
||
|
" <td>0.000481</td>\n",
|
||
|
" <td>0.000644</td>\n",
|
||
|
" <td>0.000223</td>\n",
|
||
|
" <td>0.001043</td>\n",
|
||
|
" <td>0.000335</td>\n",
|
||
|
" <td>0.003348</td>\n",
|
||
|
" <td>0.496433</td>\n",
|
||
|
" <td>0.009544</td>\n",
|
||
|
" <td>0.699046</td>\n",
|
||
|
" <td>0.005051</td>\n",
|
||
|
" <td>1.945910</td>\n",
|
||
|
" <td>0.995669</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_BaselineUI</td>\n",
|
||
|
" <td>0.967585</td>\n",
|
||
|
" <td>0.762740</td>\n",
|
||
|
" <td>0.000954</td>\n",
|
||
|
" <td>0.000170</td>\n",
|
||
|
" <td>0.000278</td>\n",
|
||
|
" <td>0.000463</td>\n",
|
||
|
" <td>0.000644</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.000752</td>\n",
|
||
|
" <td>0.000168</td>\n",
|
||
|
" <td>0.001677</td>\n",
|
||
|
" <td>0.496424</td>\n",
|
||
|
" <td>0.009544</td>\n",
|
||
|
" <td>0.600530</td>\n",
|
||
|
" <td>0.005051</td>\n",
|
||
|
" <td>1.803126</td>\n",
|
||
|
" <td>0.996380</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_IKNN</td>\n",
|
||
|
" <td>1.018363</td>\n",
|
||
|
" <td>0.808793</td>\n",
|
||
|
" <td>0.000318</td>\n",
|
||
|
" <td>0.000108</td>\n",
|
||
|
" <td>0.000140</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.000000</td>\n",
|
||
|
" <td>0.000000</td>\n",
|
||
|
" <td>0.000214</td>\n",
|
||
|
" <td>0.000037</td>\n",
|
||
|
" <td>0.000368</td>\n",
|
||
|
" <td>0.496391</td>\n",
|
||
|
" <td>0.003181</td>\n",
|
||
|
" <td>0.392153</td>\n",
|
||
|
" <td>0.115440</td>\n",
|
||
|
" <td>4.174741</td>\n",
|
||
|
" <td>0.965327</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Model RMSE MAE precision recall F_1 \\\n",
|
||
|
"0 Self_RP3Beta 3.702446 3.527273 0.282185 0.192092 0.186749 \n",
|
||
|
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
|
||
|
"0 Ready_SVD 0.952784 0.750597 0.095228 0.047497 0.053142 \n",
|
||
|
"0 Self_SVDBaseline 0.913380 0.719974 0.105726 0.045055 0.054233 \n",
|
||
|
"0 Self_SVD 0.914400 0.718047 0.103393 0.043404 0.052920 \n",
|
||
|
"0 Ready_SVDBiased 0.940375 0.742264 0.092153 0.039645 0.046804 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
||
|
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
|
||
|
"0 Ready_Random 1.518551 1.218784 0.050583 0.024085 0.027323 \n",
|
||
|
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \n",
|
||
|
"0 Ready_U-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
|
||
|
"0 Ready_I-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
|
||
|
"0 Ready_U-KNN 1.023495 0.807913 0.000742 0.000205 0.000305 \n",
|
||
|
"0 Self_TopRated 1.033085 0.822057 0.000954 0.000188 0.000298 \n",
|
||
|
"0 Self_BaselineUI 0.967585 0.762740 0.000954 0.000170 0.000278 \n",
|
||
|
"0 Self_IKNN 1.018363 0.808793 0.000318 0.000108 0.000140 \n",
|
||
|
"\n",
|
||
|
" F_05 precision_super recall_super NDCG mAP MRR \\\n",
|
||
|
"0 0.216980 0.204185 0.240096 0.339114 0.204905 0.572157 \n",
|
||
|
"0 0.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
|
||
|
"0 0.067082 0.084871 0.076457 0.109075 0.050124 0.241366 \n",
|
||
|
"0 0.071579 0.096674 0.075899 0.119979 0.059709 0.251389 \n",
|
||
|
"0 0.070119 0.093455 0.074901 0.107441 0.050770 0.200719 \n",
|
||
|
"0 0.061886 0.079399 0.055967 0.102017 0.047972 0.216876 \n",
|
||
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
||
|
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
|
||
|
"0 0.034826 0.031223 0.026436 0.054902 0.020652 0.137928 \n",
|
||
|
"0 0.016046 0.021137 0.009522 0.024214 0.008958 0.048068 \n",
|
||
|
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
|
||
|
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
|
||
|
"0 0.000449 0.000536 0.000198 0.000845 0.000274 0.002744 \n",
|
||
|
"0 0.000481 0.000644 0.000223 0.001043 0.000335 0.003348 \n",
|
||
|
"0 0.000463 0.000644 0.000189 0.000752 0.000168 0.001677 \n",
|
||
|
"0 0.000189 0.000000 0.000000 0.000214 0.000037 0.000368 \n",
|
||
|
"\n",
|
||
|
" LAUC HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.593544 0.875928 1.000000 0.077201 3.875892 0.974947 \n",
|
||
|
"0 0.555546 0.765642 1.000000 0.038961 3.159079 0.987317 \n",
|
||
|
"0 0.520459 0.499470 0.992047 0.217893 4.405246 0.953484 \n",
|
||
|
"0 0.519270 0.476140 0.999788 0.115440 3.578129 0.980463 \n",
|
||
|
"0 0.518433 0.477200 0.866384 0.145743 3.860721 0.972299 \n",
|
||
|
"0 0.516515 0.441145 0.997455 0.167388 4.235348 0.962085 \n",
|
||
|
"0 0.515501 0.437964 1.000000 0.033911 2.836513 0.991139 \n",
|
||
|
"0 0.509546 0.384942 1.000000 0.025974 2.711772 0.992003 \n",
|
||
|
"0 0.508570 0.353128 0.987699 0.183261 5.093805 0.908215 \n",
|
||
|
"0 0.499885 0.154825 0.402333 0.434343 5.133650 0.877999 \n",
|
||
|
"0 0.496724 0.021209 0.482821 0.059885 2.232578 0.994487 \n",
|
||
|
"0 0.496724 0.021209 0.482821 0.059885 2.232578 0.994487 \n",
|
||
|
"0 0.496441 0.007423 0.602121 0.010823 2.089186 0.995706 \n",
|
||
|
"0 0.496433 0.009544 0.699046 0.005051 1.945910 0.995669 \n",
|
||
|
"0 0.496424 0.009544 0.600530 0.005051 1.803126 0.996380 \n",
|
||
|
"0 0.496391 0.003181 0.392153 0.115440 4.174741 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 37,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import imp\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\n",
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"dir_path=\"Recommendations generated/ml-100k/\"\n",
|
||
|
"super_reactions=[4,5]\n",
|
||
|
"test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
|
||
|
"\n",
|
||
|
"ev.evaluate_all(test, dir_path, super_reactions)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Embeddings"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 24,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[1, 2],\n",
|
||
|
" [3, 4]])"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[0.4472136 , 0.89442719],\n",
|
||
|
" [0.6 , 0.8 ]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 24,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"x=np.array([[1,2],[3,4]])\n",
|
||
|
"display(x)\n",
|
||
|
"x/np.linalg.norm(x, axis=1)[:,None]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 33,
|
||
|
"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>code</th>\n",
|
||
|
" <th>score</th>\n",
|
||
|
" <th>item_id</th>\n",
|
||
|
" <th>id</th>\n",
|
||
|
" <th>title</th>\n",
|
||
|
" <th>genres</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>257</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>258</td>\n",
|
||
|
" <td>258</td>\n",
|
||
|
" <td>Contact (1997)</td>\n",
|
||
|
" <td>Drama, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <td>221</td>\n",
|
||
|
" <td>0.739090</td>\n",
|
||
|
" <td>222</td>\n",
|
||
|
" <td>222</td>\n",
|
||
|
" <td>Star Trek: First Contact (1996)</td>\n",
|
||
|
" <td>Action, Adventure, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <td>63</td>\n",
|
||
|
" <td>0.736794</td>\n",
|
||
|
" <td>64</td>\n",
|
||
|
" <td>64</td>\n",
|
||
|
" <td>Shawshank Redemption, The (1994)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3</th>\n",
|
||
|
" <td>1162</td>\n",
|
||
|
" <td>0.736777</td>\n",
|
||
|
" <td>1163</td>\n",
|
||
|
" <td>1163</td>\n",
|
||
|
" <td>Portrait of a Lady, The (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4</th>\n",
|
||
|
" <td>125</td>\n",
|
||
|
" <td>0.736246</td>\n",
|
||
|
" <td>126</td>\n",
|
||
|
" <td>126</td>\n",
|
||
|
" <td>Spitfire Grill, The (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>5</th>\n",
|
||
|
" <td>309</td>\n",
|
||
|
" <td>0.734523</td>\n",
|
||
|
" <td>310</td>\n",
|
||
|
" <td>310</td>\n",
|
||
|
" <td>Rainmaker, The (1997)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>6</th>\n",
|
||
|
" <td>1605</td>\n",
|
||
|
" <td>0.733826</td>\n",
|
||
|
" <td>1606</td>\n",
|
||
|
" <td>1606</td>\n",
|
||
|
" <td>Deceiver (1997)</td>\n",
|
||
|
" <td>Crime</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>7</th>\n",
|
||
|
" <td>238</td>\n",
|
||
|
" <td>0.731338</td>\n",
|
||
|
" <td>239</td>\n",
|
||
|
" <td>239</td>\n",
|
||
|
" <td>Sneakers (1992)</td>\n",
|
||
|
" <td>Crime, Drama, Sci-Fi</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>8</th>\n",
|
||
|
" <td>222</td>\n",
|
||
|
" <td>0.724939</td>\n",
|
||
|
" <td>223</td>\n",
|
||
|
" <td>223</td>\n",
|
||
|
" <td>Sling Blade (1996)</td>\n",
|
||
|
" <td>Drama, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>9</th>\n",
|
||
|
" <td>266</td>\n",
|
||
|
" <td>0.724812</td>\n",
|
||
|
" <td>267</td>\n",
|
||
|
" <td>267</td>\n",
|
||
|
" <td>unknown</td>\n",
|
||
|
" <td>unknown</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" code score item_id id title \\\n",
|
||
|
"0 257 1.000000 258 258 Contact (1997) \n",
|
||
|
"1 221 0.739090 222 222 Star Trek: First Contact (1996) \n",
|
||
|
"2 63 0.736794 64 64 Shawshank Redemption, The (1994) \n",
|
||
|
"3 1162 0.736777 1163 1163 Portrait of a Lady, The (1996) \n",
|
||
|
"4 125 0.736246 126 126 Spitfire Grill, The (1996) \n",
|
||
|
"5 309 0.734523 310 310 Rainmaker, The (1997) \n",
|
||
|
"6 1605 0.733826 1606 1606 Deceiver (1997) \n",
|
||
|
"7 238 0.731338 239 239 Sneakers (1992) \n",
|
||
|
"8 222 0.724939 223 223 Sling Blade (1996) \n",
|
||
|
"9 266 0.724812 267 267 unknown \n",
|
||
|
"\n",
|
||
|
" genres \n",
|
||
|
"0 Drama, Sci-Fi \n",
|
||
|
"1 Action, Adventure, Sci-Fi \n",
|
||
|
"2 Drama \n",
|
||
|
"3 Drama \n",
|
||
|
"4 Drama \n",
|
||
|
"5 Drama \n",
|
||
|
"6 Crime \n",
|
||
|
"7 Crime, Drama, Sci-Fi \n",
|
||
|
"8 Drama, Thriller \n",
|
||
|
"9 unknown "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 33,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"item=random.choice(list(set(train_ui.indices)))\n",
|
||
|
"\n",
|
||
|
"embeddings_norm=model.Qi/np.linalg.norm(model.Qi, axis=1)[:,None] # we do not mean-center here\n",
|
||
|
"# omitting normalization also makes sense, but items with a greater magnitude will be recommended more often\n",
|
||
|
"\n",
|
||
|
"similarity_scores=np.dot(embeddings_norm,embeddings_norm[item].T)\n",
|
||
|
"top_similar_items=pd.DataFrame(enumerate(similarity_scores), columns=['code', 'score'])\\\n",
|
||
|
".sort_values(by=['score'], ascending=[False])[:10]\n",
|
||
|
"\n",
|
||
|
"top_similar_items['item_id']=top_similar_items['code'].apply(lambda x: item_code_id[x])\n",
|
||
|
"\n",
|
||
|
"items=pd.read_csv('./Datasets/ml-100k/movies.csv')\n",
|
||
|
"\n",
|
||
|
"result=pd.merge(top_similar_items, items, left_on='item_id', right_on='id')\n",
|
||
|
"\n",
|
||
|
"result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# project task 5: implement SVD on top baseline (as it is in Surprise library)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 34,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# making changes to our implementation by considering additional parameters in the gradient descent procedure \n",
|
||
|
"# seems to be the fastest option\n",
|
||
|
"# please save the output in 'Recommendations generated/ml-100k/Self_SVDBaseline_reco.csv' and\n",
|
||
|
"# 'Recommendations generated/ml-100k/Self_SVDBaseline_estimations.csv'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Ready-made SVD - Surprise implementation"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### SVD"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 39,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Generating predictions...\n",
|
||
|
"Generating top N recommendations...\n",
|
||
|
"Generating predictions...\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import helpers\n",
|
||
|
"import surprise as sp\n",
|
||
|
"import imp\n",
|
||
|
"imp.reload(helpers)\n",
|
||
|
"\n",
|
||
|
"algo = sp.SVD(biased=False) # to use unbiased version\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_SVD_reco.csv',\n",
|
||
|
" estimations_path='Recommendations generated/ml-100k/Ready_SVD_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### SVD biased - on top baseline"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Generating predictions...\n",
|
||
|
"Generating top N recommendations...\n",
|
||
|
"Generating predictions...\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import helpers\n",
|
||
|
"import surprise as sp\n",
|
||
|
"import imp\n",
|
||
|
"imp.reload(helpers)\n",
|
||
|
"\n",
|
||
|
"algo = sp.SVD() # default is biased=True\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_SVDBiased_reco.csv',\n",
|
||
|
" estimations_path='Recommendations generated/ml-100k/Ready_SVDBiased_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 40,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 4850.60it/s]\n",
|
||
|
"943it [00:00, 4963.77it/s]\n",
|
||
|
"943it [00:00, 4500.32it/s]\n",
|
||
|
"943it [00:00, 5033.32it/s]\n",
|
||
|
"943it [00:00, 4491.41it/s]\n",
|
||
|
"943it [00:00, 5213.78it/s]\n",
|
||
|
"943it [00:00, 4930.11it/s]\n",
|
||
|
"943it [00:00, 4835.44it/s]\n",
|
||
|
"943it [00:00, 4567.62it/s]\n",
|
||
|
"943it [00:00, 4836.97it/s]\n",
|
||
|
"943it [00:00, 3965.34it/s]\n",
|
||
|
"943it [00:00, 4790.98it/s]\n",
|
||
|
"943it [00:00, 4721.85it/s]\n",
|
||
|
"943it [00:00, 4756.99it/s]\n",
|
||
|
"943it [00:00, 5004.97it/s]\n",
|
||
|
"943it [00:00, 4844.54it/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>Model</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>Self_RP3Beta</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>Self_TopPop</td>\n",
|
||
|
" <td>2.508258</td>\n",
|
||
|
" <td>2.217909</td>\n",
|
||
|
" <td>0.188865</td>\n",
|
||
|
" <td>0.116919</td>\n",
|
||
|
" <td>0.118732</td>\n",
|
||
|
" <td>0.141584</td>\n",
|
||
|
" <td>0.130472</td>\n",
|
||
|
" <td>0.137473</td>\n",
|
||
|
" <td>0.214651</td>\n",
|
||
|
" <td>0.111707</td>\n",
|
||
|
" <td>0.400939</td>\n",
|
||
|
" <td>0.555546</td>\n",
|
||
|
" <td>0.765642</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.038961</td>\n",
|
||
|
" <td>3.159079</td>\n",
|
||
|
" <td>0.987317</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVD</td>\n",
|
||
|
" <td>0.951985</td>\n",
|
||
|
" <td>0.749904</td>\n",
|
||
|
" <td>0.105832</td>\n",
|
||
|
" <td>0.054287</td>\n",
|
||
|
" <td>0.059099</td>\n",
|
||
|
" <td>0.074448</td>\n",
|
||
|
" <td>0.093562</td>\n",
|
||
|
" <td>0.085108</td>\n",
|
||
|
" <td>0.124663</td>\n",
|
||
|
" <td>0.060089</td>\n",
|
||
|
" <td>0.275660</td>\n",
|
||
|
" <td>0.523903</td>\n",
|
||
|
" <td>0.527041</td>\n",
|
||
|
" <td>0.999682</td>\n",
|
||
|
" <td>0.214286</td>\n",
|
||
|
" <td>4.410890</td>\n",
|
||
|
" <td>0.953748</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVDBaseline</td>\n",
|
||
|
" <td>0.913380</td>\n",
|
||
|
" <td>0.719974</td>\n",
|
||
|
" <td>0.105726</td>\n",
|
||
|
" <td>0.045055</td>\n",
|
||
|
" <td>0.054233</td>\n",
|
||
|
" <td>0.071579</td>\n",
|
||
|
" <td>0.096674</td>\n",
|
||
|
" <td>0.075899</td>\n",
|
||
|
" <td>0.119979</td>\n",
|
||
|
" <td>0.059709</td>\n",
|
||
|
" <td>0.251389</td>\n",
|
||
|
" <td>0.519270</td>\n",
|
||
|
" <td>0.476140</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.115440</td>\n",
|
||
|
" <td>3.578129</td>\n",
|
||
|
" <td>0.980463</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVD</td>\n",
|
||
|
" <td>0.914400</td>\n",
|
||
|
" <td>0.718047</td>\n",
|
||
|
" <td>0.103393</td>\n",
|
||
|
" <td>0.043404</td>\n",
|
||
|
" <td>0.052920</td>\n",
|
||
|
" <td>0.070119</td>\n",
|
||
|
" <td>0.093455</td>\n",
|
||
|
" <td>0.074901</td>\n",
|
||
|
" <td>0.107441</td>\n",
|
||
|
" <td>0.050770</td>\n",
|
||
|
" <td>0.200719</td>\n",
|
||
|
" <td>0.518433</td>\n",
|
||
|
" <td>0.477200</td>\n",
|
||
|
" <td>0.866384</td>\n",
|
||
|
" <td>0.145743</td>\n",
|
||
|
" <td>3.860721</td>\n",
|
||
|
" <td>0.972299</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVDBiased</td>\n",
|
||
|
" <td>0.940375</td>\n",
|
||
|
" <td>0.742264</td>\n",
|
||
|
" <td>0.092153</td>\n",
|
||
|
" <td>0.039645</td>\n",
|
||
|
" <td>0.046804</td>\n",
|
||
|
" <td>0.061886</td>\n",
|
||
|
" <td>0.079399</td>\n",
|
||
|
" <td>0.055967</td>\n",
|
||
|
" <td>0.102017</td>\n",
|
||
|
" <td>0.047972</td>\n",
|
||
|
" <td>0.216876</td>\n",
|
||
|
" <td>0.516515</td>\n",
|
||
|
" <td>0.441145</td>\n",
|
||
|
" <td>0.997455</td>\n",
|
||
|
" <td>0.167388</td>\n",
|
||
|
" <td>4.235348</td>\n",
|
||
|
" <td>0.962085</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_Baseline</td>\n",
|
||
|
" <td>0.949459</td>\n",
|
||
|
" <td>0.752487</td>\n",
|
||
|
" <td>0.091410</td>\n",
|
||
|
" <td>0.037652</td>\n",
|
||
|
" <td>0.046030</td>\n",
|
||
|
" <td>0.061286</td>\n",
|
||
|
" <td>0.079614</td>\n",
|
||
|
" <td>0.056463</td>\n",
|
||
|
" <td>0.095957</td>\n",
|
||
|
" <td>0.043178</td>\n",
|
||
|
" <td>0.198193</td>\n",
|
||
|
" <td>0.515501</td>\n",
|
||
|
" <td>0.437964</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.033911</td>\n",
|
||
|
" <td>2.836513</td>\n",
|
||
|
" <td>0.991139</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_GlobalAvg</td>\n",
|
||
|
" <td>1.125760</td>\n",
|
||
|
" <td>0.943534</td>\n",
|
||
|
" <td>0.061188</td>\n",
|
||
|
" <td>0.025968</td>\n",
|
||
|
" <td>0.031383</td>\n",
|
||
|
" <td>0.041343</td>\n",
|
||
|
" <td>0.040558</td>\n",
|
||
|
" <td>0.032107</td>\n",
|
||
|
" <td>0.067695</td>\n",
|
||
|
" <td>0.027470</td>\n",
|
||
|
" <td>0.171187</td>\n",
|
||
|
" <td>0.509546</td>\n",
|
||
|
" <td>0.384942</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.025974</td>\n",
|
||
|
" <td>2.711772</td>\n",
|
||
|
" <td>0.992003</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_Random</td>\n",
|
||
|
" <td>1.518551</td>\n",
|
||
|
" <td>1.218784</td>\n",
|
||
|
" <td>0.050583</td>\n",
|
||
|
" <td>0.024085</td>\n",
|
||
|
" <td>0.027323</td>\n",
|
||
|
" <td>0.034826</td>\n",
|
||
|
" <td>0.031223</td>\n",
|
||
|
" <td>0.026436</td>\n",
|
||
|
" <td>0.054902</td>\n",
|
||
|
" <td>0.020652</td>\n",
|
||
|
" <td>0.137928</td>\n",
|
||
|
" <td>0.508570</td>\n",
|
||
|
" <td>0.353128</td>\n",
|
||
|
" <td>0.987699</td>\n",
|
||
|
" <td>0.183261</td>\n",
|
||
|
" <td>5.093805</td>\n",
|
||
|
" <td>0.908215</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_I-KNN</td>\n",
|
||
|
" <td>1.030386</td>\n",
|
||
|
" <td>0.813067</td>\n",
|
||
|
" <td>0.026087</td>\n",
|
||
|
" <td>0.006908</td>\n",
|
||
|
" <td>0.010593</td>\n",
|
||
|
" <td>0.016046</td>\n",
|
||
|
" <td>0.021137</td>\n",
|
||
|
" <td>0.009522</td>\n",
|
||
|
" <td>0.024214</td>\n",
|
||
|
" <td>0.008958</td>\n",
|
||
|
" <td>0.048068</td>\n",
|
||
|
" <td>0.499885</td>\n",
|
||
|
" <td>0.154825</td>\n",
|
||
|
" <td>0.402333</td>\n",
|
||
|
" <td>0.434343</td>\n",
|
||
|
" <td>5.133650</td>\n",
|
||
|
" <td>0.877999</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_U-KNNBaseline</td>\n",
|
||
|
" <td>0.935327</td>\n",
|
||
|
" <td>0.737424</td>\n",
|
||
|
" <td>0.002545</td>\n",
|
||
|
" <td>0.000755</td>\n",
|
||
|
" <td>0.001105</td>\n",
|
||
|
" <td>0.001602</td>\n",
|
||
|
" <td>0.002253</td>\n",
|
||
|
" <td>0.000930</td>\n",
|
||
|
" <td>0.003444</td>\n",
|
||
|
" <td>0.001362</td>\n",
|
||
|
" <td>0.011760</td>\n",
|
||
|
" <td>0.496724</td>\n",
|
||
|
" <td>0.021209</td>\n",
|
||
|
" <td>0.482821</td>\n",
|
||
|
" <td>0.059885</td>\n",
|
||
|
" <td>2.232578</td>\n",
|
||
|
" <td>0.994487</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_I-KNNBaseline</td>\n",
|
||
|
" <td>0.935327</td>\n",
|
||
|
" <td>0.737424</td>\n",
|
||
|
" <td>0.002545</td>\n",
|
||
|
" <td>0.000755</td>\n",
|
||
|
" <td>0.001105</td>\n",
|
||
|
" <td>0.001602</td>\n",
|
||
|
" <td>0.002253</td>\n",
|
||
|
" <td>0.000930</td>\n",
|
||
|
" <td>0.003444</td>\n",
|
||
|
" <td>0.001362</td>\n",
|
||
|
" <td>0.011760</td>\n",
|
||
|
" <td>0.496724</td>\n",
|
||
|
" <td>0.021209</td>\n",
|
||
|
" <td>0.482821</td>\n",
|
||
|
" <td>0.059885</td>\n",
|
||
|
" <td>2.232578</td>\n",
|
||
|
" <td>0.994487</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_U-KNN</td>\n",
|
||
|
" <td>1.023495</td>\n",
|
||
|
" <td>0.807913</td>\n",
|
||
|
" <td>0.000742</td>\n",
|
||
|
" <td>0.000205</td>\n",
|
||
|
" <td>0.000305</td>\n",
|
||
|
" <td>0.000449</td>\n",
|
||
|
" <td>0.000536</td>\n",
|
||
|
" <td>0.000198</td>\n",
|
||
|
" <td>0.000845</td>\n",
|
||
|
" <td>0.000274</td>\n",
|
||
|
" <td>0.002744</td>\n",
|
||
|
" <td>0.496441</td>\n",
|
||
|
" <td>0.007423</td>\n",
|
||
|
" <td>0.602121</td>\n",
|
||
|
" <td>0.010823</td>\n",
|
||
|
" <td>2.089186</td>\n",
|
||
|
" <td>0.995706</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_TopRated</td>\n",
|
||
|
" <td>1.033085</td>\n",
|
||
|
" <td>0.822057</td>\n",
|
||
|
" <td>0.000954</td>\n",
|
||
|
" <td>0.000188</td>\n",
|
||
|
" <td>0.000298</td>\n",
|
||
|
" <td>0.000481</td>\n",
|
||
|
" <td>0.000644</td>\n",
|
||
|
" <td>0.000223</td>\n",
|
||
|
" <td>0.001043</td>\n",
|
||
|
" <td>0.000335</td>\n",
|
||
|
" <td>0.003348</td>\n",
|
||
|
" <td>0.496433</td>\n",
|
||
|
" <td>0.009544</td>\n",
|
||
|
" <td>0.699046</td>\n",
|
||
|
" <td>0.005051</td>\n",
|
||
|
" <td>1.945910</td>\n",
|
||
|
" <td>0.995669</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_BaselineUI</td>\n",
|
||
|
" <td>0.967585</td>\n",
|
||
|
" <td>0.762740</td>\n",
|
||
|
" <td>0.000954</td>\n",
|
||
|
" <td>0.000170</td>\n",
|
||
|
" <td>0.000278</td>\n",
|
||
|
" <td>0.000463</td>\n",
|
||
|
" <td>0.000644</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.000752</td>\n",
|
||
|
" <td>0.000168</td>\n",
|
||
|
" <td>0.001677</td>\n",
|
||
|
" <td>0.496424</td>\n",
|
||
|
" <td>0.009544</td>\n",
|
||
|
" <td>0.600530</td>\n",
|
||
|
" <td>0.005051</td>\n",
|
||
|
" <td>1.803126</td>\n",
|
||
|
" <td>0.996380</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_IKNN</td>\n",
|
||
|
" <td>1.018363</td>\n",
|
||
|
" <td>0.808793</td>\n",
|
||
|
" <td>0.000318</td>\n",
|
||
|
" <td>0.000108</td>\n",
|
||
|
" <td>0.000140</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.000000</td>\n",
|
||
|
" <td>0.000000</td>\n",
|
||
|
" <td>0.000214</td>\n",
|
||
|
" <td>0.000037</td>\n",
|
||
|
" <td>0.000368</td>\n",
|
||
|
" <td>0.496391</td>\n",
|
||
|
" <td>0.003181</td>\n",
|
||
|
" <td>0.392153</td>\n",
|
||
|
" <td>0.115440</td>\n",
|
||
|
" <td>4.174741</td>\n",
|
||
|
" <td>0.965327</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Model RMSE MAE precision recall F_1 \\\n",
|
||
|
"0 Self_RP3Beta 3.702446 3.527273 0.282185 0.192092 0.186749 \n",
|
||
|
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
|
||
|
"0 Ready_SVD 0.951985 0.749904 0.105832 0.054287 0.059099 \n",
|
||
|
"0 Self_SVDBaseline 0.913380 0.719974 0.105726 0.045055 0.054233 \n",
|
||
|
"0 Self_SVD 0.914400 0.718047 0.103393 0.043404 0.052920 \n",
|
||
|
"0 Ready_SVDBiased 0.940375 0.742264 0.092153 0.039645 0.046804 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
||
|
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
|
||
|
"0 Ready_Random 1.518551 1.218784 0.050583 0.024085 0.027323 \n",
|
||
|
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \n",
|
||
|
"0 Ready_U-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
|
||
|
"0 Ready_I-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
|
||
|
"0 Ready_U-KNN 1.023495 0.807913 0.000742 0.000205 0.000305 \n",
|
||
|
"0 Self_TopRated 1.033085 0.822057 0.000954 0.000188 0.000298 \n",
|
||
|
"0 Self_BaselineUI 0.967585 0.762740 0.000954 0.000170 0.000278 \n",
|
||
|
"0 Self_IKNN 1.018363 0.808793 0.000318 0.000108 0.000140 \n",
|
||
|
"\n",
|
||
|
" F_05 precision_super recall_super NDCG mAP MRR \\\n",
|
||
|
"0 0.216980 0.204185 0.240096 0.339114 0.204905 0.572157 \n",
|
||
|
"0 0.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
|
||
|
"0 0.074448 0.093562 0.085108 0.124663 0.060089 0.275660 \n",
|
||
|
"0 0.071579 0.096674 0.075899 0.119979 0.059709 0.251389 \n",
|
||
|
"0 0.070119 0.093455 0.074901 0.107441 0.050770 0.200719 \n",
|
||
|
"0 0.061886 0.079399 0.055967 0.102017 0.047972 0.216876 \n",
|
||
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
||
|
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
|
||
|
"0 0.034826 0.031223 0.026436 0.054902 0.020652 0.137928 \n",
|
||
|
"0 0.016046 0.021137 0.009522 0.024214 0.008958 0.048068 \n",
|
||
|
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
|
||
|
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
|
||
|
"0 0.000449 0.000536 0.000198 0.000845 0.000274 0.002744 \n",
|
||
|
"0 0.000481 0.000644 0.000223 0.001043 0.000335 0.003348 \n",
|
||
|
"0 0.000463 0.000644 0.000189 0.000752 0.000168 0.001677 \n",
|
||
|
"0 0.000189 0.000000 0.000000 0.000214 0.000037 0.000368 \n",
|
||
|
"\n",
|
||
|
" LAUC HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.593544 0.875928 1.000000 0.077201 3.875892 0.974947 \n",
|
||
|
"0 0.555546 0.765642 1.000000 0.038961 3.159079 0.987317 \n",
|
||
|
"0 0.523903 0.527041 0.999682 0.214286 4.410890 0.953748 \n",
|
||
|
"0 0.519270 0.476140 0.999788 0.115440 3.578129 0.980463 \n",
|
||
|
"0 0.518433 0.477200 0.866384 0.145743 3.860721 0.972299 \n",
|
||
|
"0 0.516515 0.441145 0.997455 0.167388 4.235348 0.962085 \n",
|
||
|
"0 0.515501 0.437964 1.000000 0.033911 2.836513 0.991139 \n",
|
||
|
"0 0.509546 0.384942 1.000000 0.025974 2.711772 0.992003 \n",
|
||
|
"0 0.508570 0.353128 0.987699 0.183261 5.093805 0.908215 \n",
|
||
|
"0 0.499885 0.154825 0.402333 0.434343 5.133650 0.877999 \n",
|
||
|
"0 0.496724 0.021209 0.482821 0.059885 2.232578 0.994487 \n",
|
||
|
"0 0.496724 0.021209 0.482821 0.059885 2.232578 0.994487 \n",
|
||
|
"0 0.496441 0.007423 0.602121 0.010823 2.089186 0.995706 \n",
|
||
|
"0 0.496433 0.009544 0.699046 0.005051 1.945910 0.995669 \n",
|
||
|
"0 0.496424 0.009544 0.600530 0.005051 1.803126 0.996380 \n",
|
||
|
"0 0.496391 0.003181 0.392153 0.115440 4.174741 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 40,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import imp\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\n",
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"dir_path=\"Recommendations generated/ml-100k/\"\n",
|
||
|
"super_reactions=[4,5]\n",
|
||
|
"test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
|
||
|
"\n",
|
||
|
"ev.evaluate_all(test, dir_path, super_reactions)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"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.6.9"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|