2664 lines
92 KiB
Plaintext
2664 lines
92 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Prepare test set"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {
|
||
|
"slideshow": {
|
||
|
"slide_type": "-"
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"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",
|
||
|
"from tqdm import tqdm\n",
|
||
|
"\n",
|
||
|
"# In evaluation we do not load train set - it is not needed\n",
|
||
|
"test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
|
||
|
"test.columns=['user', 'item', 'rating', 'timestamp']\n",
|
||
|
"\n",
|
||
|
"test['user_code'] = test['user'].astype(\"category\").cat.codes\n",
|
||
|
"test['item_code'] = test['item'].astype(\"category\").cat.codes\n",
|
||
|
"\n",
|
||
|
"user_code_id = dict(enumerate(test['user'].astype(\"category\").cat.categories))\n",
|
||
|
"user_id_code = dict((v, k) for k, v in user_code_id.items())\n",
|
||
|
"item_code_id = dict(enumerate(test['item'].astype(\"category\").cat.categories))\n",
|
||
|
"item_id_code = dict((v, k) for k, v in item_code_id.items())\n",
|
||
|
"\n",
|
||
|
"test_ui = sparse.csr_matrix((test['rating'], (test['user_code'], test['item_code'])))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Estimations metrics"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Ready_Baseline_estimations.csv', header=None)\n",
|
||
|
"estimations_df.columns=['user', 'item' ,'score']\n",
|
||
|
"\n",
|
||
|
"estimations_df['user_code']=[user_id_code[user] for user in estimations_df['user']]\n",
|
||
|
"estimations_df['item_code']=[item_id_code[item] for item in estimations_df['item']]\n",
|
||
|
"estimations=sparse.csr_matrix((estimations_df['score'], (estimations_df['user_code'], estimations_df['item_code'])), shape=test_ui.shape)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def estimations_metrics(test_ui, estimations):\n",
|
||
|
" result=[]\n",
|
||
|
"\n",
|
||
|
" RMSE=(np.sum((estimations.data-test_ui.data)**2)/estimations.nnz)**(1/2)\n",
|
||
|
" result.append(['RMSE', RMSE])\n",
|
||
|
"\n",
|
||
|
" MAE=np.sum(abs(estimations.data-test_ui.data))/estimations.nnz\n",
|
||
|
" result.append(['MAE', MAE])\n",
|
||
|
" \n",
|
||
|
" df_result=(pd.DataFrame(list(zip(*result))[1])).T\n",
|
||
|
" df_result.columns=list(zip(*result))[0]\n",
|
||
|
" return df_result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>RMSE</th>\n",
|
||
|
" <th>MAE</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>0.949459</td>\n",
|
||
|
" <td>0.752487</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE\n",
|
||
|
"0 0.949459 0.752487"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# in case of error (in the laboratories) you might have to switch to the other version of pandas\n",
|
||
|
"# try !pip3 install pandas=='1.0.3' (or pip if you use python 2) and restart the kernel\n",
|
||
|
"\n",
|
||
|
"estimations_metrics(test_ui, estimations)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Ranking metrics"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[663, 475, 62, ..., 472, 269, 503],\n",
|
||
|
" [ 48, 313, 475, ..., 591, 175, 466],\n",
|
||
|
" [351, 313, 475, ..., 591, 175, 466],\n",
|
||
|
" ...,\n",
|
||
|
" [259, 313, 475, ..., 11, 591, 175],\n",
|
||
|
" [ 33, 313, 475, ..., 11, 591, 175],\n",
|
||
|
" [ 77, 313, 475, ..., 11, 591, 175]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"reco = np.loadtxt('Recommendations generated/ml-100k/Ready_Baseline_reco.csv', delimiter=',')\n",
|
||
|
"# Let's ignore scores - they are not used in evaluation: \n",
|
||
|
"users=reco[:,:1]\n",
|
||
|
"items=reco[:,1::2]\n",
|
||
|
"# Let's use inner ids instead of real ones\n",
|
||
|
"users=np.vectorize(lambda x: user_id_code.setdefault(x, -1))(users)\n",
|
||
|
"items=np.vectorize(lambda x: item_id_code.setdefault(x, -1))(items) # maybe items we recommend are not in test set\n",
|
||
|
"# Let's put them into one array\n",
|
||
|
"reco=np.concatenate((users, items), axis=1)\n",
|
||
|
"reco"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def ranking_metrics(test_ui, reco, super_reactions=[], topK=10):\n",
|
||
|
" \n",
|
||
|
" nb_items=test_ui.shape[1]\n",
|
||
|
" relevant_users, super_relevant_users, prec, rec, F_1, F_05, prec_super, rec_super, ndcg, mAP, MRR, LAUC, HR=\\\n",
|
||
|
" 0,0,0,0,0,0,0,0,0,0,0,0,0\n",
|
||
|
" \n",
|
||
|
" cg = (1.0 / np.log2(np.arange(2, topK + 2)))\n",
|
||
|
" cg_sum = np.cumsum(cg)\n",
|
||
|
" \n",
|
||
|
" for (nb_user, user) in tqdm(enumerate(reco[:,0])):\n",
|
||
|
" u_rated_items=test_ui.indices[test_ui.indptr[user]:test_ui.indptr[user+1]]\n",
|
||
|
" nb_u_rated_items=len(u_rated_items)\n",
|
||
|
" if nb_u_rated_items>0: # skip users with no items in test set (still possible that there will be no super items)\n",
|
||
|
" relevant_users+=1\n",
|
||
|
" \n",
|
||
|
" u_super_items=u_rated_items[np.vectorize(lambda x: x in super_reactions)\\\n",
|
||
|
" (test_ui.data[test_ui.indptr[user]:test_ui.indptr[user+1]])]\n",
|
||
|
" # more natural seems u_super_items=[item for item in u_rated_items if test_ui[user,item] in super_reactions]\n",
|
||
|
" # but accesing test_ui[user,item] is expensive -we should avoid doing it\n",
|
||
|
" if len(u_super_items)>0:\n",
|
||
|
" super_relevant_users+=1\n",
|
||
|
" \n",
|
||
|
" user_successes=np.zeros(topK)\n",
|
||
|
" nb_user_successes=0\n",
|
||
|
" user_super_successes=np.zeros(topK)\n",
|
||
|
" nb_user_super_successes=0\n",
|
||
|
" \n",
|
||
|
" # evaluation\n",
|
||
|
" for (item_position,item) in enumerate(reco[nb_user,1:topK+1]):\n",
|
||
|
" if item in u_rated_items:\n",
|
||
|
" user_successes[item_position]=1\n",
|
||
|
" nb_user_successes+=1\n",
|
||
|
" if item in u_super_items:\n",
|
||
|
" user_super_successes[item_position]=1\n",
|
||
|
" nb_user_super_successes+=1\n",
|
||
|
" \n",
|
||
|
" prec_u=nb_user_successes/topK \n",
|
||
|
" prec+=prec_u\n",
|
||
|
" \n",
|
||
|
" rec_u=nb_user_successes/nb_u_rated_items\n",
|
||
|
" rec+=rec_u\n",
|
||
|
" \n",
|
||
|
" F_1+=2*(prec_u*rec_u)/(prec_u+rec_u) if prec_u+rec_u>0 else 0\n",
|
||
|
" F_05+=(0.5**2+1)*(prec_u*rec_u)/(0.5**2*prec_u+rec_u) if prec_u+rec_u>0 else 0\n",
|
||
|
" \n",
|
||
|
" prec_super+=nb_user_super_successes/topK\n",
|
||
|
" rec_super+=nb_user_super_successes/max(len(u_super_items),1) # to set 0 if no super items\n",
|
||
|
" ndcg+=np.dot(user_successes,cg)/cg_sum[min(topK, nb_u_rated_items)-1]\n",
|
||
|
" \n",
|
||
|
" cumsum_successes=np.cumsum(user_successes)\n",
|
||
|
" mAP+=np.dot(cumsum_successes/np.arange(1,topK+1), user_successes)/min(topK, nb_u_rated_items)\n",
|
||
|
" MRR+=1/(user_successes.nonzero()[0][0]+1) if user_successes.nonzero()[0].size>0 else 0\n",
|
||
|
" LAUC+=(np.dot(cumsum_successes, 1-user_successes)+\\\n",
|
||
|
" (nb_user_successes+nb_u_rated_items)/2*((nb_items-nb_u_rated_items)-(topK-nb_user_successes)))/\\\n",
|
||
|
" ((nb_items-nb_u_rated_items)*nb_u_rated_items)\n",
|
||
|
" \n",
|
||
|
" HR+=nb_user_successes>0\n",
|
||
|
" \n",
|
||
|
" \n",
|
||
|
" result=[]\n",
|
||
|
" result.append(('precision', prec/relevant_users))\n",
|
||
|
" result.append(('recall', rec/relevant_users))\n",
|
||
|
" result.append(('F_1', F_1/relevant_users))\n",
|
||
|
" result.append(('F_05', F_05/relevant_users))\n",
|
||
|
" result.append(('precision_super', prec_super/super_relevant_users))\n",
|
||
|
" result.append(('recall_super', rec_super/super_relevant_users))\n",
|
||
|
" result.append(('NDCG', ndcg/relevant_users))\n",
|
||
|
" result.append(('mAP', mAP/relevant_users))\n",
|
||
|
" result.append(('MRR', MRR/relevant_users))\n",
|
||
|
" result.append(('LAUC', LAUC/relevant_users))\n",
|
||
|
" result.append(('HR', HR/relevant_users))\n",
|
||
|
"\n",
|
||
|
" df_result=(pd.DataFrame(list(zip(*result))[1])).T\n",
|
||
|
" df_result.columns=list(zip(*result))[0]\n",
|
||
|
" return df_result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 2282.19it/s]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>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",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>0.09141</td>\n",
|
||
|
" <td>0.037652</td>\n",
|
||
|
" <td>0.04603</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",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" precision recall F_1 F_05 precision_super recall_super \\\n",
|
||
|
"0 0.09141 0.037652 0.04603 0.061286 0.079614 0.056463 \n",
|
||
|
"\n",
|
||
|
" NDCG mAP MRR LAUC HR \n",
|
||
|
"0 0.095957 0.043178 0.198193 0.515501 0.437964 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"ranking_metrics(test_ui, reco, super_reactions=[4,5], topK=10)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Diversity metrics"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def diversity_metrics(test_ui, reco, topK=10):\n",
|
||
|
" \n",
|
||
|
" frequencies=defaultdict(int)\n",
|
||
|
" \n",
|
||
|
" # let's assign 0 to all items in test set\n",
|
||
|
" for item in list(set(test_ui.indices)):\n",
|
||
|
" frequencies[item]=0\n",
|
||
|
" \n",
|
||
|
" # counting frequencies\n",
|
||
|
" for item in reco[:,1:].flat:\n",
|
||
|
" frequencies[item]+=1\n",
|
||
|
" \n",
|
||
|
" nb_reco_outside_test=frequencies[-1]\n",
|
||
|
" del frequencies[-1]\n",
|
||
|
" \n",
|
||
|
" frequencies=np.array(list(frequencies.values()))\n",
|
||
|
" \n",
|
||
|
" nb_rec_items=len(frequencies[frequencies>0])\n",
|
||
|
" nb_reco_inside_test=np.sum(frequencies)\n",
|
||
|
" \n",
|
||
|
" frequencies=frequencies/np.sum(frequencies)\n",
|
||
|
" frequencies=np.sort(frequencies)\n",
|
||
|
" \n",
|
||
|
" with np.errstate(divide='ignore'): # let's put zeros put items with 0 frequency and ignore division warning\n",
|
||
|
" log_frequencies=np.nan_to_num(np.log(frequencies), posinf=0, neginf=0)\n",
|
||
|
" \n",
|
||
|
" result=[]\n",
|
||
|
" result.append(('Reco in test', nb_reco_inside_test/(nb_reco_inside_test+nb_reco_outside_test)))\n",
|
||
|
" result.append(('Test coverage', nb_rec_items/test_ui.shape[1]))\n",
|
||
|
" result.append(('Shannon', -np.dot(frequencies, log_frequencies)))\n",
|
||
|
" result.append(('Gini', np.dot(frequencies, np.arange(1-len(frequencies), len(frequencies), 2))/(len(frequencies)-1)))\n",
|
||
|
" \n",
|
||
|
" df_result=(pd.DataFrame(list(zip(*result))[1])).T\n",
|
||
|
" df_result.columns=list(zip(*result))[0]\n",
|
||
|
" return df_result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>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.0</td>\n",
|
||
|
" <td>0.033911</td>\n",
|
||
|
" <td>2.836513</td>\n",
|
||
|
" <td>0.991139</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Reco in test Test coverage Shannon Gini\n",
|
||
|
"0 1.0 0.033911 2.836513 0.991139"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# in case of errors try !pip3 install numpy==1.18.4 (or pip if you use python 2) and restart the kernel\n",
|
||
|
"\n",
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"import imp\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\n",
|
||
|
"x=diversity_metrics(test_ui, reco, topK=10)\n",
|
||
|
"x"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# To be used in other notebooks"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 2668.06it/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>0.949459</td>\n",
|
||
|
" <td>0.752487</td>\n",
|
||
|
" <td>0.09141</td>\n",
|
||
|
" <td>0.037652</td>\n",
|
||
|
" <td>0.04603</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.1419</td>\n",
|
||
|
" <td>1.0</td>\n",
|
||
|
" <td>0.033911</td>\n",
|
||
|
" <td>2.836513</td>\n",
|
||
|
" <td>0.991139</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 0.949459 0.752487 0.09141 0.037652 0.04603 0.061286 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.079614 0.056463 0.095957 0.043178 0.198193 0.515501 \n",
|
||
|
"\n",
|
||
|
" HR F_2 Whole_average Reco in test Test coverage Shannon \\\n",
|
||
|
"0 0.437964 0.039549 0.1419 1.0 0.033911 2.836513 \n",
|
||
|
"\n",
|
||
|
" Gini \n",
|
||
|
"0 0.991139 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"import imp\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\n",
|
||
|
"estimations_df=pd.read_csv('Recommendations generated/ml-100k/Ready_Baseline_estimations.csv', header=None)\n",
|
||
|
"reco=np.loadtxt('Recommendations generated/ml-100k/Ready_Baseline_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])\n",
|
||
|
"#also you can just type ev.evaluate_all(estimations_df, reco) - I put above values as default"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 3513.93it/s]\n",
|
||
|
"943it [00:00, 5048.26it/s]\n",
|
||
|
"943it [00:00, 4530.47it/s]\n",
|
||
|
"943it [00:00, 5016.38it/s]\n",
|
||
|
"943it [00:00, 3958.29it/s]\n",
|
||
|
"943it [00:00, 4004.71it/s]\n",
|
||
|
"943it [00:00, 4465.19it/s]\n",
|
||
|
"943it [00:00, 4760.13it/s]\n",
|
||
|
"943it [00:00, 4948.57it/s]\n",
|
||
|
"943it [00:00, 3895.70it/s]\n",
|
||
|
"943it [00:00, 4446.36it/s]\n",
|
||
|
"943it [00:00, 5322.70it/s]\n",
|
||
|
"943it [00:00, 4464.53it/s]\n",
|
||
|
"943it [00:00, 5275.54it/s]\n",
|
||
|
"943it [00:00, 5161.31it/s]\n",
|
||
|
"943it [00:00, 2960.67it/s]\n",
|
||
|
"943it [00:00, 4734.14it/s]\n",
|
||
|
"943it [00:00, 3319.18it/s]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"import imp\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\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",
|
||
|
"df=ev.evaluate_all(test, dir_path, super_reactions)\n",
|
||
|
"#also you can just type ev.evaluate_all() - I put above values as default"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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",
|
||
|
" </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 \n",
|
||
|
"0 0.247538 0.245279 0.284983 \n",
|
||
|
"0 0.216980 0.204185 0.240096 \n",
|
||
|
"0 0.141584 0.130472 0.137473 \n",
|
||
|
"0 0.101063 0.107940 0.109393 \n",
|
||
|
"0 0.065625 0.082618 0.074150 \n",
|
||
|
"0 0.069313 0.093562 0.074994 \n",
|
||
|
"0 0.061286 0.079614 0.056463 \n",
|
||
|
"0 0.055493 0.074785 0.048890 \n",
|
||
|
"0 0.053170 0.068884 0.048582 \n",
|
||
|
"0 0.053932 0.072639 0.051126 \n",
|
||
|
"0 0.041343 0.040558 0.032107 \n",
|
||
|
"0 0.032845 0.029077 0.025015 \n",
|
||
|
"0 0.016046 0.021137 0.009522 \n",
|
||
|
"0 0.001602 0.002253 0.000930 \n",
|
||
|
"0 0.000449 0.000536 0.000198 \n",
|
||
|
"0 0.000481 0.000644 0.000223 \n",
|
||
|
"0 0.000463 0.000644 0.000189 \n",
|
||
|
"0 0.000189 0.000000 0.000000 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.iloc[:,:9]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>Model</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>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>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>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>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.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.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.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.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>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.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>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>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>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.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>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.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.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>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 NDCG mAP MRR LAUC HR \\\n",
|
||
|
"0 Self_RP3Beta 0.388271 0.248239 0.636318 0.605683 0.910923 \n",
|
||
|
"0 Self_P3 0.339114 0.204905 0.572157 0.593544 0.875928 \n",
|
||
|
"0 Self_TopPop 0.214651 0.111707 0.400939 0.555546 0.765642 \n",
|
||
|
"0 Self_SVDBaseline 0.164477 0.082973 0.342374 0.538097 0.638388 \n",
|
||
|
"0 Ready_SVD 0.109320 0.051383 0.240693 0.519849 0.475080 \n",
|
||
|
"0 Self_SVD 0.105416 0.050278 0.191533 0.517890 0.462354 \n",
|
||
|
"0 Ready_Baseline 0.095957 0.043178 0.198193 0.515501 0.437964 \n",
|
||
|
"0 Self_KNNSurprisetask 0.089577 0.040902 0.189057 0.513076 0.417815 \n",
|
||
|
"0 Self_TopRated 0.070766 0.027602 0.114790 0.512943 0.411453 \n",
|
||
|
"0 Ready_SVDBiased 0.087552 0.039346 0.191285 0.512818 0.416755 \n",
|
||
|
"0 Self_GlobalAvg 0.067695 0.027470 0.171187 0.509546 0.384942 \n",
|
||
|
"0 Ready_Random 0.051757 0.019242 0.128181 0.507543 0.327678 \n",
|
||
|
"0 Ready_I-KNN 0.024214 0.008958 0.048068 0.499885 0.154825 \n",
|
||
|
"0 Ready_I-KNNBaseline 0.003444 0.001362 0.011760 0.496724 0.021209 \n",
|
||
|
"0 Ready_U-KNN 0.000845 0.000274 0.002744 0.496441 0.007423 \n",
|
||
|
"0 Self_BaselineIU 0.001043 0.000335 0.003348 0.496433 0.009544 \n",
|
||
|
"0 Self_BaselineUI 0.000752 0.000168 0.001677 0.496424 0.009544 \n",
|
||
|
"0 Self_IKNN 0.000214 0.000037 0.000368 0.496391 0.003181 \n",
|
||
|
"\n",
|
||
|
" F_2 Whole_average Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.205450 0.376967 0.999788 0.178932 4.549663 0.950182 \n",
|
||
|
"0 0.181702 0.340803 1.000000 0.077201 3.875892 0.974947 \n",
|
||
|
"0 0.112750 0.249607 1.000000 0.038961 3.159079 0.987317 \n",
|
||
|
"0 0.079860 0.205748 0.999894 0.279221 5.159076 0.907220 \n",
|
||
|
"0 0.046237 0.154759 0.993425 0.206349 4.442996 0.952832 \n",
|
||
|
"0 0.044591 0.150604 0.867656 0.141414 3.929249 0.971112 \n",
|
||
|
"0 0.039549 0.141900 1.000000 0.033911 2.836513 0.991139 \n",
|
||
|
"0 0.034996 0.135177 0.888547 0.130592 3.611806 0.978659 \n",
|
||
|
"0 0.034385 0.124546 1.000000 0.024531 2.761238 0.991660 \n",
|
||
|
"0 0.034405 0.134478 0.997667 0.165224 4.147579 0.964690 \n",
|
||
|
"0 0.027213 0.118383 1.000000 0.025974 2.711772 0.992003 \n",
|
||
|
"0 0.022628 0.103269 0.987275 0.184704 5.105122 0.906561 \n",
|
||
|
"0 0.008007 0.069521 0.402333 0.434343 5.133650 0.877999 \n",
|
||
|
"0 0.000862 0.045379 0.482821 0.059885 2.232578 0.994487 \n",
|
||
|
"0 0.000235 0.042533 0.602121 0.010823 2.089186 0.995706 \n",
|
||
|
"0 0.000220 0.042809 0.699046 0.005051 1.945910 0.995669 \n",
|
||
|
"0 0.000201 0.042622 0.600530 0.005051 1.803126 0.996380 \n",
|
||
|
"0 0.000118 0.041755 0.392153 0.115440 4.174741 0.965327 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"df.iloc[:,np.append(0,np.arange(9, df.shape[1]))]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Check metrics on toy dataset"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"3it [00:00, 1024.67it/s]\n",
|
||
|
"3it [00:00, 2922.18it/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_BaselineIU</td>\n",
|
||
|
" <td>1.648337</td>\n",
|
||
|
" <td>1.575</td>\n",
|
||
|
" <td>0.444444</td>\n",
|
||
|
" <td>0.888889</td>\n",
|
||
|
" <td>0.555556</td>\n",
|
||
|
" <td>0.478632</td>\n",
|
||
|
" <td>0.333333</td>\n",
|
||
|
" <td>0.75</td>\n",
|
||
|
" <td>0.720550</td>\n",
|
||
|
" <td>0.629630</td>\n",
|
||
|
" <td>0.666667</td>\n",
|
||
|
" <td>0.722222</td>\n",
|
||
|
" <td>1.0</td>\n",
|
||
|
" <td>0.698413</td>\n",
|
||
|
" <td>0.657361</td>\n",
|
||
|
" <td>0.777778</td>\n",
|
||
|
" <td>0.8</td>\n",
|
||
|
" <td>1.351784</td>\n",
|
||
|
" <td>0.357143</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_BaselineUI</td>\n",
|
||
|
" <td>1.612452</td>\n",
|
||
|
" <td>1.400</td>\n",
|
||
|
" <td>0.444444</td>\n",
|
||
|
" <td>0.888889</td>\n",
|
||
|
" <td>0.555556</td>\n",
|
||
|
" <td>0.478632</td>\n",
|
||
|
" <td>0.333333</td>\n",
|
||
|
" <td>0.75</td>\n",
|
||
|
" <td>0.676907</td>\n",
|
||
|
" <td>0.574074</td>\n",
|
||
|
" <td>0.611111</td>\n",
|
||
|
" <td>0.638889</td>\n",
|
||
|
" <td>1.0</td>\n",
|
||
|
" <td>0.698413</td>\n",
|
||
|
" <td>0.637521</td>\n",
|
||
|
" <td>0.888889</td>\n",
|
||
|
" <td>0.8</td>\n",
|
||
|
" <td>1.386294</td>\n",
|
||
|
" <td>0.250000</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Model RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 Self_BaselineIU 1.648337 1.575 0.444444 0.888889 0.555556 0.478632 \n",
|
||
|
"0 Self_BaselineUI 1.612452 1.400 0.444444 0.888889 0.555556 0.478632 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC HR \\\n",
|
||
|
"0 0.333333 0.75 0.720550 0.629630 0.666667 0.722222 1.0 \n",
|
||
|
"0 0.333333 0.75 0.676907 0.574074 0.611111 0.638889 1.0 \n",
|
||
|
"\n",
|
||
|
" F_2 Whole_average Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.698413 0.657361 0.777778 0.8 1.351784 0.357143 \n",
|
||
|
"0 0.698413 0.637521 0.888889 0.8 1.386294 0.250000 "
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Training data:\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"matrix([[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": [
|
||
|
"Test data:\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"matrix([[0, 0, 0, 0, 0, 0, 3, 0],\n",
|
||
|
" [0, 0, 0, 0, 5, 0, 0, 0],\n",
|
||
|
" [5, 0, 4, 0, 0, 0, 0, 2]], dtype=int64)"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Recommendations:\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>0</th>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <th>3</th>\n",
|
||
|
" <th>4</th>\n",
|
||
|
" <th>5</th>\n",
|
||
|
" <th>6</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>0</td>\n",
|
||
|
" <td>30</td>\n",
|
||
|
" <td>5.0</td>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" <td>60</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <td>10</td>\n",
|
||
|
" <td>40</td>\n",
|
||
|
" <td>3.0</td>\n",
|
||
|
" <td>60</td>\n",
|
||
|
" <td>2.0</td>\n",
|
||
|
" <td>70</td>\n",
|
||
|
" <td>2.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>40</td>\n",
|
||
|
" <td>5.0</td>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" <td>70</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" 0 1 2 3 4 5 6\n",
|
||
|
"0 0 30 5.0 20 4.0 60 4.0\n",
|
||
|
"1 10 40 3.0 60 2.0 70 2.0\n",
|
||
|
"2 20 40 5.0 20 4.0 70 4.0"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Estimations:\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>user</th>\n",
|
||
|
" <th>item</th>\n",
|
||
|
" <th>est_score</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>0</td>\n",
|
||
|
" <td>60</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1</th>\n",
|
||
|
" <td>10</td>\n",
|
||
|
" <td>40</td>\n",
|
||
|
" <td>3.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2</th>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>0</td>\n",
|
||
|
" <td>3.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3</th>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4</th>\n",
|
||
|
" <td>20</td>\n",
|
||
|
" <td>70</td>\n",
|
||
|
" <td>4.0</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" user item est_score\n",
|
||
|
"0 0 60 4.0\n",
|
||
|
"1 10 40 3.0\n",
|
||
|
"2 20 0 3.0\n",
|
||
|
"3 20 20 4.0\n",
|
||
|
"4 20 70 4.0"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as ev\n",
|
||
|
"import imp\n",
|
||
|
"import helpers\n",
|
||
|
"imp.reload(ev)\n",
|
||
|
"\n",
|
||
|
"dir_path=\"Recommendations generated/toy-example/\"\n",
|
||
|
"super_reactions=[4,5]\n",
|
||
|
"test=pd.read_csv('./Datasets/toy-example/test.csv', sep='\\t', header=None)\n",
|
||
|
"\n",
|
||
|
"display(ev.evaluate_all(test, dir_path, super_reactions, topK=3))\n",
|
||
|
"#also you can just type ev.evaluate_all() - I put above values as default\n",
|
||
|
"\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",
|
||
|
"reco=pd.read_csv('Recommendations generated/toy-example/Self_BaselineUI_reco.csv', header=None)\n",
|
||
|
"estimations=pd.read_csv('Recommendations generated/toy-example/Self_BaselineUI_estimations.csv', names=['user', 'item', 'est_score'])\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",
|
||
|
"print('Training data:')\n",
|
||
|
"display(toy_train_ui.todense())\n",
|
||
|
"\n",
|
||
|
"print('Test data:')\n",
|
||
|
"display(toy_test_ui.todense())\n",
|
||
|
"\n",
|
||
|
"print('Recommendations:')\n",
|
||
|
"display(reco)\n",
|
||
|
"\n",
|
||
|
"print('Estimations:')\n",
|
||
|
"display(estimations)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Sample recommendations"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Here is what user rated high:\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>user</th>\n",
|
||
|
" <th>rating</th>\n",
|
||
|
" <th>title</th>\n",
|
||
|
" <th>genres</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>332</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Toy Story (1995)</td>\n",
|
||
|
" <td>Animation, Children's, Comedy</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>19024</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Mars Attacks! (1996)</td>\n",
|
||
|
" <td>Action, Comedy, Sci-Fi, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>55124</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Long Kiss Goodnight, The (1996)</td>\n",
|
||
|
" <td>Action, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>34978</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>My Best Friend's Wedding (1997)</td>\n",
|
||
|
" <td>Comedy, Romance</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>17149</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Leaving Las Vegas (1995)</td>\n",
|
||
|
" <td>Drama, Romance</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>60860</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Juror, The (1996)</td>\n",
|
||
|
" <td>Drama, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>24486</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>People vs. Larry Flynt, The (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>33831</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Independence Day (ID4) (1996)</td>\n",
|
||
|
" <td>Action, Sci-Fi, War</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>38565</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Spitfire Grill, The (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>44201</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Father of the Bride Part II (1995)</td>\n",
|
||
|
" <td>Comedy</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>41492</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Donnie Brasco (1997)</td>\n",
|
||
|
" <td>Crime, Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>66393</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Postino, Il (1994)</td>\n",
|
||
|
" <td>Drama, Romance</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>66231</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Stealing Beauty (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>64564</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Once Upon a Time... When We Were Colored (1995)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>51125</th>\n",
|
||
|
" <td>614</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Dragonheart (1996)</td>\n",
|
||
|
" <td>Action, Adventure, Fantasy</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" user rating title \\\n",
|
||
|
"332 614 5 Toy Story (1995) \n",
|
||
|
"19024 614 5 Mars Attacks! (1996) \n",
|
||
|
"55124 614 5 Long Kiss Goodnight, The (1996) \n",
|
||
|
"34978 614 5 My Best Friend's Wedding (1997) \n",
|
||
|
"17149 614 4 Leaving Las Vegas (1995) \n",
|
||
|
"60860 614 4 Juror, The (1996) \n",
|
||
|
"24486 614 4 People vs. Larry Flynt, The (1996) \n",
|
||
|
"33831 614 4 Independence Day (ID4) (1996) \n",
|
||
|
"38565 614 4 Spitfire Grill, The (1996) \n",
|
||
|
"44201 614 4 Father of the Bride Part II (1995) \n",
|
||
|
"41492 614 3 Donnie Brasco (1997) \n",
|
||
|
"66393 614 3 Postino, Il (1994) \n",
|
||
|
"66231 614 3 Stealing Beauty (1996) \n",
|
||
|
"64564 614 3 Once Upon a Time... When We Were Colored (1995) \n",
|
||
|
"51125 614 3 Dragonheart (1996) \n",
|
||
|
"\n",
|
||
|
" genres \n",
|
||
|
"332 Animation, Children's, Comedy \n",
|
||
|
"19024 Action, Comedy, Sci-Fi, War \n",
|
||
|
"55124 Action, Thriller \n",
|
||
|
"34978 Comedy, Romance \n",
|
||
|
"17149 Drama, Romance \n",
|
||
|
"60860 Drama, Thriller \n",
|
||
|
"24486 Drama \n",
|
||
|
"33831 Action, Sci-Fi, War \n",
|
||
|
"38565 Drama \n",
|
||
|
"44201 Comedy \n",
|
||
|
"41492 Crime, Drama \n",
|
||
|
"66393 Drama, Romance \n",
|
||
|
"66231 Drama \n",
|
||
|
"64564 Drama \n",
|
||
|
"51125 Action, Adventure, Fantasy "
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Here is what we recommend:\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>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>612</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>1</td>\n",
|
||
|
" <td>Great Day in Harlem, A (1994)</td>\n",
|
||
|
" <td>Documentary</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>1554</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>2</td>\n",
|
||
|
" <td>Tough and Deadly (1995)</td>\n",
|
||
|
" <td>Action, Drama, Thriller</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>2496</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>Aiqing wansui (1994)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>3438</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>4</td>\n",
|
||
|
" <td>Delta of Venus (1994)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>4380</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>5</td>\n",
|
||
|
" <td>Someone Else's America (1995)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>5322</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>6</td>\n",
|
||
|
" <td>Saint of Fort Washington, The (1993)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>6264</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>7</td>\n",
|
||
|
" <td>Celestial Clockwork (1994)</td>\n",
|
||
|
" <td>Comedy</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>7207</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>8</td>\n",
|
||
|
" <td>Some Mother's Son (1996)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>9101</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>9</td>\n",
|
||
|
" <td>Maya Lin: A Strong Clear Vision (1994)</td>\n",
|
||
|
" <td>Documentary</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>8147</th>\n",
|
||
|
" <td>614.0</td>\n",
|
||
|
" <td>10</td>\n",
|
||
|
" <td>Prefontaine (1997)</td>\n",
|
||
|
" <td>Drama</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" user rec_nb title \\\n",
|
||
|
"612 614.0 1 Great Day in Harlem, A (1994) \n",
|
||
|
"1554 614.0 2 Tough and Deadly (1995) \n",
|
||
|
"2496 614.0 3 Aiqing wansui (1994) \n",
|
||
|
"3438 614.0 4 Delta of Venus (1994) \n",
|
||
|
"4380 614.0 5 Someone Else's America (1995) \n",
|
||
|
"5322 614.0 6 Saint of Fort Washington, The (1993) \n",
|
||
|
"6264 614.0 7 Celestial Clockwork (1994) \n",
|
||
|
"7207 614.0 8 Some Mother's Son (1996) \n",
|
||
|
"9101 614.0 9 Maya Lin: A Strong Clear Vision (1994) \n",
|
||
|
"8147 614.0 10 Prefontaine (1997) \n",
|
||
|
"\n",
|
||
|
" genres \n",
|
||
|
"612 Documentary \n",
|
||
|
"1554 Action, Drama, Thriller \n",
|
||
|
"2496 Drama \n",
|
||
|
"3438 Drama \n",
|
||
|
"4380 Drama \n",
|
||
|
"5322 Drama \n",
|
||
|
"6264 Comedy \n",
|
||
|
"7207 Drama \n",
|
||
|
"9101 Documentary \n",
|
||
|
"8147 Drama "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"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",
|
||
|
"\n",
|
||
|
"print('Here is what user rated high:')\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_BaselineUI_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",
|
||
|
"\n",
|
||
|
"print('Here is what we recommend:')\n",
|
||
|
"recommended_content[recommended_content['user']==user][['user', 'rec_nb', 'title', 'genres']].sort_values(by='rec_nb')"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# project task 3: implement some other evaluation measure"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# it may be your idea, modification of what we have already implemented \n",
|
||
|
"# (for example Hit2 rate which would count as a success users whoreceived at least 2 relevant recommendations) \n",
|
||
|
"# or something well-known\n",
|
||
|
"# expected output: modification of evaluation_measures.py such that evaluate_all will also display your measure"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 57,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 11351.38it/s]\n",
|
||
|
"943it [00:00, 11776.77it/s]\n",
|
||
|
"943it [00:00, 11631.38it/s]\n",
|
||
|
"943it [00:00, 11925.95it/s]\n",
|
||
|
"943it [00:00, 11489.67it/s]\n",
|
||
|
"943it [00:00, 12396.58it/s]\n",
|
||
|
"943it [00:00, 12561.94it/s]\n",
|
||
|
"943it [00:00, 12078.99it/s]\n",
|
||
|
"943it [00:00, 10955.16it/s]\n",
|
||
|
"943it [00:00, 10947.46it/s]\n",
|
||
|
"943it [00:00, 11489.44it/s]\n",
|
||
|
"943it [00:00, 11925.88it/s]\n",
|
||
|
"943it [00:00, 10585.87it/s]\n",
|
||
|
"943it [00:00, 11925.80it/s]\n",
|
||
|
"943it [00:00, 11631.25it/s]\n",
|
||
|
"943it [00:00, 11631.52it/s]\n",
|
||
|
"943it [00:00, 12396.70it/s]\n",
|
||
|
"943it [00:00, 10829.27it/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.645871</td>\n",
|
||
|
" <td>3.480308</td>\n",
|
||
|
" <td>0.135949</td>\n",
|
||
|
" <td>0.078868</td>\n",
|
||
|
" <td>0.082011</td>\n",
|
||
|
" <td>0.099188</td>\n",
|
||
|
" <td>0.106974</td>\n",
|
||
|
" <td>0.103767</td>\n",
|
||
|
" <td>0.159486</td>\n",
|
||
|
" <td>0.079783</td>\n",
|
||
|
" <td>0.328576</td>\n",
|
||
|
" <td>0.536311</td>\n",
|
||
|
" <td>0.632025</td>\n",
|
||
|
" <td>0.077145</td>\n",
|
||
|
" <td>0.201674</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.281385</td>\n",
|
||
|
" <td>5.140721</td>\n",
|
||
|
" <td>0.909056</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_SVD</td>\n",
|
||
|
" <td>0.950835</td>\n",
|
||
|
" <td>0.748676</td>\n",
|
||
|
" <td>0.097879</td>\n",
|
||
|
" <td>0.048335</td>\n",
|
||
|
" <td>0.053780</td>\n",
|
||
|
" <td>0.068420</td>\n",
|
||
|
" <td>0.086159</td>\n",
|
||
|
" <td>0.080289</td>\n",
|
||
|
" <td>0.113553</td>\n",
|
||
|
" <td>0.054094</td>\n",
|
||
|
" <td>0.249037</td>\n",
|
||
|
" <td>0.520893</td>\n",
|
||
|
" <td>0.498409</td>\n",
|
||
|
" <td>0.048439</td>\n",
|
||
|
" <td>0.159941</td>\n",
|
||
|
" <td>0.997985</td>\n",
|
||
|
" <td>0.204906</td>\n",
|
||
|
" <td>4.395721</td>\n",
|
||
|
" <td>0.954872</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_SVD</td>\n",
|
||
|
" <td>0.913966</td>\n",
|
||
|
" <td>0.717846</td>\n",
|
||
|
" <td>0.105514</td>\n",
|
||
|
" <td>0.044566</td>\n",
|
||
|
" <td>0.054152</td>\n",
|
||
|
" <td>0.071575</td>\n",
|
||
|
" <td>0.095386</td>\n",
|
||
|
" <td>0.075767</td>\n",
|
||
|
" <td>0.108802</td>\n",
|
||
|
" <td>0.051730</td>\n",
|
||
|
" <td>0.200919</td>\n",
|
||
|
" <td>0.519021</td>\n",
|
||
|
" <td>0.482503</td>\n",
|
||
|
" <td>0.046741</td>\n",
|
||
|
" <td>0.154723</td>\n",
|
||
|
" <td>0.861612</td>\n",
|
||
|
" <td>0.142136</td>\n",
|
||
|
" <td>3.845461</td>\n",
|
||
|
" <td>0.973440</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>Ready_SVDBiased</td>\n",
|
||
|
" <td>0.943277</td>\n",
|
||
|
" <td>0.743628</td>\n",
|
||
|
" <td>0.080912</td>\n",
|
||
|
" <td>0.033048</td>\n",
|
||
|
" <td>0.040445</td>\n",
|
||
|
" <td>0.053881</td>\n",
|
||
|
" <td>0.070815</td>\n",
|
||
|
" <td>0.049631</td>\n",
|
||
|
" <td>0.090496</td>\n",
|
||
|
" <td>0.041928</td>\n",
|
||
|
" <td>0.200192</td>\n",
|
||
|
" <td>0.513176</td>\n",
|
||
|
" <td>0.411453</td>\n",
|
||
|
" <td>0.034776</td>\n",
|
||
|
" <td>0.135063</td>\n",
|
||
|
" <td>0.998727</td>\n",
|
||
|
" <td>0.168110</td>\n",
|
||
|
" <td>4.165618</td>\n",
|
||
|
" <td>0.964211</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>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.514265</td>\n",
|
||
|
" <td>1.215956</td>\n",
|
||
|
" <td>0.048780</td>\n",
|
||
|
" <td>0.021007</td>\n",
|
||
|
" <td>0.024667</td>\n",
|
||
|
" <td>0.032495</td>\n",
|
||
|
" <td>0.031867</td>\n",
|
||
|
" <td>0.023414</td>\n",
|
||
|
" <td>0.052904</td>\n",
|
||
|
" <td>0.020511</td>\n",
|
||
|
" <td>0.126790</td>\n",
|
||
|
" <td>0.507024</td>\n",
|
||
|
" <td>0.322375</td>\n",
|
||
|
" <td>0.021635</td>\n",
|
||
|
" <td>0.102789</td>\n",
|
||
|
" <td>0.988017</td>\n",
|
||
|
" <td>0.183983</td>\n",
|
||
|
" <td>5.100443</td>\n",
|
||
|
" <td>0.906900</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.645871 3.480308 0.135949 0.078868 0.082011 \n",
|
||
|
"0 Ready_SVD 0.950835 0.748676 0.097879 0.048335 0.053780 \n",
|
||
|
"0 Self_SVD 0.913966 0.717846 0.105514 0.044566 0.054152 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
|
||
|
"0 Ready_SVDBiased 0.943277 0.743628 0.080912 0.033048 0.040445 \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 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
|
||
|
"0 Ready_Random 1.514265 1.215956 0.048780 0.021007 0.024667 \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.099188 0.106974 0.103767 0.159486 0.079783 0.328576 \n",
|
||
|
"0 0.068420 0.086159 0.080289 0.113553 0.054094 0.249037 \n",
|
||
|
"0 0.071575 0.095386 0.075767 0.108802 0.051730 0.200919 \n",
|
||
|
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
|
||
|
"0 0.053881 0.070815 0.049631 0.090496 0.041928 0.200192 \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.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
|
||
|
"0 0.032495 0.031867 0.023414 0.052904 0.020511 0.126790 \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.536311 0.632025 0.077145 0.201674 0.999894 0.281385 \n",
|
||
|
"0 0.520893 0.498409 0.048439 0.159941 0.997985 0.204906 \n",
|
||
|
"0 0.519021 0.482503 0.046741 0.154723 0.861612 0.142136 \n",
|
||
|
"0 0.515501 0.437964 0.039549 0.141900 1.000000 0.033911 \n",
|
||
|
"0 0.513176 0.411453 0.034776 0.135063 0.998727 0.168110 \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.509546 0.384942 0.027213 0.118383 1.000000 0.025974 \n",
|
||
|
"0 0.507024 0.322375 0.021635 0.102789 0.988017 0.183983 \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.140721 0.909056 \n",
|
||
|
"0 4.395721 0.954872 \n",
|
||
|
"0 3.845461 0.973440 \n",
|
||
|
"0 2.836513 0.991139 \n",
|
||
|
"0 4.165618 0.964211 \n",
|
||
|
"0 3.611806 0.978659 \n",
|
||
|
"0 2.761238 0.991660 \n",
|
||
|
"0 2.711772 0.992003 \n",
|
||
|
"0 5.100443 0.906900 \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": 57,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"dir_path=\"Recommendations generated/ml-100k/\"\n",
|
||
|
"super_reactions=[4,5]\n",
|
||
|
"test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None)\n",
|
||
|
"\n",
|
||
|
"ev.evaluate_all(test, dir_path, super_reactions)"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"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
|
||
|
}
|