1404 lines
74 KiB
Plaintext
1404 lines
74 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",
|
|
"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",
|
|
"(\n",
|
|
" train_ui,\n",
|
|
" test_ui,\n",
|
|
" user_code_id,\n",
|
|
" user_id_code,\n",
|
|
" item_code_id,\n",
|
|
" item_id_code,\n",
|
|
") = helpers.data_to_csr(train_read, test_read)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Done similarly to https://github.com/albertauyeung/matrix-factorization-in-python\n",
|
|
"from tqdm import tqdm\n",
|
|
"\n",
|
|
"\n",
|
|
"class SVD:\n",
|
|
" def __init__(self, train_ui, learning_rate, regularization, nb_factors, iterations):\n",
|
|
" self.train_ui = train_ui\n",
|
|
" self.uir = list(\n",
|
|
" zip(*[train_ui.nonzero()[0], train_ui.nonzero()[1], train_ui.data])\n",
|
|
" )\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(\n",
|
|
" loc=0, scale=1.0 / self.nb_factors, size=(self.nb_users, self.nb_factors)\n",
|
|
" )\n",
|
|
" self.Qi = np.random.normal(\n",
|
|
" loc=0, scale=1.0 / self.nb_factors, size=(self.nb_items, self.nb_factors)\n",
|
|
" )\n",
|
|
"\n",
|
|
" def train(self, test_ui=None):\n",
|
|
" if test_ui != None:\n",
|
|
" self.test_uir = list(\n",
|
|
" zip(*[test_ui.nonzero()[0], test_ui.nonzero()[1], test_ui.data])\n",
|
|
" )\n",
|
|
"\n",
|
|
" self.learning_process = []\n",
|
|
" pbar = tqdm(range(self.iterations))\n",
|
|
" for i in pbar:\n",
|
|
" pbar.set_description(\n",
|
|
" f\"Epoch {i} RMSE: {self.learning_process[-1][1] if i>0 else 0}. Training epoch {i+1}...\"\n",
|
|
" )\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(\n",
|
|
" [i + 1, self.RMSE_total(self.uir), self.RMSE_total(self.test_uir)]\n",
|
|
" )\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 * (\n",
|
|
" e * self.Qi[i] - self.regularization * self.Pu[u]\n",
|
|
" )\n",
|
|
" Qi_update = self.learning_rate * (\n",
|
|
" e * self.Pu[u] - self.regularization * self.Qi[i]\n",
|
|
" )\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 = 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[\n",
|
|
" self.train_ui.indptr[nb_user] : self.train_ui.indptr[nb_user + 1]\n",
|
|
" ]\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(\n",
|
|
" [\n",
|
|
" user_code_id[user],\n",
|
|
" item_code_id[item],\n",
|
|
" self.estimations[user, item]\n",
|
|
" if not np.isnan(self.estimations[user, item])\n",
|
|
" else 1,\n",
|
|
" ]\n",
|
|
" )\n",
|
|
" return result"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Epoch 39 RMSE: 0.7477090330529405. Training epoch 40...: 100%|██████████| 40/40 [01:03<00:00, 1.59s/it]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"model = SVD(\n",
|
|
" train_ui, learning_rate=0.005, regularization=0.02, nb_factors=100, iterations=40\n",
|
|
")\n",
|
|
"model.train(test_ui)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<matplotlib.legend.Legend at 0x7fdc5a9a2370>"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
},
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAba0lEQVR4nO3de3RV9Z338fc3IZCEIAkhVYZwsZapjoihxNtIO1jqo1DXSF0uizNPpV2dMlqsONVa6+Pq2Ge005Fp7eCljD7S6jxdxel4rcvq4wW8tWIDBhTQgqMtEWrCLYByEfJ9/tjnkJPDSXJOcpJ9zt6f11q/tffZe59zvmzjZ+/z2zdzd0REpPiVhF2AiIjkhwJdRCQiFOgiIhGhQBcRiQgFuohIRAwJ64tHjx7tEydODOvrRUSK0qpVq7a5e12meaEF+sSJE2lqagrr60VEipKZ/aG7eepyERGJCAW6iEhEKNBFRCIitD50ESk+H330ES0tLezfvz/sUiKvvLyc+vp6ysrKsn6PAl1EstbS0sKIESOYOHEiZhZ2OZHl7mzfvp2WlhaOP/74rN+nLhcRydr+/fupra1VmA8wM6O2tjbnX0IKdBHJicJ8cPRlPRddoLe0wNVXw0cfhV2JiEhhKbpA/93v4N/+Db7//bArEREpLEUX6F/4AvzN38DNN8Pq1WFXIyKDadeuXdx11105v2/27Nns2rUr5/d9+ctf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iGsux5qC33dAVOA1xI1vAF8NzG9ENZbd7WFvt7S6pwBPD6Q662gTlsUEZG+K7QuFxER6SMFuohIRCjQRUQiQoEuIhIRCnQRkYhQoIuIRIQCXUQkIv4/uXWfnCx11KgAAAAASUVORK5CYII=\n",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"needs_background": "light"
|
|
},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"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": 5,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<matplotlib.legend.Legend at 0x7fdc6037bb20>"
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
},
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAyqElEQVR4nO3de3zPdf/H8cdrY2bO25yHYYg5DENiOR9TShIuinLJFdFVFFJdKVcHV4Wr80FR/XQuOpFQ5CqHyZnZMMzEmDkP296/P96zhuE7tn2+3+9e99ttN/t+Dt/v67NPPffZ+/P+vN9ijEEppZT38nG6AKWUUvlLg14ppbycBr1SSnk5DXqllPJyGvRKKeXlijhdQE6Cg4NNaGio02UopZTHiI6OPmiMKZ/TOrcM+tDQUFavXu10GUop5TFEZNel1l2x6UZEZorIARHZeIn1IiIzRCRORNaLSLNs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Dzgwecos1lgLXAAWGiM8ehzdInjAc89R9OAR4CMbMvy5fx4StB7o9eB2kAEsA940dFqroKIlAS+AB40xhx1up5rlcPxePQ5MsakG2MigBCgpYg0dLika3KJ4/HIcyQivYADxpjogvg8Twn6/ZntqOfaUw84XM81M8bsz/wPNwN4G2jpdE25kdlO+gXwkTHmy8zFHnuecjoeTz9H5xhjUoCfse3ZHnuOzsl+PB58jtoAt4hIPPAx0FFEPiSfzo+nBP084O7M7+8G5jpYS544dzIz3QZsvNS27ibzxti7wBZjzEvZVnnkebrU8Xj4OSovImUzvy8OdAa24rnnKMfj8dRzZIyZYIwJMcaEAv2BxcaYQeTT+XHHXjdzgPbY4Tr3A08CXwOfAtWB3cAdxhiPubl5iWNqj/1z0wDxwH3n2ubcnYi0BZYBG/irfXEitl3b487TZY5nAJ57jhpjb+b5Yi/oPjXGTBaRIDzzHF3qeD7AQ8/ROSLSHhib2esmX86P2wW9UkqpvOUpTTdKKaWukga9Ukp5OQ16pZTychr0Sinl5TTolVLKy2nQK6WUl9OgV0opL/f/92tLuFEDhXQAAAAASUVORK5CYII=\n",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"needs_background": "light"
|
|
},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"df = pd.DataFrame(\n",
|
|
" model.learning_process[10:], columns=[\"epoch\", \"train_RMSE\", \"test_RMSE\"]\n",
|
|
")\n",
|
|
"plt.plot(\"epoch\", \"train_RMSE\", data=df, color=\"blue\")\n",
|
|
"plt.plot(\"epoch\", \"test_RMSE\", data=df, color=\"green\", linestyle=\"dashed\")\n",
|
|
"plt.legend()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Saving and evaluating recommendations"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"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(\n",
|
|
" \"Recommendations generated/ml-100k/Self_SVD_reco.csv\", index=False, header=False\n",
|
|
")\n",
|
|
"\n",
|
|
"estimations = pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
|
|
"estimations.to_csv(\n",
|
|
" \"Recommendations generated/ml-100k/Self_SVD_estimations.csv\",\n",
|
|
" index=False,\n",
|
|
" header=False,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"943it [00:00, 11138.92it/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.914143</td>\n",
|
|
" <td>0.717131</td>\n",
|
|
" <td>0.101803</td>\n",
|
|
" <td>0.042134</td>\n",
|
|
" <td>0.05161</td>\n",
|
|
" <td>0.068543</td>\n",
|
|
" <td>0.091953</td>\n",
|
|
" <td>0.071255</td>\n",
|
|
" <td>0.104015</td>\n",
|
|
" <td>0.048817</td>\n",
|
|
" <td>0.193027</td>\n",
|
|
" <td>0.517784</td>\n",
|
|
" <td>0.471898</td>\n",
|
|
" <td>0.867232</td>\n",
|
|
" <td>0.147908</td>\n",
|
|
" <td>3.871296</td>\n",
|
|
" <td>0.97182</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" RMSE MAE precision recall F_1 F_05 \\\n",
|
|
"0 0.914143 0.717131 0.101803 0.042134 0.05161 0.068543 \n",
|
|
"\n",
|
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
|
"0 0.091953 0.071255 0.104015 0.048817 0.193027 0.517784 \n",
|
|
"\n",
|
|
" HR Reco in test Test coverage Shannon Gini \n",
|
|
"0 0.471898 0.867232 0.147908 3.871296 0.97182 "
|
|
]
|
|
},
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import evaluation_measures as ev\n",
|
|
"\n",
|
|
"estimations_df = pd.read_csv(\n",
|
|
" \"Recommendations generated/ml-100k/Self_SVD_estimations.csv\", header=None\n",
|
|
")\n",
|
|
"reco = np.loadtxt(\"Recommendations generated/ml-100k/Self_SVD_reco.csv\", delimiter=\",\")\n",
|
|
"\n",
|
|
"ev.evaluate(\n",
|
|
" 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],\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"943it [00:00, 10694.55it/s]\n",
|
|
"943it [00:00, 11600.99it/s]\n",
|
|
"943it [00:00, 11461.54it/s]\n",
|
|
"943it [00:00, 11660.39it/s]\n",
|
|
"943it [00:00, 9872.18it/s]\n",
|
|
"943it [00:00, 11443.77it/s]\n",
|
|
"943it [00:00, 11990.88it/s]\n",
|
|
"943it [00:00, 11615.02it/s]\n",
|
|
"943it [00:00, 11874.78it/s]\n",
|
|
"943it [00:00, 12387.19it/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_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>Self_SVD</td>\n",
|
|
" <td>0.914143</td>\n",
|
|
" <td>0.717131</td>\n",
|
|
" <td>0.101803</td>\n",
|
|
" <td>0.042134</td>\n",
|
|
" <td>0.051610</td>\n",
|
|
" <td>0.068543</td>\n",
|
|
" <td>0.091953</td>\n",
|
|
" <td>0.071255</td>\n",
|
|
" <td>0.104015</td>\n",
|
|
" <td>0.048817</td>\n",
|
|
" <td>0.193027</td>\n",
|
|
" <td>0.517784</td>\n",
|
|
" <td>0.471898</td>\n",
|
|
" <td>0.867232</td>\n",
|
|
" <td>0.147908</td>\n",
|
|
" <td>3.871296</td>\n",
|
|
" <td>0.971820</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>Ready_Random</td>\n",
|
|
" <td>1.521845</td>\n",
|
|
" <td>1.225949</td>\n",
|
|
" <td>0.047190</td>\n",
|
|
" <td>0.020753</td>\n",
|
|
" <td>0.024810</td>\n",
|
|
" <td>0.032269</td>\n",
|
|
" <td>0.029506</td>\n",
|
|
" <td>0.023707</td>\n",
|
|
" <td>0.050075</td>\n",
|
|
" <td>0.018728</td>\n",
|
|
" <td>0.121957</td>\n",
|
|
" <td>0.506893</td>\n",
|
|
" <td>0.329799</td>\n",
|
|
" <td>0.986532</td>\n",
|
|
" <td>0.184704</td>\n",
|
|
" <td>5.099706</td>\n",
|
|
" <td>0.907217</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_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.030712</td>\n",
|
|
" <td>0.820904</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_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
|
|
"0 Self_SVD 0.914143 0.717131 0.101803 0.042134 0.051610 \n",
|
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
|
"0 Ready_Random 1.521845 1.225949 0.047190 0.020753 0.024810 \n",
|
|
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \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.030712 0.820904 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.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
|
|
"0 0.068543 0.091953 0.071255 0.104015 0.048817 0.193027 \n",
|
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
|
"0 0.032269 0.029506 0.023707 0.050075 0.018728 0.121957 \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.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.555546 0.765642 1.000000 0.038961 3.159079 0.987317 \n",
|
|
"0 0.517784 0.471898 0.867232 0.147908 3.871296 0.971820 \n",
|
|
"0 0.515501 0.437964 1.000000 0.033911 2.836513 0.991139 \n",
|
|
"0 0.506893 0.329799 0.986532 0.184704 5.099706 0.907217 \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.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": 8,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"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": 9,
|
|
"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>405</td>\n",
|
|
" <td>1.000000</td>\n",
|
|
" <td>406</td>\n",
|
|
" <td>406</td>\n",
|
|
" <td>Thinner (1996)</td>\n",
|
|
" <td>Horror, Thriller</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>827</td>\n",
|
|
" <td>0.968354</td>\n",
|
|
" <td>828</td>\n",
|
|
" <td>828</td>\n",
|
|
" <td>Alaska (1996)</td>\n",
|
|
" <td>Adventure, Children's</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>818</td>\n",
|
|
" <td>0.967103</td>\n",
|
|
" <td>819</td>\n",
|
|
" <td>819</td>\n",
|
|
" <td>Eddie (1996)</td>\n",
|
|
" <td>Comedy</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>904</td>\n",
|
|
" <td>0.963944</td>\n",
|
|
" <td>905</td>\n",
|
|
" <td>905</td>\n",
|
|
" <td>Great Expectations (1998)</td>\n",
|
|
" <td>Drama, Romance</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>1293</td>\n",
|
|
" <td>0.962779</td>\n",
|
|
" <td>1294</td>\n",
|
|
" <td>1294</td>\n",
|
|
" <td>Ayn Rand: A Sense of Life (1997)</td>\n",
|
|
" <td>Documentary</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>347</td>\n",
|
|
" <td>0.961946</td>\n",
|
|
" <td>348</td>\n",
|
|
" <td>348</td>\n",
|
|
" <td>Desperate Measures (1998)</td>\n",
|
|
" <td>Crime, Drama, Thriller</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>6</th>\n",
|
|
" <td>807</td>\n",
|
|
" <td>0.960952</td>\n",
|
|
" <td>808</td>\n",
|
|
" <td>808</td>\n",
|
|
" <td>Program, The (1993)</td>\n",
|
|
" <td>Action, Drama</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>7</th>\n",
|
|
" <td>560</td>\n",
|
|
" <td>0.960885</td>\n",
|
|
" <td>561</td>\n",
|
|
" <td>561</td>\n",
|
|
" <td>Mary Shelley's Frankenstein (1994)</td>\n",
|
|
" <td>Drama, Horror</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>8</th>\n",
|
|
" <td>1392</td>\n",
|
|
" <td>0.958724</td>\n",
|
|
" <td>1393</td>\n",
|
|
" <td>1393</td>\n",
|
|
" <td>Stag (1997)</td>\n",
|
|
" <td>Action, Thriller</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>9</th>\n",
|
|
" <td>787</td>\n",
|
|
" <td>0.957891</td>\n",
|
|
" <td>788</td>\n",
|
|
" <td>788</td>\n",
|
|
" <td>Relative Fear (1994)</td>\n",
|
|
" <td>Horror, Thriller</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" code score item_id id title \\\n",
|
|
"0 405 1.000000 406 406 Thinner (1996) \n",
|
|
"1 827 0.968354 828 828 Alaska (1996) \n",
|
|
"2 818 0.967103 819 819 Eddie (1996) \n",
|
|
"3 904 0.963944 905 905 Great Expectations (1998) \n",
|
|
"4 1293 0.962779 1294 1294 Ayn Rand: A Sense of Life (1997) \n",
|
|
"5 347 0.961946 348 348 Desperate Measures (1998) \n",
|
|
"6 807 0.960952 808 808 Program, The (1993) \n",
|
|
"7 560 0.960885 561 561 Mary Shelley's Frankenstein (1994) \n",
|
|
"8 1392 0.958724 1393 1393 Stag (1997) \n",
|
|
"9 787 0.957891 788 788 Relative Fear (1994) \n",
|
|
"\n",
|
|
" genres \n",
|
|
"0 Horror, Thriller \n",
|
|
"1 Adventure, Children's \n",
|
|
"2 Comedy \n",
|
|
"3 Drama, Romance \n",
|
|
"4 Documentary \n",
|
|
"5 Crime, Drama, Thriller \n",
|
|
"6 Action, Drama \n",
|
|
"7 Drama, Horror \n",
|
|
"8 Action, Thriller \n",
|
|
"9 Horror, Thriller "
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"item = random.choice(list(set(train_ui.indices)))\n",
|
|
"\n",
|
|
"embeddings_norm = (\n",
|
|
" model.Qi / np.linalg.norm(model.Qi, axis=1)[:, None]\n",
|
|
") # 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(\n",
|
|
" 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(\n",
|
|
" lambda x: item_code_id[x]\n",
|
|
")\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": 10,
|
|
"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": 11,
|
|
"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",
|
|
"\n",
|
|
"algo = sp.SVD(biased=False) # to use unbiased version\n",
|
|
"\n",
|
|
"helpers.ready_made(\n",
|
|
" algo,\n",
|
|
" reco_path=\"Recommendations generated/ml-100k/Ready_SVD_reco.csv\",\n",
|
|
" estimations_path=\"Recommendations generated/ml-100k/Ready_SVD_estimations.csv\",\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### SVD biased - on top baseline"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Generating predictions...\n",
|
|
"Generating top N recommendations...\n",
|
|
"Generating predictions...\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"algo = sp.SVD() # default is biased=True\n",
|
|
"\n",
|
|
"helpers.ready_made(\n",
|
|
" algo,\n",
|
|
" reco_path=\"Recommendations generated/ml-100k/Ready_SVDBiased_reco.csv\",\n",
|
|
" estimations_path=\"Recommendations generated/ml-100k/Ready_SVDBiased_estimations.csv\",\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"943it [00:00, 11249.52it/s]\n",
|
|
"943it [00:00, 10927.13it/s]\n",
|
|
"943it [00:00, 11816.00it/s]\n",
|
|
"943it [00:00, 11204.84it/s]\n",
|
|
"943it [00:00, 11803.13it/s]\n",
|
|
"943it [00:00, 10580.63it/s]\n",
|
|
"943it [00:00, 11843.28it/s]\n",
|
|
"943it [00:00, 12313.76it/s]\n",
|
|
"943it [00:00, 10678.21it/s]\n",
|
|
"943it [00:00, 9772.22it/s]\n",
|
|
"943it [00:00, 10699.52it/s]\n",
|
|
"943it [00:00, 11789.55it/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_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.950347</td>\n",
|
|
" <td>0.749312</td>\n",
|
|
" <td>0.100636</td>\n",
|
|
" <td>0.050514</td>\n",
|
|
" <td>0.055794</td>\n",
|
|
" <td>0.070753</td>\n",
|
|
" <td>0.091202</td>\n",
|
|
" <td>0.082734</td>\n",
|
|
" <td>0.114054</td>\n",
|
|
" <td>0.053200</td>\n",
|
|
" <td>0.248803</td>\n",
|
|
" <td>0.521983</td>\n",
|
|
" <td>0.517497</td>\n",
|
|
" <td>0.992153</td>\n",
|
|
" <td>0.210678</td>\n",
|
|
" <td>4.418683</td>\n",
|
|
" <td>0.952848</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>Self_SVD</td>\n",
|
|
" <td>0.914143</td>\n",
|
|
" <td>0.717131</td>\n",
|
|
" <td>0.101803</td>\n",
|
|
" <td>0.042134</td>\n",
|
|
" <td>0.051610</td>\n",
|
|
" <td>0.068543</td>\n",
|
|
" <td>0.091953</td>\n",
|
|
" <td>0.071255</td>\n",
|
|
" <td>0.104015</td>\n",
|
|
" <td>0.048817</td>\n",
|
|
" <td>0.193027</td>\n",
|
|
" <td>0.517784</td>\n",
|
|
" <td>0.471898</td>\n",
|
|
" <td>0.867232</td>\n",
|
|
" <td>0.147908</td>\n",
|
|
" <td>3.871296</td>\n",
|
|
" <td>0.971820</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>Ready_SVDBiased</td>\n",
|
|
" <td>0.939472</td>\n",
|
|
" <td>0.739816</td>\n",
|
|
" <td>0.085896</td>\n",
|
|
" <td>0.036073</td>\n",
|
|
" <td>0.043528</td>\n",
|
|
" <td>0.057643</td>\n",
|
|
" <td>0.077039</td>\n",
|
|
" <td>0.057463</td>\n",
|
|
" <td>0.097753</td>\n",
|
|
" <td>0.045546</td>\n",
|
|
" <td>0.219839</td>\n",
|
|
" <td>0.514709</td>\n",
|
|
" <td>0.431601</td>\n",
|
|
" <td>0.997455</td>\n",
|
|
" <td>0.168831</td>\n",
|
|
" <td>4.217578</td>\n",
|
|
" <td>0.962577</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>Ready_Random</td>\n",
|
|
" <td>1.521845</td>\n",
|
|
" <td>1.225949</td>\n",
|
|
" <td>0.047190</td>\n",
|
|
" <td>0.020753</td>\n",
|
|
" <td>0.024810</td>\n",
|
|
" <td>0.032269</td>\n",
|
|
" <td>0.029506</td>\n",
|
|
" <td>0.023707</td>\n",
|
|
" <td>0.050075</td>\n",
|
|
" <td>0.018728</td>\n",
|
|
" <td>0.121957</td>\n",
|
|
" <td>0.506893</td>\n",
|
|
" <td>0.329799</td>\n",
|
|
" <td>0.986532</td>\n",
|
|
" <td>0.184704</td>\n",
|
|
" <td>5.099706</td>\n",
|
|
" <td>0.907217</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_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.030712</td>\n",
|
|
" <td>0.820904</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_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
|
|
"0 Ready_SVD 0.950347 0.749312 0.100636 0.050514 0.055794 \n",
|
|
"0 Self_SVD 0.914143 0.717131 0.101803 0.042134 0.051610 \n",
|
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
|
"0 Ready_SVDBiased 0.939472 0.739816 0.085896 0.036073 0.043528 \n",
|
|
"0 Ready_Random 1.521845 1.225949 0.047190 0.020753 0.024810 \n",
|
|
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \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.030712 0.820904 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.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
|
|
"0 0.070753 0.091202 0.082734 0.114054 0.053200 0.248803 \n",
|
|
"0 0.068543 0.091953 0.071255 0.104015 0.048817 0.193027 \n",
|
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
|
"0 0.057643 0.077039 0.057463 0.097753 0.045546 0.219839 \n",
|
|
"0 0.032269 0.029506 0.023707 0.050075 0.018728 0.121957 \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.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.555546 0.765642 1.000000 0.038961 3.159079 0.987317 \n",
|
|
"0 0.521983 0.517497 0.992153 0.210678 4.418683 0.952848 \n",
|
|
"0 0.517784 0.471898 0.867232 0.147908 3.871296 0.971820 \n",
|
|
"0 0.515501 0.437964 1.000000 0.033911 2.836513 0.991139 \n",
|
|
"0 0.514709 0.431601 0.997455 0.168831 4.217578 0.962577 \n",
|
|
"0 0.506893 0.329799 0.986532 0.184704 5.099706 0.907217 \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.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": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"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": "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.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|