{
"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, 7381.00it/s]\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" RMSE | \n",
" MAE | \n",
" precision | \n",
" recall | \n",
" F_1 | \n",
" F_05 | \n",
" precision_super | \n",
" recall_super | \n",
" NDCG | \n",
" mAP | \n",
" MRR | \n",
" LAUC | \n",
" HR | \n",
" HR2 | \n",
" Reco in test | \n",
" Test coverage | \n",
" Shannon | \n",
" Gini | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1.018363 | \n",
" 0.808793 | \n",
" 0.000318 | \n",
" 0.000108 | \n",
" 0.00014 | \n",
" 0.000189 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.000214 | \n",
" 0.000037 | \n",
" 0.000368 | \n",
" 0.496391 | \n",
" 0.003181 | \n",
" 0.0 | \n",
" 0.392153 | \n",
" 0.11544 | \n",
" 4.174741 | \n",
" 0.965327 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"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 HR2 Reco in test Test coverage Shannon Gini \n",
"0 0.003181 0.0 0.392153 0.11544 4.174741 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, 6244.78it/s]\n",
"943it [00:00, 6960.47it/s]\n",
"943it [00:00, 6090.17it/s]\n",
"943it [00:00, 6876.64it/s]\n",
"943it [00:00, 7185.17it/s]\n",
"943it [00:00, 6481.90it/s]\n",
"943it [00:00, 4245.42it/s]\n",
"943it [00:00, 6388.64it/s]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Model | \n",
" RMSE | \n",
" MAE | \n",
" precision | \n",
" recall | \n",
" F_1 | \n",
" F_05 | \n",
" precision_super | \n",
" recall_super | \n",
" NDCG | \n",
" mAP | \n",
" MRR | \n",
" LAUC | \n",
" HR | \n",
" HR2 | \n",
" Reco in test | \n",
" Test coverage | \n",
" Shannon | \n",
" Gini | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Self_TopPop | \n",
" 2.508258 | \n",
" 2.217909 | \n",
" 0.188865 | \n",
" 0.116919 | \n",
" 0.118732 | \n",
" 0.141584 | \n",
" 0.130472 | \n",
" 0.137473 | \n",
" 0.214651 | \n",
" 0.111707 | \n",
" 0.400939 | \n",
" 0.555546 | \n",
" 0.765642 | \n",
" 0.492047 | \n",
" 1.000000 | \n",
" 0.038961 | \n",
" 3.159079 | \n",
" 0.987317 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_Baseline | \n",
" 0.949459 | \n",
" 0.752487 | \n",
" 0.091410 | \n",
" 0.037652 | \n",
" 0.046030 | \n",
" 0.061286 | \n",
" 0.079614 | \n",
" 0.056463 | \n",
" 0.095957 | \n",
" 0.043178 | \n",
" 0.198193 | \n",
" 0.515501 | \n",
" 0.437964 | \n",
" 0.239661 | \n",
" 1.000000 | \n",
" 0.033911 | \n",
" 2.836513 | \n",
" 0.991139 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_GlobalAvg | \n",
" 1.125760 | \n",
" 0.943534 | \n",
" 0.061188 | \n",
" 0.025968 | \n",
" 0.031383 | \n",
" 0.041343 | \n",
" 0.040558 | \n",
" 0.032107 | \n",
" 0.067695 | \n",
" 0.027470 | \n",
" 0.171187 | \n",
" 0.509546 | \n",
" 0.384942 | \n",
" 0.142100 | \n",
" 1.000000 | \n",
" 0.025974 | \n",
" 2.711772 | \n",
" 0.992003 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_Random | \n",
" 1.517593 | \n",
" 1.220181 | \n",
" 0.046023 | \n",
" 0.019038 | \n",
" 0.023118 | \n",
" 0.030734 | \n",
" 0.029292 | \n",
" 0.021639 | \n",
" 0.050818 | \n",
" 0.019958 | \n",
" 0.126646 | \n",
" 0.506031 | \n",
" 0.305408 | \n",
" 0.111347 | \n",
" 0.988547 | \n",
" 0.174603 | \n",
" 5.082383 | \n",
" 0.908434 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_TopRated | \n",
" 2.508258 | \n",
" 2.217909 | \n",
" 0.000954 | \n",
" 0.000188 | \n",
" 0.000298 | \n",
" 0.000481 | \n",
" 0.000644 | \n",
" 0.000223 | \n",
" 0.001043 | \n",
" 0.000335 | \n",
" 0.003348 | \n",
" 0.496433 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.699046 | \n",
" 0.005051 | \n",
" 1.945910 | \n",
" 0.995669 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_BaselineIU | \n",
" 0.958136 | \n",
" 0.754051 | \n",
" 0.000954 | \n",
" 0.000188 | \n",
" 0.000298 | \n",
" 0.000481 | \n",
" 0.000644 | \n",
" 0.000223 | \n",
" 0.001043 | \n",
" 0.000335 | \n",
" 0.003348 | \n",
" 0.496433 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.699046 | \n",
" 0.005051 | \n",
" 1.945910 | \n",
" 0.995669 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_BaselineUI | \n",
" 0.967585 | \n",
" 0.762740 | \n",
" 0.000954 | \n",
" 0.000170 | \n",
" 0.000278 | \n",
" 0.000463 | \n",
" 0.000644 | \n",
" 0.000189 | \n",
" 0.000752 | \n",
" 0.000168 | \n",
" 0.001677 | \n",
" 0.496424 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.600530 | \n",
" 0.005051 | \n",
" 1.803126 | \n",
" 0.996380 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_IKNN | \n",
" 1.018363 | \n",
" 0.808793 | \n",
" 0.000318 | \n",
" 0.000108 | \n",
" 0.000140 | \n",
" 0.000189 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.000214 | \n",
" 0.000037 | \n",
" 0.000368 | \n",
" 0.496391 | \n",
" 0.003181 | \n",
" 0.000000 | \n",
" 0.392153 | \n",
" 0.115440 | \n",
" 4.174741 | \n",
" 0.965327 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Model RMSE MAE precision recall F_1 \\\n",
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
"0 Ready_Random 1.517593 1.220181 0.046023 0.019038 0.023118 \n",
"0 Self_TopRated 2.508258 2.217909 0.000954 0.000188 0.000298 \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.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
"0 0.030734 0.029292 0.021639 0.050818 0.019958 0.126646 \n",
"0 0.000481 0.000644 0.000223 0.001043 0.000335 0.003348 \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 HR2 Reco in test Test coverage Shannon \\\n",
"0 0.555546 0.765642 0.492047 1.000000 0.038961 3.159079 \n",
"0 0.515501 0.437964 0.239661 1.000000 0.033911 2.836513 \n",
"0 0.509546 0.384942 0.142100 1.000000 0.025974 2.711772 \n",
"0 0.506031 0.305408 0.111347 0.988547 0.174603 5.082383 \n",
"0 0.496433 0.009544 0.000000 0.699046 0.005051 1.945910 \n",
"0 0.496433 0.009544 0.000000 0.699046 0.005051 1.945910 \n",
"0 0.496424 0.009544 0.000000 0.600530 0.005051 1.803126 \n",
"0 0.496391 0.003181 0.000000 0.392153 0.115440 4.174741 \n",
"\n",
" Gini \n",
"0 0.987317 \n",
"0 0.991139 \n",
"0 0.992003 \n",
"0 0.908434 \n",
"0 0.995669 \n",
"0 0.995669 \n",
"0 0.996380 \n",
"0 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": null,
"metadata": {},
"outputs": [],
"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": 10,
"metadata": {},
"outputs": [],
"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'"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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.KNNWithMeans()\n",
"\n",
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_I-KNNWithMeans_reco.csv',\n",
" estimations_path='Recommendations generated/ml-100k/Ready_I-KNNWithMeans_estimations.csv')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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.KNNWithZScore()\n",
"\n",
"helpers.ready_made(algo, reco_path='Recommendations generated/ml-100k/Ready_I-KNNWithZScore_reco.csv',\n",
" estimations_path='Recommendations generated/ml-100k/Ready_I-KNNWithZScore_estimations.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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",
"k = 38\n",
"\n",
"for i in range(10):\n",
" path1 = \"Recommendations generated/ml-100k/Self_I-KNNBaseline%d_reco.csv\" % (k)\n",
" path2 = \"Recommendations generated/ml-100k/Self_I-KNNBaseline%d_estimations.csv\" % (k)\n",
" algo = sp.KNNBaseline(k=k)\n",
" helpers.ready_made(algo, reco_path=path1,\n",
" estimations_path=path2)\n",
" k+=1\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"943it [00:00, 6566.70it/s]\n",
"943it [00:00, 6053.18it/s]\n",
"943it [00:00, 6753.76it/s]\n",
"943it [00:00, 6451.06it/s]\n",
"943it [00:00, 3763.62it/s]\n",
"943it [00:00, 4634.14it/s]\n",
"943it [00:00, 6520.99it/s]\n",
"943it [00:00, 6061.07it/s]\n",
"943it [00:00, 5946.69it/s]\n",
"943it [00:00, 6520.59it/s]\n",
"943it [00:00, 4047.05it/s]\n",
"943it [00:00, 6061.15it/s]\n",
"943it [00:00, 6430.82it/s]\n",
"943it [00:00, 6519.56it/s]\n",
"943it [00:00, 6127.91it/s]\n",
"943it [00:00, 6220.07it/s]\n",
"943it [00:00, 6731.95it/s]\n",
"943it [00:00, 5617.04it/s]\n",
"943it [00:00, 5984.37it/s]\n",
"943it [00:00, 3923.26it/s]\n",
"943it [00:00, 4799.65it/s]\n",
"943it [00:00, 6678.60it/s]\n",
"943it [00:00, 5984.12it/s]\n",
"943it [00:00, 7217.79it/s]\n",
"943it [00:00, 4799.62it/s]\n",
"943it [00:00, 4799.67it/s]\n",
"943it [00:00, 6566.16it/s]\n"
]
}
],
"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",
"result = ev.evaluate_all(test, dir_path, super_reactions)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Model | \n",
" RMSE | \n",
" MAE | \n",
" precision | \n",
" recall | \n",
" F_1 | \n",
" F_05 | \n",
" precision_super | \n",
" recall_super | \n",
" NDCG | \n",
" mAP | \n",
" MRR | \n",
" LAUC | \n",
" HR | \n",
" HR2 | \n",
" Reco in test | \n",
" Test coverage | \n",
" Shannon | \n",
" Gini | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Self_SVDBaseline | \n",
" 0.913253 | \n",
" 0.719475 | \n",
" 0.105090 | \n",
" 0.043952 | \n",
" 0.053454 | \n",
" 0.070803 | \n",
" 0.095279 | \n",
" 0.073469 | \n",
" 0.118152 | \n",
" 0.058739 | \n",
" 0.244096 | \n",
" 0.518714 | \n",
" 0.471898 | \n",
" 0.279958 | \n",
" 0.999682 | \n",
" 0.111111 | \n",
" 3.572421 | \n",
" 0.980655 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_SVD | \n",
" 0.914521 | \n",
" 0.717680 | \n",
" 0.102757 | \n",
" 0.043043 | \n",
" 0.052432 | \n",
" 0.069515 | \n",
" 0.094528 | \n",
" 0.075122 | \n",
" 0.106751 | \n",
" 0.051431 | \n",
" 0.198701 | \n",
" 0.518248 | \n",
" 0.462354 | \n",
" 0.255567 | \n",
" 0.854931 | \n",
" 0.147186 | \n",
" 3.888926 | \n",
" 0.972044 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline42 | \n",
" 0.935028 | \n",
" 0.737210 | \n",
" 0.002969 | \n",
" 0.000980 | \n",
" 0.001374 | \n",
" 0.001929 | \n",
" 0.002682 | \n",
" 0.001217 | \n",
" 0.004069 | \n",
" 0.001677 | \n",
" 0.013349 | \n",
" 0.496838 | \n",
" 0.023330 | \n",
" 0.006363 | \n",
" 0.481972 | \n",
" 0.059163 | \n",
" 2.227849 | \n",
" 0.994531 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_KNNSurprisetask | \n",
" 0.935028 | \n",
" 0.737210 | \n",
" 0.002969 | \n",
" 0.000980 | \n",
" 0.001374 | \n",
" 0.001929 | \n",
" 0.002682 | \n",
" 0.001217 | \n",
" 0.004069 | \n",
" 0.001677 | \n",
" 0.013349 | \n",
" 0.496838 | \n",
" 0.023330 | \n",
" 0.006363 | \n",
" 0.481972 | \n",
" 0.059163 | \n",
" 2.227849 | \n",
" 0.994531 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline41 | \n",
" 0.935205 | \n",
" 0.737439 | \n",
" 0.002651 | \n",
" 0.000774 | \n",
" 0.001138 | \n",
" 0.001658 | \n",
" 0.002361 | \n",
" 0.000959 | \n",
" 0.003537 | \n",
" 0.001435 | \n",
" 0.011494 | \n",
" 0.496734 | \n",
" 0.021209 | \n",
" 0.005302 | \n",
" 0.482503 | \n",
" 0.057720 | \n",
" 2.228123 | \n",
" 0.994555 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline43 | \n",
" 0.935241 | \n",
" 0.737463 | \n",
" 0.002863 | \n",
" 0.000952 | \n",
" 0.001331 | \n",
" 0.001862 | \n",
" 0.002575 | \n",
" 0.001186 | \n",
" 0.004014 | \n",
" 0.001663 | \n",
" 0.013467 | \n",
" 0.496824 | \n",
" 0.023330 | \n",
" 0.005302 | \n",
" 0.482609 | \n",
" 0.055556 | \n",
" 2.225996 | \n",
" 0.994623 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline46 | \n",
" 0.935244 | \n",
" 0.737512 | \n",
" 0.003287 | \n",
" 0.001096 | \n",
" 0.001534 | \n",
" 0.002148 | \n",
" 0.003004 | \n",
" 0.001376 | \n",
" 0.004398 | \n",
" 0.001856 | \n",
" 0.013719 | \n",
" 0.496898 | \n",
" 0.024390 | \n",
" 0.007423 | \n",
" 0.482397 | \n",
" 0.057720 | \n",
" 2.225807 | \n",
" 0.994607 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline44 | \n",
" 0.935259 | \n",
" 0.737530 | \n",
" 0.002969 | \n",
" 0.000902 | \n",
" 0.001305 | \n",
" 0.001880 | \n",
" 0.002682 | \n",
" 0.001129 | \n",
" 0.004215 | \n",
" 0.001823 | \n",
" 0.013977 | \n",
" 0.496799 | \n",
" 0.023330 | \n",
" 0.005302 | \n",
" 0.482397 | \n",
" 0.057720 | \n",
" 2.225495 | \n",
" 0.994598 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline45 | \n",
" 0.935268 | \n",
" 0.737543 | \n",
" 0.003075 | \n",
" 0.001044 | \n",
" 0.001450 | \n",
" 0.002016 | \n",
" 0.002790 | \n",
" 0.001317 | \n",
" 0.004287 | \n",
" 0.001812 | \n",
" 0.014189 | \n",
" 0.496871 | \n",
" 0.024390 | \n",
" 0.005302 | \n",
" 0.482609 | \n",
" 0.058442 | \n",
" 2.225340 | \n",
" 0.994599 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline47 | \n",
" 0.935295 | \n",
" 0.737563 | \n",
" 0.003075 | \n",
" 0.001044 | \n",
" 0.001450 | \n",
" 0.002016 | \n",
" 0.002790 | \n",
" 0.001317 | \n",
" 0.004199 | \n",
" 0.001735 | \n",
" 0.013888 | \n",
" 0.496871 | \n",
" 0.024390 | \n",
" 0.005302 | \n",
" 0.482397 | \n",
" 0.055556 | \n",
" 2.221942 | \n",
" 0.994676 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline40 | \n",
" 0.935327 | \n",
" 0.737424 | \n",
" 0.002545 | \n",
" 0.000755 | \n",
" 0.001105 | \n",
" 0.001602 | \n",
" 0.002253 | \n",
" 0.000930 | \n",
" 0.003444 | \n",
" 0.001362 | \n",
" 0.011760 | \n",
" 0.496724 | \n",
" 0.021209 | \n",
" 0.004242 | \n",
" 0.482821 | \n",
" 0.059885 | \n",
" 2.232578 | \n",
" 0.994487 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_I-KNNBaseline | \n",
" 0.935327 | \n",
" 0.737424 | \n",
" 0.002545 | \n",
" 0.000755 | \n",
" 0.001105 | \n",
" 0.001602 | \n",
" 0.002253 | \n",
" 0.000930 | \n",
" 0.003444 | \n",
" 0.001362 | \n",
" 0.011760 | \n",
" 0.496724 | \n",
" 0.021209 | \n",
" 0.004242 | \n",
" 0.482821 | \n",
" 0.059885 | \n",
" 2.232578 | \n",
" 0.994487 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline39 | \n",
" 0.935520 | \n",
" 0.737631 | \n",
" 0.002757 | \n",
" 0.000856 | \n",
" 0.001230 | \n",
" 0.001758 | \n",
" 0.002468 | \n",
" 0.001048 | \n",
" 0.003899 | \n",
" 0.001620 | \n",
" 0.013296 | \n",
" 0.496775 | \n",
" 0.022269 | \n",
" 0.005302 | \n",
" 0.483351 | \n",
" 0.059885 | \n",
" 2.235102 | \n",
" 0.994479 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_I-KNNBaseline38 | \n",
" 0.935685 | \n",
" 0.737828 | \n",
" 0.002651 | \n",
" 0.000837 | \n",
" 0.001197 | \n",
" 0.001702 | \n",
" 0.002361 | \n",
" 0.001020 | \n",
" 0.003635 | \n",
" 0.001443 | \n",
" 0.012589 | \n",
" 0.496765 | \n",
" 0.022269 | \n",
" 0.004242 | \n",
" 0.483245 | \n",
" 0.059163 | \n",
" 2.235851 | \n",
" 0.994507 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_Baseline | \n",
" 0.949459 | \n",
" 0.752487 | \n",
" 0.091410 | \n",
" 0.037652 | \n",
" 0.046030 | \n",
" 0.061286 | \n",
" 0.079614 | \n",
" 0.056463 | \n",
" 0.095957 | \n",
" 0.043178 | \n",
" 0.198193 | \n",
" 0.515501 | \n",
" 0.437964 | \n",
" 0.239661 | \n",
" 1.000000 | \n",
" 0.033911 | \n",
" 2.836513 | \n",
" 0.991139 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_I-KNNWithMeans | \n",
" 0.955921 | \n",
" 0.754037 | \n",
" 0.004984 | \n",
" 0.003225 | \n",
" 0.003406 | \n",
" 0.003956 | \n",
" 0.004506 | \n",
" 0.003861 | \n",
" 0.006815 | \n",
" 0.002906 | \n",
" 0.020332 | \n",
" 0.497969 | \n",
" 0.039236 | \n",
" 0.007423 | \n",
" 0.587699 | \n",
" 0.071429 | \n",
" 2.699278 | \n",
" 0.991353 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_I-KNNWithZScore | \n",
" 0.957701 | \n",
" 0.752387 | \n",
" 0.003712 | \n",
" 0.001994 | \n",
" 0.002380 | \n",
" 0.002919 | \n",
" 0.003433 | \n",
" 0.002401 | \n",
" 0.005137 | \n",
" 0.002158 | \n",
" 0.016458 | \n",
" 0.497349 | \n",
" 0.027572 | \n",
" 0.007423 | \n",
" 0.389926 | \n",
" 0.067821 | \n",
" 2.475747 | \n",
" 0.992793 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_BaselineIU | \n",
" 0.958136 | \n",
" 0.754051 | \n",
" 0.000954 | \n",
" 0.000188 | \n",
" 0.000298 | \n",
" 0.000481 | \n",
" 0.000644 | \n",
" 0.000223 | \n",
" 0.001043 | \n",
" 0.000335 | \n",
" 0.003348 | \n",
" 0.496433 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.699046 | \n",
" 0.005051 | \n",
" 1.945910 | \n",
" 0.995669 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_BaselineUI | \n",
" 0.967585 | \n",
" 0.762740 | \n",
" 0.000954 | \n",
" 0.000170 | \n",
" 0.000278 | \n",
" 0.000463 | \n",
" 0.000644 | \n",
" 0.000189 | \n",
" 0.000752 | \n",
" 0.000168 | \n",
" 0.001677 | \n",
" 0.496424 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.600530 | \n",
" 0.005051 | \n",
" 1.803126 | \n",
" 0.996380 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_IKNN | \n",
" 1.018363 | \n",
" 0.808793 | \n",
" 0.000318 | \n",
" 0.000108 | \n",
" 0.000140 | \n",
" 0.000189 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.000214 | \n",
" 0.000037 | \n",
" 0.000368 | \n",
" 0.496391 | \n",
" 0.003181 | \n",
" 0.000000 | \n",
" 0.392153 | \n",
" 0.115440 | \n",
" 4.174741 | \n",
" 0.965327 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_U-KNN | \n",
" 1.023495 | \n",
" 0.807913 | \n",
" 0.000742 | \n",
" 0.000205 | \n",
" 0.000305 | \n",
" 0.000449 | \n",
" 0.000536 | \n",
" 0.000198 | \n",
" 0.000845 | \n",
" 0.000274 | \n",
" 0.002744 | \n",
" 0.496441 | \n",
" 0.007423 | \n",
" 0.000000 | \n",
" 0.602121 | \n",
" 0.010823 | \n",
" 2.089186 | \n",
" 0.995706 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_I-KNN | \n",
" 1.030386 | \n",
" 0.813067 | \n",
" 0.026087 | \n",
" 0.006908 | \n",
" 0.010593 | \n",
" 0.016046 | \n",
" 0.021137 | \n",
" 0.009522 | \n",
" 0.024214 | \n",
" 0.008958 | \n",
" 0.048068 | \n",
" 0.499885 | \n",
" 0.154825 | \n",
" 0.072110 | \n",
" 0.402333 | \n",
" 0.434343 | \n",
" 5.133650 | \n",
" 0.877999 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_GlobalAvg | \n",
" 1.125760 | \n",
" 0.943534 | \n",
" 0.061188 | \n",
" 0.025968 | \n",
" 0.031383 | \n",
" 0.041343 | \n",
" 0.040558 | \n",
" 0.032107 | \n",
" 0.067695 | \n",
" 0.027470 | \n",
" 0.171187 | \n",
" 0.509546 | \n",
" 0.384942 | \n",
" 0.142100 | \n",
" 1.000000 | \n",
" 0.025974 | \n",
" 2.711772 | \n",
" 0.992003 | \n",
"
\n",
" \n",
" 0 | \n",
" Ready_Random | \n",
" 1.517593 | \n",
" 1.220181 | \n",
" 0.046023 | \n",
" 0.019038 | \n",
" 0.023118 | \n",
" 0.030734 | \n",
" 0.029292 | \n",
" 0.021639 | \n",
" 0.050818 | \n",
" 0.019958 | \n",
" 0.126646 | \n",
" 0.506031 | \n",
" 0.305408 | \n",
" 0.111347 | \n",
" 0.988547 | \n",
" 0.174603 | \n",
" 5.082383 | \n",
" 0.908434 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_TopRated | \n",
" 2.508258 | \n",
" 2.217909 | \n",
" 0.000954 | \n",
" 0.000188 | \n",
" 0.000298 | \n",
" 0.000481 | \n",
" 0.000644 | \n",
" 0.000223 | \n",
" 0.001043 | \n",
" 0.000335 | \n",
" 0.003348 | \n",
" 0.496433 | \n",
" 0.009544 | \n",
" 0.000000 | \n",
" 0.699046 | \n",
" 0.005051 | \n",
" 1.945910 | \n",
" 0.995669 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_TopPop | \n",
" 2.508258 | \n",
" 2.217909 | \n",
" 0.188865 | \n",
" 0.116919 | \n",
" 0.118732 | \n",
" 0.141584 | \n",
" 0.130472 | \n",
" 0.137473 | \n",
" 0.214651 | \n",
" 0.111707 | \n",
" 0.400939 | \n",
" 0.555546 | \n",
" 0.765642 | \n",
" 0.492047 | \n",
" 1.000000 | \n",
" 0.038961 | \n",
" 3.159079 | \n",
" 0.987317 | \n",
"
\n",
" \n",
" 0 | \n",
" Self_P3 | \n",
" 3.702446 | \n",
" 3.527273 | \n",
" 0.282185 | \n",
" 0.192092 | \n",
" 0.186749 | \n",
" 0.216980 | \n",
" 0.204185 | \n",
" 0.240096 | \n",
" 0.339114 | \n",
" 0.204905 | \n",
" 0.572157 | \n",
" 0.593544 | \n",
" 0.875928 | \n",
" 0.685048 | \n",
" 1.000000 | \n",
" 0.077201 | \n",
" 3.875892 | \n",
" 0.974947 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Model RMSE MAE precision recall F_1 \\\n",
"0 Self_SVDBaseline 0.913253 0.719475 0.105090 0.043952 0.053454 \n",
"0 Self_SVD 0.914521 0.717680 0.102757 0.043043 0.052432 \n",
"0 Self_I-KNNBaseline42 0.935028 0.737210 0.002969 0.000980 0.001374 \n",
"0 Self_KNNSurprisetask 0.935028 0.737210 0.002969 0.000980 0.001374 \n",
"0 Self_I-KNNBaseline41 0.935205 0.737439 0.002651 0.000774 0.001138 \n",
"0 Self_I-KNNBaseline43 0.935241 0.737463 0.002863 0.000952 0.001331 \n",
"0 Self_I-KNNBaseline46 0.935244 0.737512 0.003287 0.001096 0.001534 \n",
"0 Self_I-KNNBaseline44 0.935259 0.737530 0.002969 0.000902 0.001305 \n",
"0 Self_I-KNNBaseline45 0.935268 0.737543 0.003075 0.001044 0.001450 \n",
"0 Self_I-KNNBaseline47 0.935295 0.737563 0.003075 0.001044 0.001450 \n",
"0 Self_I-KNNBaseline40 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
"0 Ready_I-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
"0 Self_I-KNNBaseline39 0.935520 0.737631 0.002757 0.000856 0.001230 \n",
"0 Self_I-KNNBaseline38 0.935685 0.737828 0.002651 0.000837 0.001197 \n",
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
"0 Ready_I-KNNWithMeans 0.955921 0.754037 0.004984 0.003225 0.003406 \n",
"0 Ready_I-KNNWithZScore 0.957701 0.752387 0.003712 0.001994 0.002380 \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",
"0 Ready_U-KNN 1.023495 0.807913 0.000742 0.000205 0.000305 \n",
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \n",
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 0.031383 \n",
"0 Ready_Random 1.517593 1.220181 0.046023 0.019038 0.023118 \n",
"0 Self_TopRated 2.508258 2.217909 0.000954 0.000188 0.000298 \n",
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
"0 Self_P3 3.702446 3.527273 0.282185 0.192092 0.186749 \n",
"\n",
" F_05 precision_super recall_super NDCG mAP MRR \\\n",
"0 0.070803 0.095279 0.073469 0.118152 0.058739 0.244096 \n",
"0 0.069515 0.094528 0.075122 0.106751 0.051431 0.198701 \n",
"0 0.001929 0.002682 0.001217 0.004069 0.001677 0.013349 \n",
"0 0.001929 0.002682 0.001217 0.004069 0.001677 0.013349 \n",
"0 0.001658 0.002361 0.000959 0.003537 0.001435 0.011494 \n",
"0 0.001862 0.002575 0.001186 0.004014 0.001663 0.013467 \n",
"0 0.002148 0.003004 0.001376 0.004398 0.001856 0.013719 \n",
"0 0.001880 0.002682 0.001129 0.004215 0.001823 0.013977 \n",
"0 0.002016 0.002790 0.001317 0.004287 0.001812 0.014189 \n",
"0 0.002016 0.002790 0.001317 0.004199 0.001735 0.013888 \n",
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
"0 0.001758 0.002468 0.001048 0.003899 0.001620 0.013296 \n",
"0 0.001702 0.002361 0.001020 0.003635 0.001443 0.012589 \n",
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
"0 0.003956 0.004506 0.003861 0.006815 0.002906 0.020332 \n",
"0 0.002919 0.003433 0.002401 0.005137 0.002158 0.016458 \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",
"0 0.000449 0.000536 0.000198 0.000845 0.000274 0.002744 \n",
"0 0.016046 0.021137 0.009522 0.024214 0.008958 0.048068 \n",
"0 0.041343 0.040558 0.032107 0.067695 0.027470 0.171187 \n",
"0 0.030734 0.029292 0.021639 0.050818 0.019958 0.126646 \n",
"0 0.000481 0.000644 0.000223 0.001043 0.000335 0.003348 \n",
"0 0.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
"0 0.216980 0.204185 0.240096 0.339114 0.204905 0.572157 \n",
"\n",
" LAUC HR HR2 Reco in test Test coverage Shannon \\\n",
"0 0.518714 0.471898 0.279958 0.999682 0.111111 3.572421 \n",
"0 0.518248 0.462354 0.255567 0.854931 0.147186 3.888926 \n",
"0 0.496838 0.023330 0.006363 0.481972 0.059163 2.227849 \n",
"0 0.496838 0.023330 0.006363 0.481972 0.059163 2.227849 \n",
"0 0.496734 0.021209 0.005302 0.482503 0.057720 2.228123 \n",
"0 0.496824 0.023330 0.005302 0.482609 0.055556 2.225996 \n",
"0 0.496898 0.024390 0.007423 0.482397 0.057720 2.225807 \n",
"0 0.496799 0.023330 0.005302 0.482397 0.057720 2.225495 \n",
"0 0.496871 0.024390 0.005302 0.482609 0.058442 2.225340 \n",
"0 0.496871 0.024390 0.005302 0.482397 0.055556 2.221942 \n",
"0 0.496724 0.021209 0.004242 0.482821 0.059885 2.232578 \n",
"0 0.496724 0.021209 0.004242 0.482821 0.059885 2.232578 \n",
"0 0.496775 0.022269 0.005302 0.483351 0.059885 2.235102 \n",
"0 0.496765 0.022269 0.004242 0.483245 0.059163 2.235851 \n",
"0 0.515501 0.437964 0.239661 1.000000 0.033911 2.836513 \n",
"0 0.497969 0.039236 0.007423 0.587699 0.071429 2.699278 \n",
"0 0.497349 0.027572 0.007423 0.389926 0.067821 2.475747 \n",
"0 0.496433 0.009544 0.000000 0.699046 0.005051 1.945910 \n",
"0 0.496424 0.009544 0.000000 0.600530 0.005051 1.803126 \n",
"0 0.496391 0.003181 0.000000 0.392153 0.115440 4.174741 \n",
"0 0.496441 0.007423 0.000000 0.602121 0.010823 2.089186 \n",
"0 0.499885 0.154825 0.072110 0.402333 0.434343 5.133650 \n",
"0 0.509546 0.384942 0.142100 1.000000 0.025974 2.711772 \n",
"0 0.506031 0.305408 0.111347 0.988547 0.174603 5.082383 \n",
"0 0.496433 0.009544 0.000000 0.699046 0.005051 1.945910 \n",
"0 0.555546 0.765642 0.492047 1.000000 0.038961 3.159079 \n",
"0 0.593544 0.875928 0.685048 1.000000 0.077201 3.875892 \n",
"\n",
" Gini \n",
"0 0.980655 \n",
"0 0.972044 \n",
"0 0.994531 \n",
"0 0.994531 \n",
"0 0.994555 \n",
"0 0.994623 \n",
"0 0.994607 \n",
"0 0.994598 \n",
"0 0.994599 \n",
"0 0.994676 \n",
"0 0.994487 \n",
"0 0.994487 \n",
"0 0.994479 \n",
"0 0.994507 \n",
"0 0.991139 \n",
"0 0.991353 \n",
"0 0.992793 \n",
"0 0.995669 \n",
"0 0.996380 \n",
"0 0.965327 \n",
"0 0.995706 \n",
"0 0.877999 \n",
"0 0.992003 \n",
"0 0.908434 \n",
"0 0.995669 \n",
"0 0.987317 \n",
"0 0.974947 "
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.sort_values(by='RMSE')"
]
},
{
"cell_type": "code",
"execution_count": 34,
"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}\n",
"algo = sp.KNNBaseline(k=42)\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": 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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}