1695 lines
61 KiB
Plaintext
1695 lines
61 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Self made simplified I-KNN"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"class IKNN():\n",
|
||
|
" \n",
|
||
|
" def fit(self, train_ui):\n",
|
||
|
" self.train_ui=train_ui\n",
|
||
|
" \n",
|
||
|
" train_iu=train_ui.transpose()\n",
|
||
|
" norms=np.linalg.norm(train_iu.A, axis=1) # here we compute lenth of each item ratings vector\n",
|
||
|
" norms=np.vectorize(lambda x: max(x,1))(norms[:,None]) # to avoid dividing by zero\n",
|
||
|
"\n",
|
||
|
" normalized_train_iu=sparse.csr_matrix(train_iu/norms)\n",
|
||
|
"\n",
|
||
|
" self.similarity_matrix_ii=normalized_train_iu*normalized_train_iu.transpose()\n",
|
||
|
" \n",
|
||
|
" self.estimations=np.array(train_ui*self.similarity_matrix_ii/((train_ui>0)*self.similarity_matrix_ii))\n",
|
||
|
" \n",
|
||
|
" def recommend(self, user_code_id, item_code_id, topK=10):\n",
|
||
|
" \n",
|
||
|
" top_k = defaultdict(list)\n",
|
||
|
" for nb_user, user in enumerate(self.estimations):\n",
|
||
|
" \n",
|
||
|
" user_rated=self.train_ui.indices[self.train_ui.indptr[nb_user]:self.train_ui.indptr[nb_user+1]]\n",
|
||
|
" for item, score in enumerate(user):\n",
|
||
|
" if item not in user_rated and not np.isnan(score):\n",
|
||
|
" top_k[user_code_id[nb_user]].append((item_code_id[item], score))\n",
|
||
|
" result=[]\n",
|
||
|
" # Let's choose k best items in the format: (user, item1, score1, item2, score2, ...)\n",
|
||
|
" for uid, item_scores in top_k.items():\n",
|
||
|
" item_scores.sort(key=lambda x: x[1], reverse=True)\n",
|
||
|
" result.append([uid]+list(chain(*item_scores[:topK])))\n",
|
||
|
" return result\n",
|
||
|
" \n",
|
||
|
" def estimate(self, user_code_id, item_code_id, test_ui):\n",
|
||
|
" result=[]\n",
|
||
|
" for user, item in zip(*test_ui.nonzero()):\n",
|
||
|
" result.append([user_code_id[user], item_code_id[item], \n",
|
||
|
" self.estimations[user,item] if not np.isnan(self.estimations[user,item]) else 1])\n",
|
||
|
" return result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"toy train ui:\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[3, 4, 0, 0, 5, 0, 0, 4],\n",
|
||
|
" [0, 1, 2, 3, 0, 0, 0, 0],\n",
|
||
|
" [0, 0, 0, 5, 0, 3, 4, 0]], dtype=int64)"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"similarity matrix:\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[1. , 0.9701425 , 0. , 0. , 1. ,\n",
|
||
|
" 0. , 0. , 1. ],\n",
|
||
|
" [0.9701425 , 1. , 0.24253563, 0.12478355, 0.9701425 ,\n",
|
||
|
" 0. , 0. , 0.9701425 ],\n",
|
||
|
" [0. , 0.24253563, 1. , 0.51449576, 0. ,\n",
|
||
|
" 0. , 0. , 0. ],\n",
|
||
|
" [0. , 0.12478355, 0.51449576, 1. , 0. ,\n",
|
||
|
" 0.85749293, 0.85749293, 0. ],\n",
|
||
|
" [1. , 0.9701425 , 0. , 0. , 1. ,\n",
|
||
|
" 0. , 0. , 1. ],\n",
|
||
|
" [0. , 0. , 0. , 0.85749293, 0. ,\n",
|
||
|
" 1. , 1. , 0. ],\n",
|
||
|
" [0. , 0. , 0. , 0.85749293, 0. ,\n",
|
||
|
" 1. , 1. , 0. ],\n",
|
||
|
" [1. , 0.9701425 , 0. , 0. , 1. ,\n",
|
||
|
" 0. , 0. , 1. ]])"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"estimations matrix:\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[4. , 4. , 4. , 4. , 4. ,\n",
|
||
|
" nan, nan, 4. ],\n",
|
||
|
" [1. , 1.35990333, 2.15478388, 2.53390319, 1. ,\n",
|
||
|
" 3. , 3. , 1. ],\n",
|
||
|
" [ nan, 5. , 5. , 4.05248907, nan,\n",
|
||
|
" 3.95012863, 3.95012863, nan]])"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"[[0, 20, 4.0, 30, 4.0],\n",
|
||
|
" [10, 50, 3.0, 60, 3.0, 0, 1.0, 40, 1.0, 70, 1.0],\n",
|
||
|
" [20, 10, 5.0, 20, 5.0]]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# toy example\n",
|
||
|
"toy_train_read=pd.read_csv('./Datasets/toy-example/train.csv', sep='\\t', header=None, names=['user', 'item', 'rating', 'timestamp'])\n",
|
||
|
"toy_test_read=pd.read_csv('./Datasets/toy-example/test.csv', sep='\\t', header=None, names=['user', 'item', 'rating', 'timestamp'])\n",
|
||
|
"\n",
|
||
|
"toy_train_ui, toy_test_ui, toy_user_code_id, toy_user_id_code, \\\n",
|
||
|
"toy_item_code_id, toy_item_id_code = helpers.data_to_csr(toy_train_read, toy_test_read)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"model=IKNN()\n",
|
||
|
"model.fit(toy_train_ui)\n",
|
||
|
"\n",
|
||
|
"print('toy train ui:')\n",
|
||
|
"display(toy_train_ui.A)\n",
|
||
|
"\n",
|
||
|
"print('similarity matrix:')\n",
|
||
|
"display(model.similarity_matrix_ii.A)\n",
|
||
|
"\n",
|
||
|
"print('estimations matrix:')\n",
|
||
|
"display(model.estimations)\n",
|
||
|
"\n",
|
||
|
"model.recommend(toy_user_code_id, toy_item_code_id)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"model=IKNN()\n",
|
||
|
"model.fit(train_ui)\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_IKNN_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_IKNN_estimations.csv', index=False, header=False)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 3162.40it/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>F_2</th>\n",
|
||
|
" <th>Whole_average</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>1.018363</td>\n",
|
||
|
" <td>0.808793</td>\n",
|
||
|
" <td>0.000318</td>\n",
|
||
|
" <td>0.000108</td>\n",
|
||
|
" <td>0.00014</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.0</td>\n",
|
||
|
" <td>0.0</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.000118</td>\n",
|
||
|
" <td>0.041755</td>\n",
|
||
|
" <td>0.392153</td>\n",
|
||
|
" <td>0.11544</td>\n",
|
||
|
" <td>4.174741</td>\n",
|
||
|
" <td>0.965327</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 1.018363 0.808793 0.000318 0.000108 0.00014 0.000189 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.0 0.0 0.000214 0.000037 0.000368 0.496391 \n",
|
||
|
"\n",
|
||
|
" HR F_2 Whole_average Reco in test Test coverage Shannon \\\n",
|
||
|
"0 0.003181 0.000118 0.041755 0.392153 0.11544 4.174741 \n",
|
||
|
"\n",
|
||
|
" Gini \n",
|
||
|
"0 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Self_IKNN_estimations.csv', header=None)\n",
|
||
|
"reco=np.loadtxt('Recommendations generated/ml-100k/Self_IKNN_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": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 3730.64it/s]\n",
|
||
|
"943it [00:00, 3921.13it/s]\n",
|
||
|
"943it [00:00, 3732.17it/s]\n",
|
||
|
"943it [00:00, 4078.27it/s]\n",
|
||
|
"943it [00:00, 2833.82it/s]\n",
|
||
|
"943it [00:00, 4027.94it/s]\n",
|
||
|
"943it [00:00, 4634.12it/s]\n",
|
||
|
"943it [00:00, 4453.36it/s]\n",
|
||
|
"943it [00:00, 4301.74it/s]\n",
|
||
|
"943it [00:00, 5008.94it/s]\n",
|
||
|
"943it [00:00, 3542.76it/s]\n",
|
||
|
"943it [00:00, 3280.94it/s]\n",
|
||
|
"943it [00:00, 3370.61it/s]\n",
|
||
|
"943it [00:00, 4467.43it/s]\n",
|
||
|
"943it [00:00, 3794.77it/s]\n",
|
||
|
"943it [00:00, 3759.22it/s]\n",
|
||
|
"943it [00:00, 4144.81it/s]\n",
|
||
|
"943it [00:00, 4232.41it/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>F_2</th>\n",
|
||
|
" <th>Whole_average</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.702928</td>\n",
|
||
|
" <td>3.527713</td>\n",
|
||
|
" <td>0.322694</td>\n",
|
||
|
" <td>0.216069</td>\n",
|
||
|
" <td>0.212152</td>\n",
|
||
|
" <td>0.247538</td>\n",
|
||
|
" <td>0.245279</td>\n",
|
||
|
" <td>0.284983</td>\n",
|
||
|
" <td>0.388271</td>\n",
|
||
|
" <td>0.248239</td>\n",
|
||
|
" <td>0.636318</td>\n",
|
||
|
" <td>0.605683</td>\n",
|
||
|
" <td>0.910923</td>\n",
|
||
|
" <td>0.205450</td>\n",
|
||
|
" <td>0.376967</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.178932</td>\n",
|
||
|
" <td>4.549663</td>\n",
|
||
|
" <td>0.950182</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_P3</td>\n",
|
||
|
" <td>3.702446</td>\n",
|
||
|
" <td>3.527273</td>\n",
|
||
|
" <td>0.282185</td>\n",
|
||
|
" <td>0.192092</td>\n",
|
||
|
" <td>0.186749</td>\n",
|
||
|
" <td>0.216980</td>\n",
|
||
|
" <td>0.204185</td>\n",
|
||
|
" <td>0.240096</td>\n",
|
||
|
" <td>0.339114</td>\n",
|
||
|
" <td>0.204905</td>\n",
|
||
|
" <td>0.572157</td>\n",
|
||
|
" <td>0.593544</td>\n",
|
||
|
" <td>0.875928</td>\n",
|
||
|
" <td>0.181702</td>\n",
|
||
|
" <td>0.340803</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>0.112750</td>\n",
|
||
|
" <td>0.249607</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_SVDBaseline</td>\n",
|
||
|
" <td>3.645666</td>\n",
|
||
|
" <td>3.480246</td>\n",
|
||
|
" <td>0.137858</td>\n",
|
||
|
" <td>0.082398</td>\n",
|
||
|
" <td>0.084151</td>\n",
|
||
|
" <td>0.101063</td>\n",
|
||
|
" <td>0.107940</td>\n",
|
||
|
" <td>0.109393</td>\n",
|
||
|
" <td>0.164477</td>\n",
|
||
|
" <td>0.082973</td>\n",
|
||
|
" <td>0.342374</td>\n",
|
||
|
" <td>0.538097</td>\n",
|
||
|
" <td>0.638388</td>\n",
|
||
|
" <td>0.079860</td>\n",
|
||
|
" <td>0.205748</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.279221</td>\n",
|
||
|
" <td>5.159076</td>\n",
|
||
|
" <td>0.907220</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVD</td>\n",
|
||
|
" <td>0.952563</td>\n",
|
||
|
" <td>0.750158</td>\n",
|
||
|
" <td>0.094486</td>\n",
|
||
|
" <td>0.046274</td>\n",
|
||
|
" <td>0.051389</td>\n",
|
||
|
" <td>0.065625</td>\n",
|
||
|
" <td>0.082618</td>\n",
|
||
|
" <td>0.074150</td>\n",
|
||
|
" <td>0.109320</td>\n",
|
||
|
" <td>0.051383</td>\n",
|
||
|
" <td>0.240693</td>\n",
|
||
|
" <td>0.519849</td>\n",
|
||
|
" <td>0.475080</td>\n",
|
||
|
" <td>0.046237</td>\n",
|
||
|
" <td>0.154759</td>\n",
|
||
|
" <td>0.993425</td>\n",
|
||
|
" <td>0.206349</td>\n",
|
||
|
" <td>4.442996</td>\n",
|
||
|
" <td>0.952832</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVD</td>\n",
|
||
|
" <td>0.914890</td>\n",
|
||
|
" <td>0.717962</td>\n",
|
||
|
" <td>0.102969</td>\n",
|
||
|
" <td>0.042325</td>\n",
|
||
|
" <td>0.052022</td>\n",
|
||
|
" <td>0.069313</td>\n",
|
||
|
" <td>0.093562</td>\n",
|
||
|
" <td>0.074994</td>\n",
|
||
|
" <td>0.105416</td>\n",
|
||
|
" <td>0.050278</td>\n",
|
||
|
" <td>0.191533</td>\n",
|
||
|
" <td>0.517890</td>\n",
|
||
|
" <td>0.462354</td>\n",
|
||
|
" <td>0.044591</td>\n",
|
||
|
" <td>0.150604</td>\n",
|
||
|
" <td>0.867656</td>\n",
|
||
|
" <td>0.141414</td>\n",
|
||
|
" <td>3.929249</td>\n",
|
||
|
" <td>0.971112</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>0.039549</td>\n",
|
||
|
" <td>0.141900</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_KNNSurprisetask</td>\n",
|
||
|
" <td>0.946255</td>\n",
|
||
|
" <td>0.745209</td>\n",
|
||
|
" <td>0.083457</td>\n",
|
||
|
" <td>0.032848</td>\n",
|
||
|
" <td>0.041227</td>\n",
|
||
|
" <td>0.055493</td>\n",
|
||
|
" <td>0.074785</td>\n",
|
||
|
" <td>0.048890</td>\n",
|
||
|
" <td>0.089577</td>\n",
|
||
|
" <td>0.040902</td>\n",
|
||
|
" <td>0.189057</td>\n",
|
||
|
" <td>0.513076</td>\n",
|
||
|
" <td>0.417815</td>\n",
|
||
|
" <td>0.034996</td>\n",
|
||
|
" <td>0.135177</td>\n",
|
||
|
" <td>0.888547</td>\n",
|
||
|
" <td>0.130592</td>\n",
|
||
|
" <td>3.611806</td>\n",
|
||
|
" <td>0.978659</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_TopRated</td>\n",
|
||
|
" <td>2.508258</td>\n",
|
||
|
" <td>2.217909</td>\n",
|
||
|
" <td>0.079321</td>\n",
|
||
|
" <td>0.032667</td>\n",
|
||
|
" <td>0.039983</td>\n",
|
||
|
" <td>0.053170</td>\n",
|
||
|
" <td>0.068884</td>\n",
|
||
|
" <td>0.048582</td>\n",
|
||
|
" <td>0.070766</td>\n",
|
||
|
" <td>0.027602</td>\n",
|
||
|
" <td>0.114790</td>\n",
|
||
|
" <td>0.512943</td>\n",
|
||
|
" <td>0.411453</td>\n",
|
||
|
" <td>0.034385</td>\n",
|
||
|
" <td>0.124546</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.024531</td>\n",
|
||
|
" <td>2.761238</td>\n",
|
||
|
" <td>0.991660</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVDBiased</td>\n",
|
||
|
" <td>0.942141</td>\n",
|
||
|
" <td>0.742760</td>\n",
|
||
|
" <td>0.081230</td>\n",
|
||
|
" <td>0.032344</td>\n",
|
||
|
" <td>0.040302</td>\n",
|
||
|
" <td>0.053932</td>\n",
|
||
|
" <td>0.072639</td>\n",
|
||
|
" <td>0.051126</td>\n",
|
||
|
" <td>0.087552</td>\n",
|
||
|
" <td>0.039346</td>\n",
|
||
|
" <td>0.191285</td>\n",
|
||
|
" <td>0.512818</td>\n",
|
||
|
" <td>0.416755</td>\n",
|
||
|
" <td>0.034405</td>\n",
|
||
|
" <td>0.134478</td>\n",
|
||
|
" <td>0.997667</td>\n",
|
||
|
" <td>0.165224</td>\n",
|
||
|
" <td>4.147579</td>\n",
|
||
|
" <td>0.964690</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>0.027213</td>\n",
|
||
|
" <td>0.118383</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.525633</td>\n",
|
||
|
" <td>1.225714</td>\n",
|
||
|
" <td>0.047720</td>\n",
|
||
|
" <td>0.022049</td>\n",
|
||
|
" <td>0.025494</td>\n",
|
||
|
" <td>0.032845</td>\n",
|
||
|
" <td>0.029077</td>\n",
|
||
|
" <td>0.025015</td>\n",
|
||
|
" <td>0.051757</td>\n",
|
||
|
" <td>0.019242</td>\n",
|
||
|
" <td>0.128181</td>\n",
|
||
|
" <td>0.507543</td>\n",
|
||
|
" <td>0.327678</td>\n",
|
||
|
" <td>0.022628</td>\n",
|
||
|
" <td>0.103269</td>\n",
|
||
|
" <td>0.987275</td>\n",
|
||
|
" <td>0.184704</td>\n",
|
||
|
" <td>5.105122</td>\n",
|
||
|
" <td>0.906561</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.008007</td>\n",
|
||
|
" <td>0.069521</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.000862</td>\n",
|
||
|
" <td>0.045379</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.000235</td>\n",
|
||
|
" <td>0.042533</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_BaselineIU</td>\n",
|
||
|
" <td>0.958136</td>\n",
|
||
|
" <td>0.754051</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.000220</td>\n",
|
||
|
" <td>0.042809</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.000201</td>\n",
|
||
|
" <td>0.042622</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.000118</td>\n",
|
||
|
" <td>0.041755</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.702928 3.527713 0.322694 0.216069 0.212152 \n",
|
||
|
"0 Self_P3 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 Self_SVDBaseline 3.645666 3.480246 0.137858 0.082398 0.084151 \n",
|
||
|
"0 Ready_SVD 0.952563 0.750158 0.094486 0.046274 0.051389 \n",
|
||
|
"0 Self_SVD 0.914890 0.717962 0.102969 0.042325 0.052022 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
||
|
"0 Self_KNNSurprisetask 0.946255 0.745209 0.083457 0.032848 0.041227 \n",
|
||
|
"0 Self_TopRated 2.508258 2.217909 0.079321 0.032667 0.039983 \n",
|
||
|
"0 Ready_SVDBiased 0.942141 0.742760 0.081230 0.032344 0.040302 \n",
|
||
|
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
|
||
|
"0 Ready_Random 1.525633 1.225714 0.047720 0.022049 0.025494 \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_BaselineIU 0.958136 0.754051 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.247538 0.245279 0.284983 0.388271 0.248239 0.636318 \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.101063 0.107940 0.109393 0.164477 0.082973 0.342374 \n",
|
||
|
"0 0.065625 0.082618 0.074150 0.109320 0.051383 0.240693 \n",
|
||
|
"0 0.069313 0.093562 0.074994 0.105416 0.050278 0.191533 \n",
|
||
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
||
|
"0 0.055493 0.074785 0.048890 0.089577 0.040902 0.189057 \n",
|
||
|
"0 0.053170 0.068884 0.048582 0.070766 0.027602 0.114790 \n",
|
||
|
"0 0.053932 0.072639 0.051126 0.087552 0.039346 0.191285 \n",
|
||
|
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
|
||
|
"0 0.032845 0.029077 0.025015 0.051757 0.019242 0.128181 \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 F_2 Whole_average Reco in test Test coverage \\\n",
|
||
|
"0 0.605683 0.910923 0.205450 0.376967 0.999788 0.178932 \n",
|
||
|
"0 0.593544 0.875928 0.181702 0.340803 1.000000 0.077201 \n",
|
||
|
"0 0.555546 0.765642 0.112750 0.249607 1.000000 0.038961 \n",
|
||
|
"0 0.538097 0.638388 0.079860 0.205748 0.999894 0.279221 \n",
|
||
|
"0 0.519849 0.475080 0.046237 0.154759 0.993425 0.206349 \n",
|
||
|
"0 0.517890 0.462354 0.044591 0.150604 0.867656 0.141414 \n",
|
||
|
"0 0.515501 0.437964 0.039549 0.141900 1.000000 0.033911 \n",
|
||
|
"0 0.513076 0.417815 0.034996 0.135177 0.888547 0.130592 \n",
|
||
|
"0 0.512943 0.411453 0.034385 0.124546 1.000000 0.024531 \n",
|
||
|
"0 0.512818 0.416755 0.034405 0.134478 0.997667 0.165224 \n",
|
||
|
"0 0.509546 0.384942 0.027213 0.118383 1.000000 0.025974 \n",
|
||
|
"0 0.507543 0.327678 0.022628 0.103269 0.987275 0.184704 \n",
|
||
|
"0 0.499885 0.154825 0.008007 0.069521 0.402333 0.434343 \n",
|
||
|
"0 0.496724 0.021209 0.000862 0.045379 0.482821 0.059885 \n",
|
||
|
"0 0.496441 0.007423 0.000235 0.042533 0.602121 0.010823 \n",
|
||
|
"0 0.496433 0.009544 0.000220 0.042809 0.699046 0.005051 \n",
|
||
|
"0 0.496424 0.009544 0.000201 0.042622 0.600530 0.005051 \n",
|
||
|
"0 0.496391 0.003181 0.000118 0.041755 0.392153 0.115440 \n",
|
||
|
"\n",
|
||
|
" Shannon Gini \n",
|
||
|
"0 4.549663 0.950182 \n",
|
||
|
"0 3.875892 0.974947 \n",
|
||
|
"0 3.159079 0.987317 \n",
|
||
|
"0 5.159076 0.907220 \n",
|
||
|
"0 4.442996 0.952832 \n",
|
||
|
"0 3.929249 0.971112 \n",
|
||
|
"0 2.836513 0.991139 \n",
|
||
|
"0 3.611806 0.978659 \n",
|
||
|
"0 2.761238 0.991660 \n",
|
||
|
"0 4.147579 0.964690 \n",
|
||
|
"0 2.711772 0.992003 \n",
|
||
|
"0 5.105122 0.906561 \n",
|
||
|
"0 5.133650 0.877999 \n",
|
||
|
"0 2.232578 0.994487 \n",
|
||
|
"0 2.089186 0.995706 \n",
|
||
|
"0 1.945910 0.995669 \n",
|
||
|
"0 1.803126 0.996380 \n",
|
||
|
"0 4.174741 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 6,
|
||
|
"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": [
|
||
|
"# Ready-made KNNs - Surprise implementation"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### I-KNN - basic"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Computing the cosine similarity matrix...\n",
|
||
|
"Done computing similarity matrix.\n",
|
||
|
"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",
|
||
|
"sim_options = {'name': 'cosine',\n",
|
||
|
" 'user_based': False} # compute similarities between items\n",
|
||
|
"algo = sp.KNNBasic(sim_options=sim_options)\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_I-KNN_reco.csv',\n",
|
||
|
" estimations_path='Recommendations generated/ml-100k/Ready_I-KNN_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### U-KNN - basic"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Computing the cosine similarity matrix...\n",
|
||
|
"Done computing similarity matrix.\n",
|
||
|
"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",
|
||
|
"sim_options = {'name': 'cosine',\n",
|
||
|
" 'user_based': True} # compute similarities between users\n",
|
||
|
"algo = sp.KNNBasic(sim_options=sim_options)\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_U-KNN_reco.csv',\n",
|
||
|
" estimations_path='Recommendations generated/ml-100k/Ready_U-KNN_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### I-KNN - on top baseline"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Estimating biases using als...\n",
|
||
|
"Computing the msd similarity matrix...\n",
|
||
|
"Done computing similarity matrix.\n",
|
||
|
"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",
|
||
|
"sim_options = {'name': 'cosine',\n",
|
||
|
" 'user_based': False} # compute similarities between items\n",
|
||
|
"algo = sp.KNNBaseline()\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_I-KNNBaseline_reco.csv',\n",
|
||
|
" estimations_path='Recommendations generated/ml-100k/Ready_I-KNNBaseline_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# project task 4: use a version of your choice of Surprise KNNalgorithm"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Estimating biases using als...\n",
|
||
|
"Computing the cosine similarity matrix...\n",
|
||
|
"Done computing similarity matrix.\n",
|
||
|
"Generating predictions...\n",
|
||
|
"Generating top N recommendations...\n",
|
||
|
"Generating predictions...\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# read the docs and try to find best parameter configuration (let say in terms of RMSE)\n",
|
||
|
"# https://surprise.readthedocs.io/en/stable/knn_inspired.html##surprise.prediction_algorithms.knns.KNNBaseline\n",
|
||
|
"# the solution here can be similar to examples above\n",
|
||
|
"# please save the output in 'Recommendations generated/ml-100k/Self_KNNSurprisetask_reco.csv' and\n",
|
||
|
"# 'Recommendations generated/ml-100k/Self_KNNSurprisetask_estimations.csv'\n",
|
||
|
"\n",
|
||
|
"## SOLUTION TASK 4\n",
|
||
|
"\n",
|
||
|
"import helpers\n",
|
||
|
"import surprise as sp\n",
|
||
|
"import imp\n",
|
||
|
"\n",
|
||
|
"imp.reload(helpers)\n",
|
||
|
"\n",
|
||
|
"sim_options = {'name': 'cosine',\n",
|
||
|
" 'user_based': False}\n",
|
||
|
"\n",
|
||
|
"algo = sp.KNNBaseline(sim_options = sim_options)\n",
|
||
|
"\n",
|
||
|
"helpers.ready_made(algo, reco_path = 'Recommendations generated/ml-100k/Self_KNNSurprisetask_reco.csv',\n",
|
||
|
" estimations_path = 'Recommendations generated/ml-100k/Self_KNNSurprisetask_estimations.csv')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 2579.01it/s]\n",
|
||
|
"943it [00:00, 2473.28it/s]\n",
|
||
|
"943it [00:00, 2787.61it/s]\n",
|
||
|
"943it [00:00, 2862.03it/s]\n",
|
||
|
"943it [00:00, 2636.14it/s]\n",
|
||
|
"943it [00:00, 2764.91it/s]\n",
|
||
|
"943it [00:00, 2362.52it/s]\n",
|
||
|
"943it [00:00, 2446.87it/s]\n",
|
||
|
"943it [00:00, 2961.39it/s]\n",
|
||
|
"943it [00:00, 2858.86it/s]\n",
|
||
|
"943it [00:00, 2449.24it/s]\n",
|
||
|
"943it [00:00, 2748.70it/s]\n",
|
||
|
"943it [00:00, 2379.95it/s]\n",
|
||
|
"943it [00:00, 2599.51it/s]\n",
|
||
|
"943it [00:00, 2705.51it/s]\n",
|
||
|
"943it [00:00, 2574.33it/s]\n",
|
||
|
"943it [00:00, 2450.80it/s]\n",
|
||
|
"943it [00:00, 2242.87it/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>F_2</th>\n",
|
||
|
" <th>Whole_average</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.702928</td>\n",
|
||
|
" <td>3.527713</td>\n",
|
||
|
" <td>0.322694</td>\n",
|
||
|
" <td>0.216069</td>\n",
|
||
|
" <td>0.212152</td>\n",
|
||
|
" <td>0.247538</td>\n",
|
||
|
" <td>0.245279</td>\n",
|
||
|
" <td>0.284983</td>\n",
|
||
|
" <td>0.388271</td>\n",
|
||
|
" <td>0.248239</td>\n",
|
||
|
" <td>0.636318</td>\n",
|
||
|
" <td>0.605683</td>\n",
|
||
|
" <td>0.910923</td>\n",
|
||
|
" <td>0.205450</td>\n",
|
||
|
" <td>0.376967</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.178932</td>\n",
|
||
|
" <td>4.549663</td>\n",
|
||
|
" <td>0.950182</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_P3</td>\n",
|
||
|
" <td>3.702446</td>\n",
|
||
|
" <td>3.527273</td>\n",
|
||
|
" <td>0.282185</td>\n",
|
||
|
" <td>0.192092</td>\n",
|
||
|
" <td>0.186749</td>\n",
|
||
|
" <td>0.216980</td>\n",
|
||
|
" <td>0.204185</td>\n",
|
||
|
" <td>0.240096</td>\n",
|
||
|
" <td>0.339114</td>\n",
|
||
|
" <td>0.204905</td>\n",
|
||
|
" <td>0.572157</td>\n",
|
||
|
" <td>0.593544</td>\n",
|
||
|
" <td>0.875928</td>\n",
|
||
|
" <td>0.181702</td>\n",
|
||
|
" <td>0.340803</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>0.112750</td>\n",
|
||
|
" <td>0.249607</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_SVDBaseline</td>\n",
|
||
|
" <td>3.645666</td>\n",
|
||
|
" <td>3.480246</td>\n",
|
||
|
" <td>0.137858</td>\n",
|
||
|
" <td>0.082398</td>\n",
|
||
|
" <td>0.084151</td>\n",
|
||
|
" <td>0.101063</td>\n",
|
||
|
" <td>0.107940</td>\n",
|
||
|
" <td>0.109393</td>\n",
|
||
|
" <td>0.164477</td>\n",
|
||
|
" <td>0.082973</td>\n",
|
||
|
" <td>0.342374</td>\n",
|
||
|
" <td>0.538097</td>\n",
|
||
|
" <td>0.638388</td>\n",
|
||
|
" <td>0.079860</td>\n",
|
||
|
" <td>0.205748</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.279221</td>\n",
|
||
|
" <td>5.159076</td>\n",
|
||
|
" <td>0.907220</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVD</td>\n",
|
||
|
" <td>0.952563</td>\n",
|
||
|
" <td>0.750158</td>\n",
|
||
|
" <td>0.094486</td>\n",
|
||
|
" <td>0.046274</td>\n",
|
||
|
" <td>0.051389</td>\n",
|
||
|
" <td>0.065625</td>\n",
|
||
|
" <td>0.082618</td>\n",
|
||
|
" <td>0.074150</td>\n",
|
||
|
" <td>0.109320</td>\n",
|
||
|
" <td>0.051383</td>\n",
|
||
|
" <td>0.240693</td>\n",
|
||
|
" <td>0.519849</td>\n",
|
||
|
" <td>0.475080</td>\n",
|
||
|
" <td>0.046237</td>\n",
|
||
|
" <td>0.154759</td>\n",
|
||
|
" <td>0.993425</td>\n",
|
||
|
" <td>0.206349</td>\n",
|
||
|
" <td>4.442996</td>\n",
|
||
|
" <td>0.952832</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVD</td>\n",
|
||
|
" <td>0.914890</td>\n",
|
||
|
" <td>0.717962</td>\n",
|
||
|
" <td>0.102969</td>\n",
|
||
|
" <td>0.042325</td>\n",
|
||
|
" <td>0.052022</td>\n",
|
||
|
" <td>0.069313</td>\n",
|
||
|
" <td>0.093562</td>\n",
|
||
|
" <td>0.074994</td>\n",
|
||
|
" <td>0.105416</td>\n",
|
||
|
" <td>0.050278</td>\n",
|
||
|
" <td>0.191533</td>\n",
|
||
|
" <td>0.517890</td>\n",
|
||
|
" <td>0.462354</td>\n",
|
||
|
" <td>0.044591</td>\n",
|
||
|
" <td>0.150604</td>\n",
|
||
|
" <td>0.867656</td>\n",
|
||
|
" <td>0.141414</td>\n",
|
||
|
" <td>3.929249</td>\n",
|
||
|
" <td>0.971112</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>0.039549</td>\n",
|
||
|
" <td>0.141900</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_KNNSurprisetask</td>\n",
|
||
|
" <td>0.946255</td>\n",
|
||
|
" <td>0.745209</td>\n",
|
||
|
" <td>0.083457</td>\n",
|
||
|
" <td>0.032848</td>\n",
|
||
|
" <td>0.041227</td>\n",
|
||
|
" <td>0.055493</td>\n",
|
||
|
" <td>0.074785</td>\n",
|
||
|
" <td>0.048890</td>\n",
|
||
|
" <td>0.089577</td>\n",
|
||
|
" <td>0.040902</td>\n",
|
||
|
" <td>0.189057</td>\n",
|
||
|
" <td>0.513076</td>\n",
|
||
|
" <td>0.417815</td>\n",
|
||
|
" <td>0.034996</td>\n",
|
||
|
" <td>0.135177</td>\n",
|
||
|
" <td>0.888547</td>\n",
|
||
|
" <td>0.130592</td>\n",
|
||
|
" <td>3.611806</td>\n",
|
||
|
" <td>0.978659</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_TopRated</td>\n",
|
||
|
" <td>2.508258</td>\n",
|
||
|
" <td>2.217909</td>\n",
|
||
|
" <td>0.079321</td>\n",
|
||
|
" <td>0.032667</td>\n",
|
||
|
" <td>0.039983</td>\n",
|
||
|
" <td>0.053170</td>\n",
|
||
|
" <td>0.068884</td>\n",
|
||
|
" <td>0.048582</td>\n",
|
||
|
" <td>0.070766</td>\n",
|
||
|
" <td>0.027602</td>\n",
|
||
|
" <td>0.114790</td>\n",
|
||
|
" <td>0.512943</td>\n",
|
||
|
" <td>0.411453</td>\n",
|
||
|
" <td>0.034385</td>\n",
|
||
|
" <td>0.124546</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.024531</td>\n",
|
||
|
" <td>2.761238</td>\n",
|
||
|
" <td>0.991660</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVDBiased</td>\n",
|
||
|
" <td>0.942141</td>\n",
|
||
|
" <td>0.742760</td>\n",
|
||
|
" <td>0.081230</td>\n",
|
||
|
" <td>0.032344</td>\n",
|
||
|
" <td>0.040302</td>\n",
|
||
|
" <td>0.053932</td>\n",
|
||
|
" <td>0.072639</td>\n",
|
||
|
" <td>0.051126</td>\n",
|
||
|
" <td>0.087552</td>\n",
|
||
|
" <td>0.039346</td>\n",
|
||
|
" <td>0.191285</td>\n",
|
||
|
" <td>0.512818</td>\n",
|
||
|
" <td>0.416755</td>\n",
|
||
|
" <td>0.034405</td>\n",
|
||
|
" <td>0.134478</td>\n",
|
||
|
" <td>0.997667</td>\n",
|
||
|
" <td>0.165224</td>\n",
|
||
|
" <td>4.147579</td>\n",
|
||
|
" <td>0.964690</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>0.027213</td>\n",
|
||
|
" <td>0.118383</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.525633</td>\n",
|
||
|
" <td>1.225714</td>\n",
|
||
|
" <td>0.047720</td>\n",
|
||
|
" <td>0.022049</td>\n",
|
||
|
" <td>0.025494</td>\n",
|
||
|
" <td>0.032845</td>\n",
|
||
|
" <td>0.029077</td>\n",
|
||
|
" <td>0.025015</td>\n",
|
||
|
" <td>0.051757</td>\n",
|
||
|
" <td>0.019242</td>\n",
|
||
|
" <td>0.128181</td>\n",
|
||
|
" <td>0.507543</td>\n",
|
||
|
" <td>0.327678</td>\n",
|
||
|
" <td>0.022628</td>\n",
|
||
|
" <td>0.103269</td>\n",
|
||
|
" <td>0.987275</td>\n",
|
||
|
" <td>0.184704</td>\n",
|
||
|
" <td>5.105122</td>\n",
|
||
|
" <td>0.906561</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.008007</td>\n",
|
||
|
" <td>0.069521</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.000862</td>\n",
|
||
|
" <td>0.045379</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.000235</td>\n",
|
||
|
" <td>0.042533</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_BaselineIU</td>\n",
|
||
|
" <td>0.958136</td>\n",
|
||
|
" <td>0.754051</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.000220</td>\n",
|
||
|
" <td>0.042809</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.000201</td>\n",
|
||
|
" <td>0.042622</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.000118</td>\n",
|
||
|
" <td>0.041755</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.702928 3.527713 0.322694 0.216069 0.212152 \n",
|
||
|
"0 Self_P3 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 Self_SVDBaseline 3.645666 3.480246 0.137858 0.082398 0.084151 \n",
|
||
|
"0 Ready_SVD 0.952563 0.750158 0.094486 0.046274 0.051389 \n",
|
||
|
"0 Self_SVD 0.914890 0.717962 0.102969 0.042325 0.052022 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
||
|
"0 Self_KNNSurprisetask 0.946255 0.745209 0.083457 0.032848 0.041227 \n",
|
||
|
"0 Self_TopRated 2.508258 2.217909 0.079321 0.032667 0.039983 \n",
|
||
|
"0 Ready_SVDBiased 0.942141 0.742760 0.081230 0.032344 0.040302 \n",
|
||
|
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
|
||
|
"0 Ready_Random 1.525633 1.225714 0.047720 0.022049 0.025494 \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_BaselineIU 0.958136 0.754051 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.247538 0.245279 0.284983 0.388271 0.248239 0.636318 \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.101063 0.107940 0.109393 0.164477 0.082973 0.342374 \n",
|
||
|
"0 0.065625 0.082618 0.074150 0.109320 0.051383 0.240693 \n",
|
||
|
"0 0.069313 0.093562 0.074994 0.105416 0.050278 0.191533 \n",
|
||
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
||
|
"0 0.055493 0.074785 0.048890 0.089577 0.040902 0.189057 \n",
|
||
|
"0 0.053170 0.068884 0.048582 0.070766 0.027602 0.114790 \n",
|
||
|
"0 0.053932 0.072639 0.051126 0.087552 0.039346 0.191285 \n",
|
||
|
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
|
||
|
"0 0.032845 0.029077 0.025015 0.051757 0.019242 0.128181 \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 F_2 Whole_average Reco in test Test coverage \\\n",
|
||
|
"0 0.605683 0.910923 0.205450 0.376967 0.999788 0.178932 \n",
|
||
|
"0 0.593544 0.875928 0.181702 0.340803 1.000000 0.077201 \n",
|
||
|
"0 0.555546 0.765642 0.112750 0.249607 1.000000 0.038961 \n",
|
||
|
"0 0.538097 0.638388 0.079860 0.205748 0.999894 0.279221 \n",
|
||
|
"0 0.519849 0.475080 0.046237 0.154759 0.993425 0.206349 \n",
|
||
|
"0 0.517890 0.462354 0.044591 0.150604 0.867656 0.141414 \n",
|
||
|
"0 0.515501 0.437964 0.039549 0.141900 1.000000 0.033911 \n",
|
||
|
"0 0.513076 0.417815 0.034996 0.135177 0.888547 0.130592 \n",
|
||
|
"0 0.512943 0.411453 0.034385 0.124546 1.000000 0.024531 \n",
|
||
|
"0 0.512818 0.416755 0.034405 0.134478 0.997667 0.165224 \n",
|
||
|
"0 0.509546 0.384942 0.027213 0.118383 1.000000 0.025974 \n",
|
||
|
"0 0.507543 0.327678 0.022628 0.103269 0.987275 0.184704 \n",
|
||
|
"0 0.499885 0.154825 0.008007 0.069521 0.402333 0.434343 \n",
|
||
|
"0 0.496724 0.021209 0.000862 0.045379 0.482821 0.059885 \n",
|
||
|
"0 0.496441 0.007423 0.000235 0.042533 0.602121 0.010823 \n",
|
||
|
"0 0.496433 0.009544 0.000220 0.042809 0.699046 0.005051 \n",
|
||
|
"0 0.496424 0.009544 0.000201 0.042622 0.600530 0.005051 \n",
|
||
|
"0 0.496391 0.003181 0.000118 0.041755 0.392153 0.115440 \n",
|
||
|
"\n",
|
||
|
" Shannon Gini \n",
|
||
|
"0 4.549663 0.950182 \n",
|
||
|
"0 3.875892 0.974947 \n",
|
||
|
"0 3.159079 0.987317 \n",
|
||
|
"0 5.159076 0.907220 \n",
|
||
|
"0 4.442996 0.952832 \n",
|
||
|
"0 3.929249 0.971112 \n",
|
||
|
"0 2.836513 0.991139 \n",
|
||
|
"0 3.611806 0.978659 \n",
|
||
|
"0 2.761238 0.991660 \n",
|
||
|
"0 4.147579 0.964690 \n",
|
||
|
"0 2.711772 0.992003 \n",
|
||
|
"0 5.105122 0.906561 \n",
|
||
|
"0 5.133650 0.877999 \n",
|
||
|
"0 2.232578 0.994487 \n",
|
||
|
"0 2.089186 0.995706 \n",
|
||
|
"0 1.945910 0.995669 \n",
|
||
|
"0 1.803126 0.996380 \n",
|
||
|
"0 4.174741 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"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": "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.6.9"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|