Uczenie_maszynowe_Systemy_R.../P5. Graph-based.ipynb

1686 lines
569 KiB
Plaintext
Raw Normal View History

2020-06-14 22:23:50 +02:00
{
"nbformat": 4,
"nbformat_minor": 0,
"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"
},
"colab": {
"name": "P5. Graph-based.ipynb",
"provenance": [],
"collapsed_sections": [],
"toc_visible": true
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "oBFGfLoaZjNI",
"colab_type": "text"
},
"source": [
"# Self made RP3-beta"
]
},
{
"cell_type": "code",
"metadata": {
"id": "XCsUZhTrEVf5",
"colab_type": "code",
"outputId": "3c14b890-022d-45bd-83b7-da73fbe20be0",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 289
}
},
"source": [
"pip install surprise"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"Collecting surprise\n",
" Downloading https://files.pythonhosted.org/packages/61/de/e5cba8682201fcf9c3719a6fdda95693468ed061945493dea2dd37c5618b/surprise-0.1-py2.py3-none-any.whl\n",
"Collecting scikit-surprise\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/f5/da/b5700d96495fb4f092be497f02492768a3d96a3f4fa2ae7dea46d4081cfa/scikit-surprise-1.1.0.tar.gz (6.4MB)\n",
"\u001b[K |████████████████████████████████| 6.5MB 2.8MB/s \n",
"\u001b[?25hRequirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (0.15.1)\n",
"Requirement already satisfied: numpy>=1.11.2 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.18.5)\n",
"Requirement already satisfied: scipy>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.4.1)\n",
"Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.12.0)\n",
"Building wheels for collected packages: scikit-surprise\n",
" Building wheel for scikit-surprise (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for scikit-surprise: filename=scikit_surprise-1.1.0-cp36-cp36m-linux_x86_64.whl size=1675402 sha256=0402e186e04cc281f74955fc53a5f90361c98d08599a8e72cc36eb0b55dafd8a\n",
" Stored in directory: /root/.cache/pip/wheels/cc/fa/8c/16c93fccce688ae1bde7d979ff102f7bee980d9cfeb8641bcf\n",
"Successfully built scikit-surprise\n",
"Installing collected packages: scikit-surprise, surprise\n",
"Successfully installed scikit-surprise-1.1.0 surprise-0.1\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cV3e4dIGZjNJ",
"colab_type": "code",
"colab": {}
},
"source": [
"import helpers\n",
"import pandas as pd\n",
"import numpy as np\n",
"import scipy.sparse as sparse\n",
"from collections import defaultdict\n",
"from itertools import chain\n",
"import random\n",
"import time\n",
"import matplotlib.pyplot as plt\n",
"\n",
"train_read=pd.read_csv('./Datasets/ml-100k/train.csv', sep='\\t', header=None)\n",
"test_read=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
"train_ui, test_ui, user_code_id, user_id_code, item_code_id, item_id_code = helpers.data_to_csr(train_read, test_read)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "x-7AjdoUZjNM",
"colab_type": "code",
"colab": {}
},
"source": [
"class RP3Beta():\n",
" def fit(self, train_ui, alpha, beta):\n",
" \"\"\"We weight our edges by user's explicit ratings so if user rated movie high we'll follow that path\n",
" with higher probability.\"\"\"\n",
" self.train_ui=train_ui\n",
" self.train_iu=train_ui.transpose()\n",
" \n",
" self.alpha = alpha\n",
" self.beta = beta\n",
" \n",
" # Define Pui \n",
" Pui=sparse.csr_matrix(self.train_ui/self.train_ui.sum(axis=1))\n",
" \n",
" # Define Piu\n",
" to_divide=np.vectorize(lambda x: x if x>0 else 1)(self.train_iu.sum(axis=1)) # to avoid dividing by zero\n",
" Piu=sparse.csr_matrix(self.train_iu/to_divide)\n",
" item_orders=(self.train_ui>0).sum(axis=0)\n",
" \n",
" Pui = Pui.power(self.alpha)\n",
" Piu = Piu.power(self.alpha)\n",
"\n",
" P3=Pui*Piu*Pui\n",
" \n",
" P3/=np.power(np.vectorize(lambda x: x if x>0 else 1)(item_orders), self.beta)\n",
" \n",
" self.estimations=np.array(P3)\n",
" \n",
" def recommend(self, user_code_id, item_code_id, topK=10):\n",
" \n",
" top_k = defaultdict(list)\n",
" for nb_user, user in enumerate(self.estimations):\n",
" \n",
" user_rated=self.train_ui.indices[self.train_ui.indptr[nb_user]:self.train_ui.indptr[nb_user+1]]\n",
" for item, score in enumerate(user):\n",
" if item not in user_rated and not np.isnan(score):\n",
" top_k[user_code_id[nb_user]].append((item_code_id[item], score))\n",
" result=[]\n",
" # Let's choose k best items in the format: (user, item1, score1, item2, score2, ...)\n",
" for uid, item_scores in top_k.items():\n",
" item_scores.sort(key=lambda x: x[1], reverse=True)\n",
" result.append([uid]+list(chain(*item_scores[:topK])))\n",
" return result\n",
" \n",
" def estimate(self, user_code_id, item_code_id, test_ui):\n",
" result=[]\n",
" for user, item in zip(*test_ui.nonzero()):\n",
" result.append([user_code_id[user], item_code_id[item], \n",
" self.estimations[user,item] if not np.isnan(self.estimations[user,item]) else 1])\n",
" return result"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "NAbmrKYtZjNO",
"colab_type": "code",
"colab": {}
},
"source": [
"model=RP3Beta()\n",
"model.fit(train_ui, alpha=1, beta=0)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "4gcTSfdDZjNR",
"colab_type": "code",
"colab": {}
},
"source": [
"top_n=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
"\n",
"top_n.to_csv('Recommendations generated/ml-100k/Self_P3_reco.csv', index=False, header=False)\n",
"\n",
"estimations=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
"estimations.to_csv('Recommendations generated/ml-100k/Self_P3_estimations.csv', index=False, header=False)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "88miK6I_ZjNT",
"colab_type": "code",
"outputId": "4934d7c9-d48a-49b6-dfeb-046559bc0e8f",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 97
}
},
"source": [
"import evaluation_measures as ev\n",
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Self_P3_estimations.csv', header=None)\n",
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_P3_reco.csv', delimiter=',')\n",
"\n",
"ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=reco,\n",
" super_reactions=[4,5])"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"943it [00:00, 6376.09it/s]\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.21698</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>1.0</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision ... Test coverage Shannon Gini\n",
"0 3.702446 3.527273 0.282185 ... 0.077201 3.875892 0.974947\n",
"\n",
"[1 rows x 17 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 10
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oQgtfbTiZjNW",
"colab_type": "text"
},
"source": [
"# Let's check hiperparameters"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "frYdl2NxZjNW",
"colab_type": "text"
},
"source": [
"##### Alpha"
]
},
{
"cell_type": "code",
"metadata": {
"id": "3Qqk8x3kZjNW",
"colab_type": "code",
"outputId": "cb300375-98cb-42fc-f3db-34202e3d3955",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 739
}
},
"source": [
"from tqdm import tqdm\n",
"result=[]\n",
"for alpha in tqdm([round(i,1) for i in np.arange(0.2,1.6001,0.2)]):\n",
" model=RP3Beta()\n",
" model.fit(train_ui, alpha=alpha, beta=0)\n",
" reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
" estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=np.array(reco),\n",
" super_reactions=[4,5])\n",
" to_append.insert(0, \"Alpha\", alpha)\n",
" result.append(to_append)\n",
" \n",
"result=pd.concat(result)\n",
"result"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
" 0%| | 0/8 [00:00<?, ?it/s]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6334.35it/s]\n",
" 12%|█▎ | 1/8 [00:11<01:19, 11.38s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6365.04it/s]\n",
" 25%|██▌ | 2/8 [00:22<01:07, 11.33s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6323.80it/s]\n",
" 38%|███▊ | 3/8 [00:34<00:56, 11.37s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6484.87it/s]\n",
" 50%|█████ | 4/8 [00:45<00:45, 11.32s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6172.18it/s]\n",
" 62%|██████▎ | 5/8 [00:56<00:33, 11.27s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6405.62it/s]\n",
" 75%|███████▌ | 6/8 [01:07<00:22, 11.32s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6547.37it/s]\n",
" 88%|████████▊ | 7/8 [01:19<00:11, 11.35s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6573.96it/s]\n",
"100%|██████████| 8/8 [01:30<00:00, 11.31s/it]\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Alpha</th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.2</td>\n",
" <td>268.177832</td>\n",
" <td>211.732649</td>\n",
" <td>0.262672</td>\n",
" <td>0.166858</td>\n",
" <td>0.166277</td>\n",
" <td>0.197184</td>\n",
" <td>0.187661</td>\n",
" <td>0.203252</td>\n",
" <td>0.320910</td>\n",
" <td>0.196132</td>\n",
" <td>0.563378</td>\n",
" <td>0.580866</td>\n",
" <td>0.850477</td>\n",
" <td>1.000000</td>\n",
" <td>0.060606</td>\n",
" <td>3.669627</td>\n",
" <td>0.979636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.4</td>\n",
" <td>10.546689</td>\n",
" <td>7.792373</td>\n",
" <td>0.268505</td>\n",
" <td>0.172669</td>\n",
" <td>0.171569</td>\n",
" <td>0.202643</td>\n",
" <td>0.192489</td>\n",
" <td>0.212653</td>\n",
" <td>0.326760</td>\n",
" <td>0.200172</td>\n",
" <td>0.565148</td>\n",
" <td>0.583801</td>\n",
" <td>0.854719</td>\n",
" <td>1.000000</td>\n",
" <td>0.064214</td>\n",
" <td>3.726996</td>\n",
" <td>0.978426</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.6</td>\n",
" <td>3.143988</td>\n",
" <td>2.948790</td>\n",
" <td>0.274655</td>\n",
" <td>0.180502</td>\n",
" <td>0.177820</td>\n",
" <td>0.208730</td>\n",
" <td>0.198176</td>\n",
" <td>0.222746</td>\n",
" <td>0.332872</td>\n",
" <td>0.203290</td>\n",
" <td>0.568872</td>\n",
" <td>0.587738</td>\n",
" <td>0.870626</td>\n",
" <td>1.000000</td>\n",
" <td>0.065657</td>\n",
" <td>3.785282</td>\n",
" <td>0.977090</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.8</td>\n",
" <td>3.670728</td>\n",
" <td>3.495735</td>\n",
" <td>0.281972</td>\n",
" <td>0.189868</td>\n",
" <td>0.185300</td>\n",
" <td>0.216071</td>\n",
" <td>0.203541</td>\n",
" <td>0.236751</td>\n",
" <td>0.339867</td>\n",
" <td>0.206688</td>\n",
" <td>0.573729</td>\n",
" <td>0.592432</td>\n",
" <td>0.874867</td>\n",
" <td>1.000000</td>\n",
" <td>0.070707</td>\n",
" <td>3.832415</td>\n",
" <td>0.975998</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.216980</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>1.000000</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.2</td>\n",
" <td>3.704441</td>\n",
" <td>3.529251</td>\n",
" <td>0.280912</td>\n",
" <td>0.193633</td>\n",
" <td>0.187311</td>\n",
" <td>0.216872</td>\n",
" <td>0.203004</td>\n",
" <td>0.240588</td>\n",
" <td>0.338049</td>\n",
" <td>0.203453</td>\n",
" <td>0.571830</td>\n",
" <td>0.594313</td>\n",
" <td>0.883351</td>\n",
" <td>1.000000</td>\n",
" <td>0.085859</td>\n",
" <td>3.910718</td>\n",
" <td>0.974073</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.4</td>\n",
" <td>3.704580</td>\n",
" <td>3.529388</td>\n",
" <td>0.273595</td>\n",
" <td>0.190651</td>\n",
" <td>0.183874</td>\n",
" <td>0.212183</td>\n",
" <td>0.199464</td>\n",
" <td>0.239118</td>\n",
" <td>0.329550</td>\n",
" <td>0.195433</td>\n",
" <td>0.566171</td>\n",
" <td>0.592793</td>\n",
" <td>0.871686</td>\n",
" <td>1.000000</td>\n",
" <td>0.107504</td>\n",
" <td>3.961915</td>\n",
" <td>0.972674</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.6</td>\n",
" <td>3.704591</td>\n",
" <td>3.529399</td>\n",
" <td>0.263097</td>\n",
" <td>0.186255</td>\n",
" <td>0.178709</td>\n",
" <td>0.205170</td>\n",
" <td>0.191094</td>\n",
" <td>0.232920</td>\n",
" <td>0.317439</td>\n",
" <td>0.184917</td>\n",
" <td>0.552349</td>\n",
" <td>0.590545</td>\n",
" <td>0.868505</td>\n",
" <td>0.999576</td>\n",
" <td>0.156566</td>\n",
" <td>4.060156</td>\n",
" <td>0.969203</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Alpha RMSE MAE ... Test coverage Shannon Gini\n",
"0 0.2 268.177832 211.732649 ... 0.060606 3.669627 0.979636\n",
"0 0.4 10.546689 7.792373 ... 0.064214 3.726996 0.978426\n",
"0 0.6 3.143988 2.948790 ... 0.065657 3.785282 0.977090\n",
"0 0.8 3.670728 3.495735 ... 0.070707 3.832415 0.975998\n",
"0 1.0 3.702446 3.527273 ... 0.077201 3.875892 0.974947\n",
"0 1.2 3.704441 3.529251 ... 0.085859 3.910718 0.974073\n",
"0 1.4 3.704580 3.529388 ... 0.107504 3.961915 0.972674\n",
"0 1.6 3.704591 3.529399 ... 0.156566 4.060156 0.969203\n",
"\n",
"[8 rows x 18 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"metadata": {
"scrolled": false,
"id": "sh8WT8VrZjNY",
"colab_type": "code",
"outputId": "958316d9-f909-4be3-85f9-018235eaf4c3",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"metrics=list(result.columns[[i not in ['Alpha'] for i in result.columns]])\n",
"\n",
"charts_per_row=6\n",
"charts_per_column=3\n",
"\n",
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
"import itertools\n",
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
"\n",
"for i in range(len(metrics)):\n",
" df=result[['Alpha', metrics[i]]]\n",
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCwAAAkoCAYAAACgVC5GAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzde3xV9ZX//9fKPYdbOCFAQhJAReUaUEAsUhXRiiVoW2t1atupnXGm1XY67fy+Y6f9tR2nPmaqvY0t7bSddmynFm/TC7F4L7b6HRFRCVdRlHsChHBLIBeSrO8fZyceYpBbztknOe/n43EenPPZe5+sjbrdWXt91sfcHRERERERERGRVJIRdgAiIiIiIiIiIt0pYSEiIiIiIiIiKUcJCxERERERERFJOUpYiIiIiIiIiEjKUcJCRERERERERFKOEhYiIiIiIiIiknKUsBAREREREZEuZvYfZvb/n8R+68zssiSEJGlKCQvpd8xsi5k1mVmjme0ys/vMbGCw7T4zczO7ttsx3w3G/zL4nGNm3zazHcH3bDGz7x3nZ3S+fpDUExUR6UOC62armQ3rNv5qcP0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TTz7JxRdfzAUXXMCHP/xhGhsbAXjppZd4z3veQ0VFBTNnzqShoYFnn322q5rtT3/6U1el2rRp02hoaGDLli1MmjQJiPXx+OQnP8nkyZOZNm0ay5YtA+C+++7jgx/8IFdffTXjxo3j//yf/5OUvw+tEiIiCfHPVetYX3OoV79zQslgvlY58cQ7Ess8P/PMM3zqU586ZrzzJ
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tqDcNjXgZjNb",
"colab_type": "text"
},
"source": [
"##### Beta"
]
},
{
"cell_type": "code",
"metadata": {
"id": "lBQMbnnkZjNb",
"colab_type": "code",
"outputId": "c6f92402-79fb-4488-ee5a-1450d131e4fa",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 886
}
},
"source": [
"from tqdm import tqdm\n",
"result=[]\n",
"for beta in tqdm([round(i,1) for i in np.arange(0,1,0.1)]):\n",
" model=RP3Beta()\n",
" model.fit(train_ui, alpha=1, beta=beta)\n",
" reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
" estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=np.array(reco),\n",
" super_reactions=[4,5])\n",
" to_append.insert(0, \"Beta\", beta)\n",
" result.append(to_append)\n",
" \n",
"result=pd.concat(result)\n",
"result"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
" 0%| | 0/10 [00:00<?, ?it/s]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6498.11it/s]\n",
" 10%|█ | 1/10 [00:11<01:44, 11.61s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6408.36it/s]\n",
" 20%|██ | 2/10 [00:23<01:32, 11.61s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6396.07it/s]\n",
" 30%|███ | 3/10 [00:34<01:20, 11.54s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 5925.94it/s]\n",
" 40%|████ | 4/10 [00:46<01:09, 11.58s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 5799.00it/s]\n",
" 50%|█████ | 5/10 [00:57<00:57, 11.46s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6089.68it/s]\n",
" 60%|██████ | 6/10 [01:08<00:45, 11.37s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 5271.79it/s]\n",
" 70%|███████ | 7/10 [01:20<00:34, 11.43s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6396.94it/s]\n",
" 80%|████████ | 8/10 [01:31<00:22, 11.32s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6464.53it/s]\n",
" 90%|█████████ | 9/10 [01:42<00:11, 11.29s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 6338.37it/s]\n",
"100%|██████████| 10/10 [01:53<00:00, 11.38s/it]\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Beta</th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.216980</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>1.000000</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.1</td>\n",
" <td>3.703312</td>\n",
" <td>3.528128</td>\n",
" <td>0.290138</td>\n",
" <td>0.197597</td>\n",
" <td>0.192259</td>\n",
" <td>0.223336</td>\n",
" <td>0.210944</td>\n",
" <td>0.246153</td>\n",
" <td>0.347768</td>\n",
" <td>0.212034</td>\n",
" <td>0.581038</td>\n",
" <td>0.596328</td>\n",
" <td>0.884411</td>\n",
" <td>1.000000</td>\n",
" <td>0.085137</td>\n",
" <td>3.957416</td>\n",
" <td>0.972784</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.2</td>\n",
" <td>3.703825</td>\n",
" <td>3.528636</td>\n",
" <td>0.297137</td>\n",
" <td>0.201202</td>\n",
" <td>0.196067</td>\n",
" <td>0.228169</td>\n",
" <td>0.218026</td>\n",
" <td>0.252767</td>\n",
" <td>0.355655</td>\n",
" <td>0.219909</td>\n",
" <td>0.588904</td>\n",
" <td>0.598160</td>\n",
" <td>0.886532</td>\n",
" <td>1.000000</td>\n",
" <td>0.094517</td>\n",
" <td>4.053212</td>\n",
" <td>0.969980</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.3</td>\n",
" <td>3.704130</td>\n",
" <td>3.528939</td>\n",
" <td>0.303499</td>\n",
" <td>0.204749</td>\n",
" <td>0.199901</td>\n",
" <td>0.232829</td>\n",
" <td>0.225107</td>\n",
" <td>0.260797</td>\n",
" <td>0.363757</td>\n",
" <td>0.226825</td>\n",
" <td>0.599969</td>\n",
" <td>0.599964</td>\n",
" <td>0.888653</td>\n",
" <td>1.000000</td>\n",
" <td>0.105339</td>\n",
" <td>4.147779</td>\n",
" <td>0.966948</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.4</td>\n",
" <td>3.704313</td>\n",
" <td>3.529120</td>\n",
" <td>0.308908</td>\n",
" <td>0.208811</td>\n",
" <td>0.203854</td>\n",
" <td>0.237241</td>\n",
" <td>0.229614</td>\n",
" <td>0.266918</td>\n",
" <td>0.370758</td>\n",
" <td>0.232673</td>\n",
" <td>0.609385</td>\n",
" <td>0.602014</td>\n",
" <td>0.895016</td>\n",
" <td>0.999894</td>\n",
" <td>0.132035</td>\n",
" <td>4.259682</td>\n",
" <td>0.962989</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.5</td>\n",
" <td>3.704422</td>\n",
" <td>3.529229</td>\n",
" <td>0.314316</td>\n",
" <td>0.211411</td>\n",
" <td>0.206768</td>\n",
" <td>0.240986</td>\n",
" <td>0.237124</td>\n",
" <td>0.273416</td>\n",
" <td>0.378307</td>\n",
" <td>0.239297</td>\n",
" <td>0.622792</td>\n",
" <td>0.603327</td>\n",
" <td>0.903499</td>\n",
" <td>0.999046</td>\n",
" <td>0.168831</td>\n",
" <td>4.411281</td>\n",
" <td>0.956648</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.6</td>\n",
" <td>3.704488</td>\n",
" <td>3.529295</td>\n",
" <td>0.314634</td>\n",
" <td>0.206209</td>\n",
" <td>0.204818</td>\n",
" <td>0.240159</td>\n",
" <td>0.242489</td>\n",
" <td>0.273850</td>\n",
" <td>0.376438</td>\n",
" <td>0.238428</td>\n",
" <td>0.622042</td>\n",
" <td>0.600721</td>\n",
" <td>0.897137</td>\n",
" <td>0.996394</td>\n",
" <td>0.212843</td>\n",
" <td>4.621938</td>\n",
" <td>0.945932</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.7</td>\n",
" <td>3.704528</td>\n",
" <td>3.529335</td>\n",
" <td>0.304136</td>\n",
" <td>0.187298</td>\n",
" <td>0.191990</td>\n",
" <td>0.228749</td>\n",
" <td>0.238305</td>\n",
" <td>0.256201</td>\n",
" <td>0.358807</td>\n",
" <td>0.226808</td>\n",
" <td>0.593897</td>\n",
" <td>0.591207</td>\n",
" <td>0.868505</td>\n",
" <td>0.983033</td>\n",
" <td>0.256854</td>\n",
" <td>4.898568</td>\n",
" <td>0.928065</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.8</td>\n",
" <td>3.704552</td>\n",
" <td>3.529360</td>\n",
" <td>0.266384</td>\n",
" <td>0.147571</td>\n",
" <td>0.158660</td>\n",
" <td>0.194838</td>\n",
" <td>0.214485</td>\n",
" <td>0.209336</td>\n",
" <td>0.299850</td>\n",
" <td>0.184356</td>\n",
" <td>0.492852</td>\n",
" <td>0.571152</td>\n",
" <td>0.803818</td>\n",
" <td>0.936373</td>\n",
" <td>0.341270</td>\n",
" <td>5.257397</td>\n",
" <td>0.895882</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.9</td>\n",
" <td>3.704567</td>\n",
" <td>3.529375</td>\n",
" <td>0.162354</td>\n",
" <td>0.076967</td>\n",
" <td>0.089233</td>\n",
" <td>0.114583</td>\n",
" <td>0.134657</td>\n",
" <td>0.113253</td>\n",
" <td>0.160868</td>\n",
" <td>0.085486</td>\n",
" <td>0.243590</td>\n",
" <td>0.535405</td>\n",
" <td>0.580064</td>\n",
" <td>0.800106</td>\n",
" <td>0.415584</td>\n",
" <td>5.563910</td>\n",
" <td>0.857396</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Beta RMSE MAE ... Test coverage Shannon Gini\n",
"0 0.0 3.702446 3.527273 ... 0.077201 3.875892 0.974947\n",
"0 0.1 3.703312 3.528128 ... 0.085137 3.957416 0.972784\n",
"0 0.2 3.703825 3.528636 ... 0.094517 4.053212 0.969980\n",
"0 0.3 3.704130 3.528939 ... 0.105339 4.147779 0.966948\n",
"0 0.4 3.704313 3.529120 ... 0.132035 4.259682 0.962989\n",
"0 0.5 3.704422 3.529229 ... 0.168831 4.411281 0.956648\n",
"0 0.6 3.704488 3.529295 ... 0.212843 4.621938 0.945932\n",
"0 0.7 3.704528 3.529335 ... 0.256854 4.898568 0.928065\n",
"0 0.8 3.704552 3.529360 ... 0.341270 5.257397 0.895882\n",
"0 0.9 3.704567 3.529375 ... 0.415584 5.563910 0.857396\n",
"\n",
"[10 rows x 18 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"metadata": {
"scrolled": false,
"id": "Fap212kSZjNd",
"colab_type": "code",
"outputId": "6bacdcbf-6ef9-429f-d2a9-64b744cb82ff",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"### import matplotlib.pyplot as plt\n",
"\n",
"metrics=list(result.columns[[i not in ['Beta'] for i in result.columns]])\n",
"\n",
"charts_per_row=6\n",
"charts_per_column=3\n",
"\n",
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
"import itertools\n",
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
"\n",
"for i in range(len(metrics)):\n",
" df=result[['Beta', metrics[i]]]\n",
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0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UuJiIggJSWl/rFkyRLPn5yISAthjOHqq6+u366urqZDhw5MmjTpiH6XXHIJw4cPP6LtV7/6FXFxcUeMuXVjuYjIibDWfmCt7W2t7WGt/a277RFr7Tvu57dba/tZa1Ostedaaze52x+31oa62+se+U6ei4i0TKtXr+a222475v6cnBwuu+wyD0Z04pSwaELBwcGkpaWxceNGoqKimD17dv2+bt268f7779dvv/766/Tr169++7bbbuOOO+4gLS2NLVu2cOutt9bvGzVqFGlpafWPcePGeeaERERaoNDQUDZu3EhZWRkAixcvJi4u7og+hYWFrFmzhkOHDrFr164j9tWNxXWPyMhIj8UuIiIi0lhNTc0P6p+amsqf/vSnY+6PjY3ljTfeONWwmoQSFh4yYsQIsrO/rbEUEhJCYmIiq1evBmDevHlcccUV9ftzc3OJj4+v305OTvZcsCIircwFF1xQnySeO3cuV1555RH733zzTS666CKmTZvGa6+95kSIIiIiImRkZNC3b1+mT59OYmIil112GaWlpXTt2pVf/vKXDB48mNdff51FixYxYsQIBg8ezOWXX05JSQkAq1at4swzz2TgwIEMHTqU4uJili5dWj+z9LPPPqufNTpo0CCKi4vJyMigf//+gKuOx/XXX09ycjKDBg3i008/BeCll15iypQpTJw4kV69enHvvfd65PfRalcJaejX725ic07RaX3Np
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "I-FL4okWZjNf",
"colab_type": "text"
},
"source": [
"# Check sample recommendations"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Y2DDJAGVZjNf",
"colab_type": "code",
"outputId": "676b4348-9ac9-46fc-9e2d-9bddbcc04c36",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 856
}
},
"source": [
"train=pd.read_csv('./Datasets/ml-100k/train.csv', sep='\\t', header=None, names=['user', 'item', 'rating', 'timestamp'])\n",
"items=pd.read_csv('./Datasets/ml-100k/movies.csv')\n",
"\n",
"user=random.choice(list(set(train['user'])))\n",
"\n",
"train_content=pd.merge(train, items, left_on='item', right_on='id')\n",
"display(train_content[train_content['user']==user][['user', 'rating', 'title', 'genres']]\\\n",
" .sort_values(by='rating', ascending=False)[:15])\n",
"\n",
"reco = np.loadtxt('Recommendations generated/ml-100k/Self_P3_reco.csv', delimiter=',')\n",
"items=pd.read_csv('./Datasets/ml-100k/movies.csv')\n",
"\n",
"# Let's ignore scores - they are not used in evaluation: \n",
"reco_users=reco[:,:1]\n",
"reco_items=reco[:,1::2]\n",
"# Let's put them into one array\n",
"reco=np.concatenate((reco_users, reco_items), axis=1)\n",
"\n",
"# Let's rebuild it user-item dataframe\n",
"recommended=[]\n",
"for row in reco:\n",
" for rec_nb, entry in enumerate(row[1:]):\n",
" recommended.append((row[0], rec_nb+1, entry))\n",
"recommended=pd.DataFrame(recommended, columns=['user','rec_nb', 'item'])\n",
"\n",
"recommended_content=pd.merge(recommended, items, left_on='item', right_on='id')\n",
"recommended_content[recommended_content['user']==user][['user', 'rec_nb', 'title', 'genres']].sort_values(by='rec_nb')"
],
"execution_count": 0,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user</th>\n",
" <th>rating</th>\n",
" <th>title</th>\n",
" <th>genres</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>10631</th>\n",
" <td>190</td>\n",
" <td>5</td>\n",
" <td>Courage Under Fire (1996)</td>\n",
" <td>Drama, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19196</th>\n",
" <td>190</td>\n",
" <td>5</td>\n",
" <td>Scream (1996)</td>\n",
" <td>Horror, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5262</th>\n",
" <td>190</td>\n",
" <td>5</td>\n",
" <td>Jerry Maguire (1996)</td>\n",
" <td>Drama, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46114</th>\n",
" <td>190</td>\n",
" <td>5</td>\n",
" <td>L.A. Confidential (1997)</td>\n",
" <td>Crime, Film-Noir, Mystery, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40446</th>\n",
" <td>190</td>\n",
" <td>5</td>\n",
" <td>Titanic (1997)</td>\n",
" <td>Action, Drama, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45123</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Tomorrow Never Dies (1997)</td>\n",
" <td>Action, Romance, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33331</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Game, The (1997)</td>\n",
" <td>Mystery, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34493</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Devil's Own, The (1997)</td>\n",
" <td>Action, Drama, Thriller, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39439</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Sleepers (1996)</td>\n",
" <td>Crime, Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40264</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Rainmaker, The (1997)</td>\n",
" <td>Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>461</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Heat (1995)</td>\n",
" <td>Action, Crime, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30171</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Star Trek: First Contact (1996)</td>\n",
" <td>Action, Adventure, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47145</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Primal Fear (1996)</td>\n",
" <td>Drama, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>55123</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Long Kiss Goodnight, The (1996)</td>\n",
" <td>Action, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58856</th>\n",
" <td>190</td>\n",
" <td>4</td>\n",
" <td>Wedding Singer, The (1998)</td>\n",
" <td>Comedy, Romance</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user ... genres\n",
"10631 190 ... Drama, War\n",
"19196 190 ... Horror, Thriller\n",
"5262 190 ... Drama, Romance\n",
"46114 190 ... Crime, Film-Noir, Mystery, Thriller\n",
"40446 190 ... Action, Drama, Romance\n",
"45123 190 ... Action, Romance, Thriller\n",
"33331 190 ... Mystery, Thriller\n",
"34493 190 ... Action, Drama, Thriller, War\n",
"39439 190 ... Crime, Drama\n",
"40264 190 ... Drama\n",
"461 190 ... Action, Crime, Thriller\n",
"30171 190 ... Action, Adventure, Sci-Fi\n",
"47145 190 ... Drama, Thriller\n",
"55123 190 ... Action, Thriller\n",
"58856 190 ... Comedy, Romance\n",
"\n",
"[15 rows x 4 columns]"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user</th>\n",
" <th>rec_nb</th>\n",
" <th>title</th>\n",
" <th>genres</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>190.0</td>\n",
" <td>1</td>\n",
" <td>Star Wars (1977)</td>\n",
" <td>Action, Adventure, Romance, Sci-Fi, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1019</th>\n",
" <td>190.0</td>\n",
" <td>2</td>\n",
" <td>English Patient, The (1996)</td>\n",
" <td>Drama, Romance, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2704</th>\n",
" <td>190.0</td>\n",
" <td>3</td>\n",
" <td>Return of the Jedi (1983)</td>\n",
" <td>Action, Adventure, Romance, Sci-Fi, War</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3106</th>\n",
" <td>190.0</td>\n",
" <td>4</td>\n",
" <td>Toy Story (1995)</td>\n",
" <td>Animation, Children's, Comedy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3611</th>\n",
" <td>190.0</td>\n",
" <td>5</td>\n",
" <td>Conspiracy Theory (1997)</td>\n",
" <td>Action, Mystery, Romance, Thriller</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2268</th>\n",
" <td>190.0</td>\n",
" <td>6</td>\n",
" <td>Godfather, The (1972)</td>\n",
" <td>Action, Crime, Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8825</th>\n",
" <td>190.0</td>\n",
" <td>7</td>\n",
" <td>Men in Black (1997)</td>\n",
" <td>Action, Adventure, Comedy, Sci-Fi</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6263</th>\n",
" <td>190.0</td>\n",
" <td>8</td>\n",
" <td>Good Will Hunting (1997)</td>\n",
" <td>Drama</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8307</th>\n",
" <td>190.0</td>\n",
" <td>9</td>\n",
" <td>Leaving Las Vegas (1995)</td>\n",
" <td>Drama, Romance</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4369</th>\n",
" <td>190.0</td>\n",
" <td>10</td>\n",
" <td>Dead Man Walking (1995)</td>\n",
" <td>Drama</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user ... genres\n",
"84 190.0 ... Action, Adventure, Romance, Sci-Fi, War\n",
"1019 190.0 ... Drama, Romance, War\n",
"2704 190.0 ... Action, Adventure, Romance, Sci-Fi, War\n",
"3106 190.0 ... Animation, Children's, Comedy\n",
"3611 190.0 ... Action, Mystery, Romance, Thriller\n",
"2268 190.0 ... Action, Crime, Drama\n",
"8825 190.0 ... Action, Adventure, Comedy, Sci-Fi\n",
"6263 190.0 ... Drama\n",
"8307 190.0 ... Drama, Romance\n",
"4369 190.0 ... Drama\n",
"\n",
"[10 rows x 4 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 16
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nt4U7HgnZjNi",
"colab_type": "text"
},
"source": [
"# project task 6: generate recommendations of RP3Beta for hiperparameters found to optimize recall"
]
},
{
"cell_type": "code",
"metadata": {
"id": "cCR_y7yCZjNi",
"colab_type": "code",
"outputId": "a0fc7c7a-7acf-4387-9e19-edfc0913161b",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 97
}
},
"source": [
"# use better values than (1,0) for alpha and beta\n",
"# if you want you can also modify the model to consider different weights (we took as weights user ratings, maybe take ones or squares of ratings instead)\n",
"# save the outptut in 'Recommendations generated/ml-100k/Self_RP3Beta_estimations.csv'\n",
"# and 'Recommendations generated/ml-100k/Self_RP3Beta_reco.csv'\n",
"\n",
"import evaluation_measures as ev\n",
"\n",
"model=RP3Beta()\n",
"model.fit(train_ui, alpha=0.6, beta=0.4) # wartości alpha 0.6, beta 0.4 mają mniejszy RMSE, MAE, większą precyzję i niedużo większy recall\n",
"model_reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
"model_reco.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_reco.csv', index=False, header=False)\n",
"estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
"estimations_df.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_estimations.csv', index=False, header=False)\n",
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_RP3Beta_reco.csv', delimiter=',')\n",
"\n",
"ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
" estimations_df=estimations_df, \n",
" reco=reco,\n",
" super_reactions=[4,5])"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"943it [00:00, 7119.46it/s]\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.626913</td>\n",
" <td>3.450842</td>\n",
" <td>0.309862</td>\n",
" <td>0.208881</td>\n",
" <td>0.203915</td>\n",
" <td>0.23761</td>\n",
" <td>0.228541</td>\n",
" <td>0.263796</td>\n",
" <td>0.375901</td>\n",
" <td>0.239086</td>\n",
" <td>0.621655</td>\n",
" <td>0.602052</td>\n",
" <td>0.889714</td>\n",
" <td>1.0</td>\n",
" <td>0.105339</td>\n",
" <td>4.209113</td>\n",
" <td>0.964697</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision ... Test coverage Shannon Gini\n",
"0 3.626913 3.450842 0.309862 ... 0.105339 4.209113 0.964697\n",
"\n",
"[1 rows x 17 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 20
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "7D2g6NVvG-PC",
"colab_type": "code",
"outputId": "8efd043b-2f6a-44fe-86eb-348a35208c9e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 97
}
},
"source": [
"import evaluation_measures as ev\n",
"\n",
"model=RP3Beta()\n",
"model.fit(train_ui, alpha=1, beta=0) # alpha, 1 beta 0\n",
"model_reco=pd.DataFrame(model.recommend(user_code_id, item_code_id, topK=10))\n",
"model_reco.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_reco2.csv', index=False, header=False)\n",
"estimations_df=pd.DataFrame(model.estimate(user_code_id, item_code_id, test_ui))\n",
"estimations_df.to_csv('Recommendations generated/ml-100k/Self_RP3Beta_estimations2.csv', index=False, header=False)\n",
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_RP3Beta_reco2.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])"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"943it [00:00, 6878.29it/s]\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>RMSE</th>\n",
" <th>MAE</th>\n",
" <th>precision</th>\n",
" <th>recall</th>\n",
" <th>F_1</th>\n",
" <th>F_05</th>\n",
" <th>precision_super</th>\n",
" <th>recall_super</th>\n",
" <th>NDCG</th>\n",
" <th>mAP</th>\n",
" <th>MRR</th>\n",
" <th>LAUC</th>\n",
" <th>HR</th>\n",
" <th>Reco in test</th>\n",
" <th>Test coverage</th>\n",
" <th>Shannon</th>\n",
" <th>Gini</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.21698</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>1.0</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision ... Test coverage Shannon Gini\n",
"0 3.702446 3.527273 0.282185 ... 0.077201 3.875892 0.974947\n",
"\n",
"[1 rows x 17 columns]"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zGMadzSUZjNk",
"colab_type": "text"
},
"source": [
"# project task 7 (optional): implement graph-based model of your choice "
]
},
{
"cell_type": "code",
"metadata": {
"id": "QjWPqKiRZjNl",
"colab_type": "code",
"colab": {}
},
"source": [
"# for example change length of paths in RP3beta\n",
"# save the outptut in 'Recommendations generated/ml-100k/Self_GraphTask_estimations.csv'\n",
"# and 'Recommendations generated/ml-100k/Self_GraphTask_reco.csv'"
],
"execution_count": 0,
"outputs": []
}
]
}