1597 lines
549 KiB
Plaintext
1597 lines
549 KiB
Plaintext
![]() |
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import helpers\n",
|
||
|
"import pandas as pd\n",
|
||
|
"import numpy as np\n",
|
||
|
"import scipy.sparse as sparse\n",
|
||
|
"from collections import defaultdict\n",
|
||
|
"from itertools import chain\n",
|
||
|
"import random\n",
|
||
|
"import time\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import implicit\n",
|
||
|
"import evaluation_measures as ev\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": [
|
||
|
"alpha = 30\n",
|
||
|
"train_ui*=alpha\n",
|
||
|
"train_iu=train_ui.transpose().tocsr()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"application/vnd.jupyter.widget-view+json": {
|
||
|
"model_id": "46ba5e7e03384fc8b3772ab86a7eb2a8",
|
||
|
"version_major": 2,
|
||
|
"version_minor": 0
|
||
|
},
|
||
|
"text/plain": [
|
||
|
"HBox(children=(FloatProgress(value=0.0, max=10.0), HTML(value='')))"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"model = implicit.als.AlternatingLeastSquares(factors=200, regularization=0.1, iterations=10)\n",
|
||
|
"model.fit(train_iu)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def top_k_recommendations(model, user_code_id, item_code_id, topK=10):\n",
|
||
|
" recommendations=[]\n",
|
||
|
" for u in range(train_ui.shape[0]):\n",
|
||
|
" u_recommended_items=model.recommend(u, train_ui, N=10, filter_already_liked_items=True)\n",
|
||
|
" recommendations.append([user_code_id[u]]+list(chain(*u_recommended_items)))\n",
|
||
|
" reco=pd.DataFrame(recommendations)\n",
|
||
|
" reco.iloc[:,1::2]=reco.iloc[:,1::2].applymap(lambda x: item_code_id[x])\n",
|
||
|
" return reco\n",
|
||
|
"\n",
|
||
|
"def estimate(model, 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",
|
||
|
" model.rank_items(userid=user, user_items=train_ui, selected_items=[item])[0][1]])\n",
|
||
|
" return result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"reco=top_k_recommendations(model, user_code_id, item_code_id, topK=10)\n",
|
||
|
"reco.to_csv('Recommendations generated/ml-100k/Ready_ImplicitALS_reco.csv', index=False, header=False)\n",
|
||
|
"\n",
|
||
|
"estimations_df=pd.DataFrame(estimate(model, user_code_id, item_code_id, test_ui))\n",
|
||
|
"estimations_df.to_csv('Recommendations generated/ml-100k/Ready_ImplicitALS_estimations.csv', index=False, header=False)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 7273.15it/s]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>RMSE</th>\n",
|
||
|
" <th>MAE</th>\n",
|
||
|
" <th>precision</th>\n",
|
||
|
" <th>recall</th>\n",
|
||
|
" <th>F_1</th>\n",
|
||
|
" <th>F_05</th>\n",
|
||
|
" <th>precision_super</th>\n",
|
||
|
" <th>recall_super</th>\n",
|
||
|
" <th>NDCG</th>\n",
|
||
|
" <th>mAP</th>\n",
|
||
|
" <th>MRR</th>\n",
|
||
|
" <th>LAUC</th>\n",
|
||
|
" <th>HR</th>\n",
|
||
|
" <th>Reco in test</th>\n",
|
||
|
" <th>Test coverage</th>\n",
|
||
|
" <th>Shannon</th>\n",
|
||
|
" <th>Gini</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>3.266101</td>\n",
|
||
|
" <td>3.065824</td>\n",
|
||
|
" <td>0.255037</td>\n",
|
||
|
" <td>0.188653</td>\n",
|
||
|
" <td>0.176852</td>\n",
|
||
|
" <td>0.201189</td>\n",
|
||
|
" <td>0.166631</td>\n",
|
||
|
" <td>0.214925</td>\n",
|
||
|
" <td>0.305908</td>\n",
|
||
|
" <td>0.172546</td>\n",
|
||
|
" <td>0.523871</td>\n",
|
||
|
" <td>0.591709</td>\n",
|
||
|
" <td>0.889714</td>\n",
|
||
|
" <td>1.0</td>\n",
|
||
|
" <td>0.502886</td>\n",
|
||
|
" <td>5.722957</td>\n",
|
||
|
" <td>0.827507</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 3.266101 3.065824 0.255037 0.188653 0.176852 0.201189 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.166631 0.214925 0.305908 0.172546 0.523871 0.591709 \n",
|
||
|
"\n",
|
||
|
" HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.889714 1.0 0.502886 5.722957 0.827507 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 9,
|
||
|
"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_ImplicitALS_estimations.csv', header=None)\n",
|
||
|
"reco=np.loadtxt('Recommendations generated/ml-100k/Ready_ImplicitALS_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": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Hiperparameters tuning"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Number of latent factors"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
" 0%| | 0/15 [00:00<?, ?it/s]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7627.67it/s]\u001b[A\n",
|
||
|
" 7%|▋ | 1/15 [00:01<00:24, 1.72s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7209.44it/s]\u001b[A\n",
|
||
|
" 13%|█▎ | 2/15 [00:03<00:22, 1.73s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7676.76it/s]\u001b[A\n",
|
||
|
" 20%|██ | 3/15 [00:05<00:20, 1.73s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6846.90it/s]\u001b[A\n",
|
||
|
" 27%|██▋ | 4/15 [00:06<00:19, 1.74s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7293.55it/s]\u001b[A\n",
|
||
|
" 33%|███▎ | 5/15 [00:08<00:17, 1.78s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7443.26it/s]\u001b[A\n",
|
||
|
" 40%|████ | 6/15 [00:10<00:16, 1.81s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6977.23it/s]\u001b[A\n",
|
||
|
" 47%|████▋ | 7/15 [00:12<00:14, 1.85s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7493.35it/s]\u001b[A\n",
|
||
|
" 53%|█████▎ | 8/15 [00:14<00:13, 1.86s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7549.26it/s]\u001b[A\n",
|
||
|
" 60%|██████ | 9/15 [00:16<00:11, 1.90s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7077.91it/s]\u001b[A\n",
|
||
|
" 67%|██████▋ | 10/15 [00:18<00:09, 1.98s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7225.27it/s]\u001b[A\n",
|
||
|
" 73%|███████▎ | 11/15 [00:20<00:08, 2.05s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7431.09it/s]\u001b[A\n",
|
||
|
" 80%|████████ | 12/15 [00:23<00:06, 2.12s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7203.73it/s]\u001b[A\n",
|
||
|
" 87%|████████▋ | 13/15 [00:25<00:04, 2.17s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7066.09it/s]\u001b[A\n",
|
||
|
" 93%|█████████▎| 14/15 [00:27<00:02, 2.24s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7179.03it/s]\u001b[A\n",
|
||
|
"100%|██████████| 15/15 [00:30<00:00, 2.03s/it]\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>Factors</th>\n",
|
||
|
" <th>RMSE</th>\n",
|
||
|
" <th>MAE</th>\n",
|
||
|
" <th>precision</th>\n",
|
||
|
" <th>recall</th>\n",
|
||
|
" <th>F_1</th>\n",
|
||
|
" <th>F_05</th>\n",
|
||
|
" <th>precision_super</th>\n",
|
||
|
" <th>recall_super</th>\n",
|
||
|
" <th>NDCG</th>\n",
|
||
|
" <th>mAP</th>\n",
|
||
|
" <th>MRR</th>\n",
|
||
|
" <th>LAUC</th>\n",
|
||
|
" <th>HR</th>\n",
|
||
|
" <th>Reco in test</th>\n",
|
||
|
" <th>Test coverage</th>\n",
|
||
|
" <th>Shannon</th>\n",
|
||
|
" <th>Gini</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>25</td>\n",
|
||
|
" <td>2.846560</td>\n",
|
||
|
" <td>2.620794</td>\n",
|
||
|
" <td>0.105726</td>\n",
|
||
|
" <td>0.108047</td>\n",
|
||
|
" <td>0.090518</td>\n",
|
||
|
" <td>0.093488</td>\n",
|
||
|
" <td>0.061481</td>\n",
|
||
|
" <td>0.123853</td>\n",
|
||
|
" <td>0.116915</td>\n",
|
||
|
" <td>0.048083</td>\n",
|
||
|
" <td>0.203663</td>\n",
|
||
|
" <td>0.550716</td>\n",
|
||
|
" <td>0.624602</td>\n",
|
||
|
" <td>0.996819</td>\n",
|
||
|
" <td>0.715007</td>\n",
|
||
|
" <td>6.465360</td>\n",
|
||
|
" <td>0.644456</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>50</td>\n",
|
||
|
" <td>2.898666</td>\n",
|
||
|
" <td>2.677181</td>\n",
|
||
|
" <td>0.143690</td>\n",
|
||
|
" <td>0.138828</td>\n",
|
||
|
" <td>0.119410</td>\n",
|
||
|
" <td>0.125049</td>\n",
|
||
|
" <td>0.089700</td>\n",
|
||
|
" <td>0.154579</td>\n",
|
||
|
" <td>0.164112</td>\n",
|
||
|
" <td>0.074820</td>\n",
|
||
|
" <td>0.284589</td>\n",
|
||
|
" <td>0.566289</td>\n",
|
||
|
" <td>0.750795</td>\n",
|
||
|
" <td>0.999258</td>\n",
|
||
|
" <td>0.664502</td>\n",
|
||
|
" <td>6.275680</td>\n",
|
||
|
" <td>0.699156</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>75</td>\n",
|
||
|
" <td>2.944450</td>\n",
|
||
|
" <td>2.726341</td>\n",
|
||
|
" <td>0.171898</td>\n",
|
||
|
" <td>0.154471</td>\n",
|
||
|
" <td>0.135551</td>\n",
|
||
|
" <td>0.145599</td>\n",
|
||
|
" <td>0.104936</td>\n",
|
||
|
" <td>0.173039</td>\n",
|
||
|
" <td>0.195845</td>\n",
|
||
|
" <td>0.092338</td>\n",
|
||
|
" <td>0.337621</td>\n",
|
||
|
" <td>0.574228</td>\n",
|
||
|
" <td>0.802757</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.598846</td>\n",
|
||
|
" <td>6.057144</td>\n",
|
||
|
" <td>0.757071</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>100</td>\n",
|
||
|
" <td>2.985948</td>\n",
|
||
|
" <td>2.769517</td>\n",
|
||
|
" <td>0.183775</td>\n",
|
||
|
" <td>0.155463</td>\n",
|
||
|
" <td>0.140189</td>\n",
|
||
|
" <td>0.152755</td>\n",
|
||
|
" <td>0.110193</td>\n",
|
||
|
" <td>0.167837</td>\n",
|
||
|
" <td>0.215259</td>\n",
|
||
|
" <td>0.106274</td>\n",
|
||
|
" <td>0.383384</td>\n",
|
||
|
" <td>0.574794</td>\n",
|
||
|
" <td>0.813362</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.558442</td>\n",
|
||
|
" <td>5.920294</td>\n",
|
||
|
" <td>0.788368</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>125</td>\n",
|
||
|
" <td>3.017333</td>\n",
|
||
|
" <td>2.802986</td>\n",
|
||
|
" <td>0.198940</td>\n",
|
||
|
" <td>0.165227</td>\n",
|
||
|
" <td>0.149710</td>\n",
|
||
|
" <td>0.164644</td>\n",
|
||
|
" <td>0.127575</td>\n",
|
||
|
" <td>0.183066</td>\n",
|
||
|
" <td>0.234839</td>\n",
|
||
|
" <td>0.119023</td>\n",
|
||
|
" <td>0.416181</td>\n",
|
||
|
" <td>0.579735</td>\n",
|
||
|
" <td>0.830329</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.532468</td>\n",
|
||
|
" <td>5.813474</td>\n",
|
||
|
" <td>0.811387</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>150</td>\n",
|
||
|
" <td>3.042801</td>\n",
|
||
|
" <td>2.830367</td>\n",
|
||
|
" <td>0.214528</td>\n",
|
||
|
" <td>0.168468</td>\n",
|
||
|
" <td>0.155574</td>\n",
|
||
|
" <td>0.173686</td>\n",
|
||
|
" <td>0.139378</td>\n",
|
||
|
" <td>0.189273</td>\n",
|
||
|
" <td>0.247685</td>\n",
|
||
|
" <td>0.126369</td>\n",
|
||
|
" <td>0.424573</td>\n",
|
||
|
" <td>0.581421</td>\n",
|
||
|
" <td>0.856840</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.507937</td>\n",
|
||
|
" <td>5.727541</td>\n",
|
||
|
" <td>0.825294</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>175</td>\n",
|
||
|
" <td>3.063186</td>\n",
|
||
|
" <td>2.851980</td>\n",
|
||
|
" <td>0.218664</td>\n",
|
||
|
" <td>0.170133</td>\n",
|
||
|
" <td>0.157283</td>\n",
|
||
|
" <td>0.176077</td>\n",
|
||
|
" <td>0.141202</td>\n",
|
||
|
" <td>0.197503</td>\n",
|
||
|
" <td>0.254178</td>\n",
|
||
|
" <td>0.132146</td>\n",
|
||
|
" <td>0.435676</td>\n",
|
||
|
" <td>0.582275</td>\n",
|
||
|
" <td>0.854719</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.497835</td>\n",
|
||
|
" <td>5.681921</td>\n",
|
||
|
" <td>0.833476</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>200</td>\n",
|
||
|
" <td>3.089628</td>\n",
|
||
|
" <td>2.878716</td>\n",
|
||
|
" <td>0.220042</td>\n",
|
||
|
" <td>0.168505</td>\n",
|
||
|
" <td>0.156406</td>\n",
|
||
|
" <td>0.176143</td>\n",
|
||
|
" <td>0.142597</td>\n",
|
||
|
" <td>0.188596</td>\n",
|
||
|
" <td>0.257188</td>\n",
|
||
|
" <td>0.134919</td>\n",
|
||
|
" <td>0.443163</td>\n",
|
||
|
" <td>0.581471</td>\n",
|
||
|
" <td>0.845175</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.490620</td>\n",
|
||
|
" <td>5.645500</td>\n",
|
||
|
" <td>0.838308</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>225</td>\n",
|
||
|
" <td>3.102684</td>\n",
|
||
|
" <td>2.892941</td>\n",
|
||
|
" <td>0.221209</td>\n",
|
||
|
" <td>0.167369</td>\n",
|
||
|
" <td>0.155187</td>\n",
|
||
|
" <td>0.175486</td>\n",
|
||
|
" <td>0.140773</td>\n",
|
||
|
" <td>0.185437</td>\n",
|
||
|
" <td>0.256898</td>\n",
|
||
|
" <td>0.134811</td>\n",
|
||
|
" <td>0.441676</td>\n",
|
||
|
" <td>0.580896</td>\n",
|
||
|
" <td>0.855779</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.474026</td>\n",
|
||
|
" <td>5.628248</td>\n",
|
||
|
" <td>0.842938</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>250</td>\n",
|
||
|
" <td>3.110198</td>\n",
|
||
|
" <td>2.901659</td>\n",
|
||
|
" <td>0.221421</td>\n",
|
||
|
" <td>0.166139</td>\n",
|
||
|
" <td>0.154255</td>\n",
|
||
|
" <td>0.175268</td>\n",
|
||
|
" <td>0.145064</td>\n",
|
||
|
" <td>0.193650</td>\n",
|
||
|
" <td>0.257955</td>\n",
|
||
|
" <td>0.136844</td>\n",
|
||
|
" <td>0.436043</td>\n",
|
||
|
" <td>0.580283</td>\n",
|
||
|
" <td>0.851538</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.482684</td>\n",
|
||
|
" <td>5.552392</td>\n",
|
||
|
" <td>0.850104</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>275</td>\n",
|
||
|
" <td>3.123178</td>\n",
|
||
|
" <td>2.915596</td>\n",
|
||
|
" <td>0.234146</td>\n",
|
||
|
" <td>0.163006</td>\n",
|
||
|
" <td>0.158760</td>\n",
|
||
|
" <td>0.183134</td>\n",
|
||
|
" <td>0.152146</td>\n",
|
||
|
" <td>0.183701</td>\n",
|
||
|
" <td>0.270489</td>\n",
|
||
|
" <td>0.144723</td>\n",
|
||
|
" <td>0.472533</td>\n",
|
||
|
" <td>0.578769</td>\n",
|
||
|
" <td>0.853659</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.460317</td>\n",
|
||
|
" <td>5.597279</td>\n",
|
||
|
" <td>0.847138</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>300</td>\n",
|
||
|
" <td>3.130343</td>\n",
|
||
|
" <td>2.923515</td>\n",
|
||
|
" <td>0.237116</td>\n",
|
||
|
" <td>0.167547</td>\n",
|
||
|
" <td>0.160936</td>\n",
|
||
|
" <td>0.185078</td>\n",
|
||
|
" <td>0.154292</td>\n",
|
||
|
" <td>0.192522</td>\n",
|
||
|
" <td>0.272852</td>\n",
|
||
|
" <td>0.149091</td>\n",
|
||
|
" <td>0.460155</td>\n",
|
||
|
" <td>0.581044</td>\n",
|
||
|
" <td>0.841994</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.457431</td>\n",
|
||
|
" <td>5.534284</td>\n",
|
||
|
" <td>0.855633</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>325</td>\n",
|
||
|
" <td>3.141945</td>\n",
|
||
|
" <td>2.934988</td>\n",
|
||
|
" <td>0.232025</td>\n",
|
||
|
" <td>0.165168</td>\n",
|
||
|
" <td>0.157315</td>\n",
|
||
|
" <td>0.181076</td>\n",
|
||
|
" <td>0.147639</td>\n",
|
||
|
" <td>0.179435</td>\n",
|
||
|
" <td>0.272440</td>\n",
|
||
|
" <td>0.150512</td>\n",
|
||
|
" <td>0.462026</td>\n",
|
||
|
" <td>0.579861</td>\n",
|
||
|
" <td>0.840933</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.451659</td>\n",
|
||
|
" <td>5.500822</td>\n",
|
||
|
" <td>0.860569</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>350</td>\n",
|
||
|
" <td>3.149635</td>\n",
|
||
|
" <td>2.943592</td>\n",
|
||
|
" <td>0.232662</td>\n",
|
||
|
" <td>0.167366</td>\n",
|
||
|
" <td>0.158349</td>\n",
|
||
|
" <td>0.181597</td>\n",
|
||
|
" <td>0.151717</td>\n",
|
||
|
" <td>0.186675</td>\n",
|
||
|
" <td>0.270835</td>\n",
|
||
|
" <td>0.146983</td>\n",
|
||
|
" <td>0.463859</td>\n",
|
||
|
" <td>0.580944</td>\n",
|
||
|
" <td>0.853659</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.458153</td>\n",
|
||
|
" <td>5.490997</td>\n",
|
||
|
" <td>0.860762</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>375</td>\n",
|
||
|
" <td>3.161007</td>\n",
|
||
|
" <td>2.955454</td>\n",
|
||
|
" <td>0.234571</td>\n",
|
||
|
" <td>0.167177</td>\n",
|
||
|
" <td>0.159795</td>\n",
|
||
|
" <td>0.183107</td>\n",
|
||
|
" <td>0.150536</td>\n",
|
||
|
" <td>0.180057</td>\n",
|
||
|
" <td>0.269211</td>\n",
|
||
|
" <td>0.147040</td>\n",
|
||
|
" <td>0.451392</td>\n",
|
||
|
" <td>0.580851</td>\n",
|
||
|
" <td>0.851538</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.460317</td>\n",
|
||
|
" <td>5.478842</td>\n",
|
||
|
" <td>0.860159</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Factors RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 25 2.846560 2.620794 0.105726 0.108047 0.090518 0.093488 \n",
|
||
|
"0 50 2.898666 2.677181 0.143690 0.138828 0.119410 0.125049 \n",
|
||
|
"0 75 2.944450 2.726341 0.171898 0.154471 0.135551 0.145599 \n",
|
||
|
"0 100 2.985948 2.769517 0.183775 0.155463 0.140189 0.152755 \n",
|
||
|
"0 125 3.017333 2.802986 0.198940 0.165227 0.149710 0.164644 \n",
|
||
|
"0 150 3.042801 2.830367 0.214528 0.168468 0.155574 0.173686 \n",
|
||
|
"0 175 3.063186 2.851980 0.218664 0.170133 0.157283 0.176077 \n",
|
||
|
"0 200 3.089628 2.878716 0.220042 0.168505 0.156406 0.176143 \n",
|
||
|
"0 225 3.102684 2.892941 0.221209 0.167369 0.155187 0.175486 \n",
|
||
|
"0 250 3.110198 2.901659 0.221421 0.166139 0.154255 0.175268 \n",
|
||
|
"0 275 3.123178 2.915596 0.234146 0.163006 0.158760 0.183134 \n",
|
||
|
"0 300 3.130343 2.923515 0.237116 0.167547 0.160936 0.185078 \n",
|
||
|
"0 325 3.141945 2.934988 0.232025 0.165168 0.157315 0.181076 \n",
|
||
|
"0 350 3.149635 2.943592 0.232662 0.167366 0.158349 0.181597 \n",
|
||
|
"0 375 3.161007 2.955454 0.234571 0.167177 0.159795 0.183107 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.061481 0.123853 0.116915 0.048083 0.203663 0.550716 \n",
|
||
|
"0 0.089700 0.154579 0.164112 0.074820 0.284589 0.566289 \n",
|
||
|
"0 0.104936 0.173039 0.195845 0.092338 0.337621 0.574228 \n",
|
||
|
"0 0.110193 0.167837 0.215259 0.106274 0.383384 0.574794 \n",
|
||
|
"0 0.127575 0.183066 0.234839 0.119023 0.416181 0.579735 \n",
|
||
|
"0 0.139378 0.189273 0.247685 0.126369 0.424573 0.581421 \n",
|
||
|
"0 0.141202 0.197503 0.254178 0.132146 0.435676 0.582275 \n",
|
||
|
"0 0.142597 0.188596 0.257188 0.134919 0.443163 0.581471 \n",
|
||
|
"0 0.140773 0.185437 0.256898 0.134811 0.441676 0.580896 \n",
|
||
|
"0 0.145064 0.193650 0.257955 0.136844 0.436043 0.580283 \n",
|
||
|
"0 0.152146 0.183701 0.270489 0.144723 0.472533 0.578769 \n",
|
||
|
"0 0.154292 0.192522 0.272852 0.149091 0.460155 0.581044 \n",
|
||
|
"0 0.147639 0.179435 0.272440 0.150512 0.462026 0.579861 \n",
|
||
|
"0 0.151717 0.186675 0.270835 0.146983 0.463859 0.580944 \n",
|
||
|
"0 0.150536 0.180057 0.269211 0.147040 0.451392 0.580851 \n",
|
||
|
"\n",
|
||
|
" HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.624602 0.996819 0.715007 6.465360 0.644456 \n",
|
||
|
"0 0.750795 0.999258 0.664502 6.275680 0.699156 \n",
|
||
|
"0 0.802757 0.999894 0.598846 6.057144 0.757071 \n",
|
||
|
"0 0.813362 1.000000 0.558442 5.920294 0.788368 \n",
|
||
|
"0 0.830329 0.999788 0.532468 5.813474 0.811387 \n",
|
||
|
"0 0.856840 1.000000 0.507937 5.727541 0.825294 \n",
|
||
|
"0 0.854719 1.000000 0.497835 5.681921 0.833476 \n",
|
||
|
"0 0.845175 0.999894 0.490620 5.645500 0.838308 \n",
|
||
|
"0 0.855779 1.000000 0.474026 5.628248 0.842938 \n",
|
||
|
"0 0.851538 1.000000 0.482684 5.552392 0.850104 \n",
|
||
|
"0 0.853659 1.000000 0.460317 5.597279 0.847138 \n",
|
||
|
"0 0.841994 1.000000 0.457431 5.534284 0.855633 \n",
|
||
|
"0 0.840933 1.000000 0.451659 5.500822 0.860569 \n",
|
||
|
"0 0.853659 1.000000 0.458153 5.490997 0.860762 \n",
|
||
|
"0 0.851538 0.999894 0.460317 5.478842 0.860159 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from tqdm import tqdm\n",
|
||
|
"result=[]\n",
|
||
|
"for factors in tqdm([i for i in np.arange(25,400,25)]):\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)\n",
|
||
|
" \n",
|
||
|
" train_ui*=100\n",
|
||
|
" train_iu=train_ui.transpose().tocsr()\n",
|
||
|
" \n",
|
||
|
" model = implicit.als.AlternatingLeastSquares(factors=factors, regularization=0.1, iterations=10)\n",
|
||
|
" model.fit(train_iu, show_progress=False)\n",
|
||
|
" \n",
|
||
|
" reco=top_k_recommendations(model, user_code_id, item_code_id, topK=10)\n",
|
||
|
" estimations_df=pd.DataFrame(estimate(model, user_code_id, item_code_id, test_ui))\n",
|
||
|
" \n",
|
||
|
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
|
||
|
" estimations_df=estimations_df, \n",
|
||
|
" reco=np.array(reco),\n",
|
||
|
" super_reactions=[4,5])\n",
|
||
|
" to_append.insert(0, \"Factors\", factors)\n",
|
||
|
" result.append(to_append)\n",
|
||
|
" \n",
|
||
|
"result=pd.concat(result)\n",
|
||
|
"result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABCAAAAkoCAYAAAC6aM7IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzdd3RVVdrH8e9OSAgh1BBCCRA6oRm6iCiCCCqogzpiV3QYHevo+Nq7zljGPjiW0WEcFQugoCAI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EhoYSExPDsmXLAHj//ff5/e9/f7B+x44dREUdnAZInz59qi5YEZFa5KyzzmLOnDkATJs2jYsvvviQ+pkzZzJ+/HgmTpzIe++9548QRaR2Wgp0dc51dM4FAxOB2aUbOOf6Aa8C55hZ2oFyM7vUzNqbWTTeaRhv1dTkQ1JSEj169ODSSy8lJiaGCy64gLy8PKKjo7nzzjvp378/H374IZ9//jlDhw6lf//+XHjhheTk5ACwdOlSTjrpJE444QQGDx5MdnY2ixYtOjiS7euvvz44Sq1fv35kZ2eTlJRE7969Ae8aGFdffTV9+vShX79+fPXVVwBMnTqVCRMmMHbsWLp27cr//d//+ecvSESOqkaOgHj4kzUkbN9Xodfs2aYxD47vdeyGeLO6X3zxBddcc80h5QcediMjIwkMDKRNmzZs374d8H7rNnLkSE466STOOOMMrr76apo2bQrA4sWLiY2NPXidGTNm0Llz5wq6MxGRiufPfnjixIk88sgjjBs3jpUrVzJp0iQWL158sH7atGk
|
||
|
"text/plain": [
|
||
|
"<Figure size 1296x3024 with 18 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"### import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"metrics=list(result.columns[[i not in ['Factors'] for i in result.columns]])\n",
|
||
|
"\n",
|
||
|
"charts_per_row=6\n",
|
||
|
"charts_per_column=3\n",
|
||
|
"\n",
|
||
|
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
|
||
|
"import itertools\n",
|
||
|
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
|
||
|
"\n",
|
||
|
"for i in range(len(metrics)):\n",
|
||
|
" df=result[['Factors', metrics[i]]]\n",
|
||
|
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Alpha"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
" 0%| | 0/13 [00:00<?, ?it/s]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7477.64it/s]\u001b[A\n",
|
||
|
" 8%|▊ | 1/13 [00:02<00:31, 2.61s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7366.79it/s]\u001b[A\n",
|
||
|
" 15%|█▌ | 2/13 [00:05<00:28, 2.58s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7482.23it/s]\u001b[A\n",
|
||
|
" 23%|██▎ | 3/13 [00:07<00:25, 2.58s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7401.22it/s]\u001b[A\n",
|
||
|
" 31%|███ | 4/13 [00:10<00:23, 2.58s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6881.15it/s]\u001b[A\n",
|
||
|
" 38%|███▊ | 5/13 [00:12<00:20, 2.59s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6983.24it/s]\u001b[A\n",
|
||
|
" 46%|████▌ | 6/13 [00:15<00:17, 2.56s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6942.52it/s]\u001b[A\n",
|
||
|
" 54%|█████▍ | 7/13 [00:17<00:15, 2.55s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7235.29it/s]\u001b[A\n",
|
||
|
" 62%|██████▏ | 8/13 [00:20<00:12, 2.53s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7101.42it/s]\u001b[A\n",
|
||
|
" 69%|██████▉ | 9/13 [00:22<00:10, 2.53s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7151.07it/s]\u001b[A\n",
|
||
|
" 77%|███████▋ | 10/13 [00:25<00:07, 2.51s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7058.24it/s]\u001b[A\n",
|
||
|
" 85%|████████▍ | 11/13 [00:27<00:04, 2.49s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 7171.05it/s]\u001b[A\n",
|
||
|
" 92%|█████████▏| 12/13 [00:30<00:02, 2.48s/it]\n",
|
||
|
"0it [00:00, ?it/s]\u001b[A\n",
|
||
|
"943it [00:00, 6831.82it/s]\u001b[A\n",
|
||
|
"100%|██████████| 13/13 [00:32<00:00, 2.52s/it]\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>Alpha</th>\n",
|
||
|
" <th>RMSE</th>\n",
|
||
|
" <th>MAE</th>\n",
|
||
|
" <th>precision</th>\n",
|
||
|
" <th>recall</th>\n",
|
||
|
" <th>F_1</th>\n",
|
||
|
" <th>F_05</th>\n",
|
||
|
" <th>precision_super</th>\n",
|
||
|
" <th>recall_super</th>\n",
|
||
|
" <th>NDCG</th>\n",
|
||
|
" <th>mAP</th>\n",
|
||
|
" <th>MRR</th>\n",
|
||
|
" <th>LAUC</th>\n",
|
||
|
" <th>HR</th>\n",
|
||
|
" <th>Reco in test</th>\n",
|
||
|
" <th>Test coverage</th>\n",
|
||
|
" <th>Shannon</th>\n",
|
||
|
" <th>Gini</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>1</td>\n",
|
||
|
" <td>3.667401</td>\n",
|
||
|
" <td>3.489285</td>\n",
|
||
|
" <td>0.097349</td>\n",
|
||
|
" <td>0.072948</td>\n",
|
||
|
" <td>0.068621</td>\n",
|
||
|
" <td>0.077305</td>\n",
|
||
|
" <td>0.054614</td>\n",
|
||
|
" <td>0.071923</td>\n",
|
||
|
" <td>0.115946</td>\n",
|
||
|
" <td>0.050679</td>\n",
|
||
|
" <td>0.253435</td>\n",
|
||
|
" <td>0.533195</td>\n",
|
||
|
" <td>0.577943</td>\n",
|
||
|
" <td>0.994804</td>\n",
|
||
|
" <td>0.730880</td>\n",
|
||
|
" <td>6.699624</td>\n",
|
||
|
" <td>0.535431</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>3</td>\n",
|
||
|
" <td>3.628888</td>\n",
|
||
|
" <td>3.449626</td>\n",
|
||
|
" <td>0.142418</td>\n",
|
||
|
" <td>0.099087</td>\n",
|
||
|
" <td>0.095250</td>\n",
|
||
|
" <td>0.109958</td>\n",
|
||
|
" <td>0.086159</td>\n",
|
||
|
" <td>0.105848</td>\n",
|
||
|
" <td>0.170625</td>\n",
|
||
|
" <td>0.082786</td>\n",
|
||
|
" <td>0.347226</td>\n",
|
||
|
" <td>0.546454</td>\n",
|
||
|
" <td>0.698834</td>\n",
|
||
|
" <td>0.994910</td>\n",
|
||
|
" <td>0.712121</td>\n",
|
||
|
" <td>6.639279</td>\n",
|
||
|
" <td>0.568322</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>7</td>\n",
|
||
|
" <td>3.557600</td>\n",
|
||
|
" <td>3.376851</td>\n",
|
||
|
" <td>0.219618</td>\n",
|
||
|
" <td>0.145557</td>\n",
|
||
|
" <td>0.142994</td>\n",
|
||
|
" <td>0.167132</td>\n",
|
||
|
" <td>0.142489</td>\n",
|
||
|
" <td>0.165904</td>\n",
|
||
|
" <td>0.259872</td>\n",
|
||
|
" <td>0.143493</td>\n",
|
||
|
" <td>0.465442</td>\n",
|
||
|
" <td>0.570010</td>\n",
|
||
|
" <td>0.820785</td>\n",
|
||
|
" <td>0.997137</td>\n",
|
||
|
" <td>0.629870</td>\n",
|
||
|
" <td>6.325220</td>\n",
|
||
|
" <td>0.691428</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>10</td>\n",
|
||
|
" <td>3.507947</td>\n",
|
||
|
" <td>3.325719</td>\n",
|
||
|
" <td>0.255143</td>\n",
|
||
|
" <td>0.174045</td>\n",
|
||
|
" <td>0.168845</td>\n",
|
||
|
" <td>0.196237</td>\n",
|
||
|
" <td>0.170386</td>\n",
|
||
|
" <td>0.197982</td>\n",
|
||
|
" <td>0.307968</td>\n",
|
||
|
" <td>0.179416</td>\n",
|
||
|
" <td>0.542711</td>\n",
|
||
|
" <td>0.584408</td>\n",
|
||
|
" <td>0.863203</td>\n",
|
||
|
" <td>0.998197</td>\n",
|
||
|
" <td>0.579365</td>\n",
|
||
|
" <td>6.075866</td>\n",
|
||
|
" <td>0.756129</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>30</td>\n",
|
||
|
" <td>3.359788</td>\n",
|
||
|
" <td>3.168804</td>\n",
|
||
|
" <td>0.271262</td>\n",
|
||
|
" <td>0.191732</td>\n",
|
||
|
" <td>0.184405</td>\n",
|
||
|
" <td>0.211858</td>\n",
|
||
|
" <td>0.182833</td>\n",
|
||
|
" <td>0.228368</td>\n",
|
||
|
" <td>0.323901</td>\n",
|
||
|
" <td>0.187954</td>\n",
|
||
|
" <td>0.549506</td>\n",
|
||
|
" <td>0.593310</td>\n",
|
||
|
" <td>0.889714</td>\n",
|
||
|
" <td>0.999470</td>\n",
|
||
|
" <td>0.494949</td>\n",
|
||
|
" <td>5.612128</td>\n",
|
||
|
" <td>0.840695</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>50</td>\n",
|
||
|
" <td>3.273254</td>\n",
|
||
|
" <td>3.075697</td>\n",
|
||
|
" <td>0.265217</td>\n",
|
||
|
" <td>0.188703</td>\n",
|
||
|
" <td>0.179673</td>\n",
|
||
|
" <td>0.206738</td>\n",
|
||
|
" <td>0.174571</td>\n",
|
||
|
" <td>0.214519</td>\n",
|
||
|
" <td>0.315700</td>\n",
|
||
|
" <td>0.182200</td>\n",
|
||
|
" <td>0.532506</td>\n",
|
||
|
" <td>0.591772</td>\n",
|
||
|
" <td>0.872747</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.466089</td>\n",
|
||
|
" <td>5.493297</td>\n",
|
||
|
" <td>0.856776</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>70</td>\n",
|
||
|
" <td>3.214601</td>\n",
|
||
|
" <td>3.012592</td>\n",
|
||
|
" <td>0.249629</td>\n",
|
||
|
" <td>0.175516</td>\n",
|
||
|
" <td>0.169005</td>\n",
|
||
|
" <td>0.194526</td>\n",
|
||
|
" <td>0.162661</td>\n",
|
||
|
" <td>0.202930</td>\n",
|
||
|
" <td>0.292262</td>\n",
|
||
|
" <td>0.163398</td>\n",
|
||
|
" <td>0.501654</td>\n",
|
||
|
" <td>0.585098</td>\n",
|
||
|
" <td>0.862142</td>\n",
|
||
|
" <td>0.999788</td>\n",
|
||
|
" <td>0.450938</td>\n",
|
||
|
" <td>5.482008</td>\n",
|
||
|
" <td>0.860232</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>90</td>\n",
|
||
|
" <td>3.174570</td>\n",
|
||
|
" <td>2.970676</td>\n",
|
||
|
" <td>0.244751</td>\n",
|
||
|
" <td>0.171145</td>\n",
|
||
|
" <td>0.164571</td>\n",
|
||
|
" <td>0.190198</td>\n",
|
||
|
" <td>0.162876</td>\n",
|
||
|
" <td>0.199225</td>\n",
|
||
|
" <td>0.283543</td>\n",
|
||
|
" <td>0.156381</td>\n",
|
||
|
" <td>0.479877</td>\n",
|
||
|
" <td>0.582885</td>\n",
|
||
|
" <td>0.849417</td>\n",
|
||
|
" <td>0.999894</td>\n",
|
||
|
" <td>0.450216</td>\n",
|
||
|
" <td>5.491347</td>\n",
|
||
|
" <td>0.861497</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>110</td>\n",
|
||
|
" <td>3.138148</td>\n",
|
||
|
" <td>2.931536</td>\n",
|
||
|
" <td>0.229692</td>\n",
|
||
|
" <td>0.164445</td>\n",
|
||
|
" <td>0.156457</td>\n",
|
||
|
" <td>0.179431</td>\n",
|
||
|
" <td>0.151931</td>\n",
|
||
|
" <td>0.191769</td>\n",
|
||
|
" <td>0.267423</td>\n",
|
||
|
" <td>0.144461</td>\n",
|
||
|
" <td>0.460625</td>\n",
|
||
|
" <td>0.579477</td>\n",
|
||
|
" <td>0.845175</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.458153</td>\n",
|
||
|
" <td>5.474450</td>\n",
|
||
|
" <td>0.861871</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>130</td>\n",
|
||
|
" <td>3.114034</td>\n",
|
||
|
" <td>2.904438</td>\n",
|
||
|
" <td>0.225133</td>\n",
|
||
|
" <td>0.158999</td>\n",
|
||
|
" <td>0.152533</td>\n",
|
||
|
" <td>0.175715</td>\n",
|
||
|
" <td>0.149571</td>\n",
|
||
|
" <td>0.183970</td>\n",
|
||
|
" <td>0.258418</td>\n",
|
||
|
" <td>0.138422</td>\n",
|
||
|
" <td>0.438959</td>\n",
|
||
|
" <td>0.576722</td>\n",
|
||
|
" <td>0.826087</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.449495</td>\n",
|
||
|
" <td>5.474419</td>\n",
|
||
|
" <td>0.862658</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>150</td>\n",
|
||
|
" <td>3.089790</td>\n",
|
||
|
" <td>2.880051</td>\n",
|
||
|
" <td>0.219300</td>\n",
|
||
|
" <td>0.155447</td>\n",
|
||
|
" <td>0.149104</td>\n",
|
||
|
" <td>0.171284</td>\n",
|
||
|
" <td>0.144635</td>\n",
|
||
|
" <td>0.176639</td>\n",
|
||
|
" <td>0.250976</td>\n",
|
||
|
" <td>0.130455</td>\n",
|
||
|
" <td>0.445470</td>\n",
|
||
|
" <td>0.574904</td>\n",
|
||
|
" <td>0.851538</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.461760</td>\n",
|
||
|
" <td>5.473903</td>\n",
|
||
|
" <td>0.864300</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>170</td>\n",
|
||
|
" <td>3.070975</td>\n",
|
||
|
" <td>2.858780</td>\n",
|
||
|
" <td>0.216331</td>\n",
|
||
|
" <td>0.158103</td>\n",
|
||
|
" <td>0.149290</td>\n",
|
||
|
" <td>0.170456</td>\n",
|
||
|
" <td>0.141416</td>\n",
|
||
|
" <td>0.181804</td>\n",
|
||
|
" <td>0.247910</td>\n",
|
||
|
" <td>0.129594</td>\n",
|
||
|
" <td>0.427431</td>\n",
|
||
|
" <td>0.576235</td>\n",
|
||
|
" <td>0.831389</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.463925</td>\n",
|
||
|
" <td>5.500412</td>\n",
|
||
|
" <td>0.857992</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>190</td>\n",
|
||
|
" <td>3.055852</td>\n",
|
||
|
" <td>2.843086</td>\n",
|
||
|
" <td>0.207317</td>\n",
|
||
|
" <td>0.149367</td>\n",
|
||
|
" <td>0.142287</td>\n",
|
||
|
" <td>0.162816</td>\n",
|
||
|
" <td>0.132833</td>\n",
|
||
|
" <td>0.163011</td>\n",
|
||
|
" <td>0.234566</td>\n",
|
||
|
" <td>0.119859</td>\n",
|
||
|
" <td>0.405354</td>\n",
|
||
|
" <td>0.571824</td>\n",
|
||
|
" <td>0.831389</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.467532</td>\n",
|
||
|
" <td>5.523357</td>\n",
|
||
|
" <td>0.857033</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Alpha RMSE MAE precision recall F_1 F_05 \\\n",
|
||
|
"0 1 3.667401 3.489285 0.097349 0.072948 0.068621 0.077305 \n",
|
||
|
"0 3 3.628888 3.449626 0.142418 0.099087 0.095250 0.109958 \n",
|
||
|
"0 7 3.557600 3.376851 0.219618 0.145557 0.142994 0.167132 \n",
|
||
|
"0 10 3.507947 3.325719 0.255143 0.174045 0.168845 0.196237 \n",
|
||
|
"0 30 3.359788 3.168804 0.271262 0.191732 0.184405 0.211858 \n",
|
||
|
"0 50 3.273254 3.075697 0.265217 0.188703 0.179673 0.206738 \n",
|
||
|
"0 70 3.214601 3.012592 0.249629 0.175516 0.169005 0.194526 \n",
|
||
|
"0 90 3.174570 2.970676 0.244751 0.171145 0.164571 0.190198 \n",
|
||
|
"0 110 3.138148 2.931536 0.229692 0.164445 0.156457 0.179431 \n",
|
||
|
"0 130 3.114034 2.904438 0.225133 0.158999 0.152533 0.175715 \n",
|
||
|
"0 150 3.089790 2.880051 0.219300 0.155447 0.149104 0.171284 \n",
|
||
|
"0 170 3.070975 2.858780 0.216331 0.158103 0.149290 0.170456 \n",
|
||
|
"0 190 3.055852 2.843086 0.207317 0.149367 0.142287 0.162816 \n",
|
||
|
"\n",
|
||
|
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
|
||
|
"0 0.054614 0.071923 0.115946 0.050679 0.253435 0.533195 \n",
|
||
|
"0 0.086159 0.105848 0.170625 0.082786 0.347226 0.546454 \n",
|
||
|
"0 0.142489 0.165904 0.259872 0.143493 0.465442 0.570010 \n",
|
||
|
"0 0.170386 0.197982 0.307968 0.179416 0.542711 0.584408 \n",
|
||
|
"0 0.182833 0.228368 0.323901 0.187954 0.549506 0.593310 \n",
|
||
|
"0 0.174571 0.214519 0.315700 0.182200 0.532506 0.591772 \n",
|
||
|
"0 0.162661 0.202930 0.292262 0.163398 0.501654 0.585098 \n",
|
||
|
"0 0.162876 0.199225 0.283543 0.156381 0.479877 0.582885 \n",
|
||
|
"0 0.151931 0.191769 0.267423 0.144461 0.460625 0.579477 \n",
|
||
|
"0 0.149571 0.183970 0.258418 0.138422 0.438959 0.576722 \n",
|
||
|
"0 0.144635 0.176639 0.250976 0.130455 0.445470 0.574904 \n",
|
||
|
"0 0.141416 0.181804 0.247910 0.129594 0.427431 0.576235 \n",
|
||
|
"0 0.132833 0.163011 0.234566 0.119859 0.405354 0.571824 \n",
|
||
|
"\n",
|
||
|
" HR Reco in test Test coverage Shannon Gini \n",
|
||
|
"0 0.577943 0.994804 0.730880 6.699624 0.535431 \n",
|
||
|
"0 0.698834 0.994910 0.712121 6.639279 0.568322 \n",
|
||
|
"0 0.820785 0.997137 0.629870 6.325220 0.691428 \n",
|
||
|
"0 0.863203 0.998197 0.579365 6.075866 0.756129 \n",
|
||
|
"0 0.889714 0.999470 0.494949 5.612128 0.840695 \n",
|
||
|
"0 0.872747 1.000000 0.466089 5.493297 0.856776 \n",
|
||
|
"0 0.862142 0.999788 0.450938 5.482008 0.860232 \n",
|
||
|
"0 0.849417 0.999894 0.450216 5.491347 0.861497 \n",
|
||
|
"0 0.845175 1.000000 0.458153 5.474450 0.861871 \n",
|
||
|
"0 0.826087 1.000000 0.449495 5.474419 0.862658 \n",
|
||
|
"0 0.851538 1.000000 0.461760 5.473903 0.864300 \n",
|
||
|
"0 0.831389 1.000000 0.463925 5.500412 0.857992 \n",
|
||
|
"0 0.831389 1.000000 0.467532 5.523357 0.857033 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from tqdm import tqdm\n",
|
||
|
"result=[]\n",
|
||
|
"for alpha in tqdm([1, 3, 7]+[i for i in np.arange(10,200,20)]):\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)\n",
|
||
|
" \n",
|
||
|
" train_ui*=alpha\n",
|
||
|
" train_iu=train_ui.transpose().tocsr()\n",
|
||
|
" \n",
|
||
|
" model = implicit.als.AlternatingLeastSquares(factors=factors, regularization=0.1, iterations=10)\n",
|
||
|
" model.fit(train_iu, show_progress=False)\n",
|
||
|
" \n",
|
||
|
" reco=top_k_recommendations(model, user_code_id, item_code_id, topK=10)\n",
|
||
|
" estimations_df=pd.DataFrame(estimate(model, user_code_id, item_code_id, test_ui))\n",
|
||
|
" \n",
|
||
|
" to_append=ev.evaluate(test=pd.read_csv('./Datasets/ml-100k/test.csv', sep='\\t', header=None),\n",
|
||
|
" estimations_df=estimations_df, \n",
|
||
|
" reco=np.array(reco),\n",
|
||
|
" super_reactions=[4,5])\n",
|
||
|
" to_append.insert(0, \"Alpha\", alpha)\n",
|
||
|
" result.append(to_append)\n",
|
||
|
" \n",
|
||
|
"result=pd.concat(result)\n",
|
||
|
"result"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABB8AAAkoCAYAAAAjkBd9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOzdeXyU1fXH8c+Z7DtLVpKwh4BsQSCCiIqKYFXcBapWxaXaqm3VurS2trb2V/Xn8rPFqrUtWpVFqnXDXVBcQEAQkB1kXxLAsCVkvb8/ZhJDDMqS5Elmvu/Xa17NPM+dZ87oq9dnztx7jjnnEBERERERERFpLD6vAxARERERERGR4Kbkg4iIiIiIiIg0KiUfRERERERERKRRKfkgIiIiIiIiIo1KyQcRERERERERaVRKPoiIiIiIiIhIo1LyQUREREREJEiZ2eNm9ptDGPelmZ3cBCFJiFLyQZo9M1trZiVmttfMtprZBDOLD5ybYGbOzM6p85qHA8evCDyPNLMHzWxj4DprzeyRg7xH9eOvTfpBRURaiMCcWWZmyXWOzw/MvR1rHftd4NhxdcZeYWaVdebdvWbWrmk+hYhIaHDOXeec+8MhjOvpnJvRBCFJiFLyQVqKs51z8UAe0A+4s9a5FcCPqp+YWThwM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+nevTuXXHIJPXr04MILL6S4uJiOHTty++23c+yxx/LCCy/w9ttvM3jwYI499lguuugi9u7176qdM2cOxx9/PH379iU/P589e/YwY8aMmlVmH3zwQc0Ksn7
|
||
|
"text/plain": [
|
||
|
"<Figure size 1296x3024 with 18 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"### import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"metrics=list(result.columns[[i not in ['Alpha'] for i in result.columns]])\n",
|
||
|
"\n",
|
||
|
"charts_per_row=6\n",
|
||
|
"charts_per_column=3\n",
|
||
|
"\n",
|
||
|
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
|
||
|
"import itertools\n",
|
||
|
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
|
||
|
"\n",
|
||
|
"for i in range(len(metrics)):\n",
|
||
|
" df=result[['Alpha', metrics[i]]]\n",
|
||
|
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"943it [00:00, 7384.16it/s]\n",
|
||
|
"943it [00:00, 7881.42it/s]\n",
|
||
|
"943it [00:00, 8618.41it/s]\n",
|
||
|
"943it [00:00, 7851.41it/s]\n",
|
||
|
"943it [00:00, 8173.68it/s]\n",
|
||
|
"943it [00:00, 7964.65it/s]\n",
|
||
|
"943it [00:00, 6842.04it/s]\n",
|
||
|
"943it [00:00, 6556.41it/s]\n",
|
||
|
"943it [00:00, 8900.33it/s]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/html": [
|
||
|
"<div>\n",
|
||
|
"<style scoped>\n",
|
||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
" vertical-align: middle;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe tbody tr th {\n",
|
||
|
" vertical-align: top;\n",
|
||
|
" }\n",
|
||
|
"\n",
|
||
|
" .dataframe thead th {\n",
|
||
|
" text-align: right;\n",
|
||
|
" }\n",
|
||
|
"</style>\n",
|
||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
" <thead>\n",
|
||
|
" <tr style=\"text-align: right;\">\n",
|
||
|
" <th></th>\n",
|
||
|
" <th>Model</th>\n",
|
||
|
" <th>RMSE</th>\n",
|
||
|
" <th>MAE</th>\n",
|
||
|
" <th>precision</th>\n",
|
||
|
" <th>recall</th>\n",
|
||
|
" <th>F_1</th>\n",
|
||
|
" <th>F_05</th>\n",
|
||
|
" <th>precision_super</th>\n",
|
||
|
" <th>recall_super</th>\n",
|
||
|
" <th>NDCG</th>\n",
|
||
|
" <th>mAP</th>\n",
|
||
|
" <th>MRR</th>\n",
|
||
|
" <th>LAUC</th>\n",
|
||
|
" <th>HR</th>\n",
|
||
|
" <th>Reco in test</th>\n",
|
||
|
" <th>Test coverage</th>\n",
|
||
|
" <th>Shannon</th>\n",
|
||
|
" <th>Gini</th>\n",
|
||
|
" </tr>\n",
|
||
|
" </thead>\n",
|
||
|
" <tbody>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_LightFMpureMF</td>\n",
|
||
|
" <td>7.953192</td>\n",
|
||
|
" <td>7.462008</td>\n",
|
||
|
" <td>0.334464</td>\n",
|
||
|
" <td>0.219997</td>\n",
|
||
|
" <td>0.217225</td>\n",
|
||
|
" <td>0.254981</td>\n",
|
||
|
" <td>0.233798</td>\n",
|
||
|
" <td>0.266952</td>\n",
|
||
|
" <td>0.398778</td>\n",
|
||
|
" <td>0.263058</td>\n",
|
||
|
" <td>0.629129</td>\n",
|
||
|
" <td>0.607709</td>\n",
|
||
|
" <td>0.913043</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.275613</td>\n",
|
||
|
" <td>5.085818</td>\n",
|
||
|
" <td>0.913665</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_LightFM</td>\n",
|
||
|
" <td>162.707436</td>\n",
|
||
|
" <td>160.855483</td>\n",
|
||
|
" <td>0.340827</td>\n",
|
||
|
" <td>0.217682</td>\n",
|
||
|
" <td>0.217990</td>\n",
|
||
|
" <td>0.258010</td>\n",
|
||
|
" <td>0.243884</td>\n",
|
||
|
" <td>0.260663</td>\n",
|
||
|
" <td>0.403850</td>\n",
|
||
|
" <td>0.268266</td>\n",
|
||
|
" <td>0.637590</td>\n",
|
||
|
" <td>0.606568</td>\n",
|
||
|
" <td>0.898197</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.351371</td>\n",
|
||
|
" <td>5.366291</td>\n",
|
||
|
" <td>0.885046</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_ImplicitALS</td>\n",
|
||
|
" <td>3.266101</td>\n",
|
||
|
" <td>3.065824</td>\n",
|
||
|
" <td>0.255037</td>\n",
|
||
|
" <td>0.188653</td>\n",
|
||
|
" <td>0.176852</td>\n",
|
||
|
" <td>0.201189</td>\n",
|
||
|
" <td>0.166631</td>\n",
|
||
|
" <td>0.214925</td>\n",
|
||
|
" <td>0.305908</td>\n",
|
||
|
" <td>0.172546</td>\n",
|
||
|
" <td>0.523871</td>\n",
|
||
|
" <td>0.591709</td>\n",
|
||
|
" <td>0.889714</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.502886</td>\n",
|
||
|
" <td>5.722957</td>\n",
|
||
|
" <td>0.827507</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>1.000000</td>\n",
|
||
|
" <td>0.038961</td>\n",
|
||
|
" <td>3.159079</td>\n",
|
||
|
" <td>0.987317</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_LightFMcontent</td>\n",
|
||
|
" <td>182.471340</td>\n",
|
||
|
" <td>180.405210</td>\n",
|
||
|
" <td>0.160339</td>\n",
|
||
|
" <td>0.101224</td>\n",
|
||
|
" <td>0.102198</td>\n",
|
||
|
" <td>0.121074</td>\n",
|
||
|
" <td>0.102682</td>\n",
|
||
|
" <td>0.112455</td>\n",
|
||
|
" <td>0.180079</td>\n",
|
||
|
" <td>0.087429</td>\n",
|
||
|
" <td>0.337825</td>\n",
|
||
|
" <td>0.547572</td>\n",
|
||
|
" <td>0.704136</td>\n",
|
||
|
" <td>0.974973</td>\n",
|
||
|
" <td>0.264791</td>\n",
|
||
|
" <td>4.909893</td>\n",
|
||
|
" <td>0.926201</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Ready_Baseline</td>\n",
|
||
|
" <td>0.949459</td>\n",
|
||
|
" <td>0.752487</td>\n",
|
||
|
" <td>0.091410</td>\n",
|
||
|
" <td>0.037652</td>\n",
|
||
|
" <td>0.046030</td>\n",
|
||
|
" <td>0.061286</td>\n",
|
||
|
" <td>0.079614</td>\n",
|
||
|
" <td>0.056463</td>\n",
|
||
|
" <td>0.095957</td>\n",
|
||
|
" <td>0.043178</td>\n",
|
||
|
" <td>0.198193</td>\n",
|
||
|
" <td>0.515501</td>\n",
|
||
|
" <td>0.437964</td>\n",
|
||
|
" <td>1.000000</td>\n",
|
||
|
" <td>0.033911</td>\n",
|
||
|
" <td>2.836513</td>\n",
|
||
|
" <td>0.991139</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>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>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.514355</td>\n",
|
||
|
" <td>1.216383</td>\n",
|
||
|
" <td>0.049735</td>\n",
|
||
|
" <td>0.022300</td>\n",
|
||
|
" <td>0.025782</td>\n",
|
||
|
" <td>0.033598</td>\n",
|
||
|
" <td>0.028219</td>\n",
|
||
|
" <td>0.021751</td>\n",
|
||
|
" <td>0.054383</td>\n",
|
||
|
" <td>0.021119</td>\n",
|
||
|
" <td>0.133978</td>\n",
|
||
|
" <td>0.507680</td>\n",
|
||
|
" <td>0.339343</td>\n",
|
||
|
" <td>0.986957</td>\n",
|
||
|
" <td>0.177489</td>\n",
|
||
|
" <td>5.088670</td>\n",
|
||
|
" <td>0.907676</td>\n",
|
||
|
" </tr>\n",
|
||
|
" <tr>\n",
|
||
|
" <th>0</th>\n",
|
||
|
" <td>Self_BaselineUI</td>\n",
|
||
|
" <td>0.967585</td>\n",
|
||
|
" <td>0.762740</td>\n",
|
||
|
" <td>0.000954</td>\n",
|
||
|
" <td>0.000170</td>\n",
|
||
|
" <td>0.000278</td>\n",
|
||
|
" <td>0.000463</td>\n",
|
||
|
" <td>0.000644</td>\n",
|
||
|
" <td>0.000189</td>\n",
|
||
|
" <td>0.000752</td>\n",
|
||
|
" <td>0.000168</td>\n",
|
||
|
" <td>0.001677</td>\n",
|
||
|
" <td>0.496424</td>\n",
|
||
|
" <td>0.009544</td>\n",
|
||
|
" <td>0.600530</td>\n",
|
||
|
" <td>0.005051</td>\n",
|
||
|
" <td>1.803126</td>\n",
|
||
|
" <td>0.996380</td>\n",
|
||
|
" </tr>\n",
|
||
|
" </tbody>\n",
|
||
|
"</table>\n",
|
||
|
"</div>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
" Model RMSE MAE precision recall \\\n",
|
||
|
"0 Ready_LightFMpureMF 7.953192 7.462008 0.334464 0.219997 \n",
|
||
|
"0 Ready_LightFM 162.707436 160.855483 0.340827 0.217682 \n",
|
||
|
"0 Ready_ImplicitALS 3.266101 3.065824 0.255037 0.188653 \n",
|
||
|
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 \n",
|
||
|
"0 Ready_LightFMcontent 182.471340 180.405210 0.160339 0.101224 \n",
|
||
|
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 \n",
|
||
|
"0 Self_GlobalAvg 1.125760 0.943534 0.061188 0.025968 \n",
|
||
|
"0 Ready_Random 1.514355 1.216383 0.049735 0.022300 \n",
|
||
|
"0 Self_BaselineUI 0.967585 0.762740 0.000954 0.000170 \n",
|
||
|
"\n",
|
||
|
" F_1 F_05 precision_super recall_super NDCG mAP \\\n",
|
||
|
"0 0.217225 0.254981 0.233798 0.266952 0.398778 0.263058 \n",
|
||
|
"0 0.217990 0.258010 0.243884 0.260663 0.403850 0.268266 \n",
|
||
|
"0 0.176852 0.201189 0.166631 0.214925 0.305908 0.172546 \n",
|
||
|
"0 0.118732 0.141584 0.130472 0.137473 0.214651 0.111707 \n",
|
||
|
"0 0.102198 0.121074 0.102682 0.112455 0.180079 0.087429 \n",
|
||
|
"0 0.046030 0.061286 0.079614 0.056463 0.095957 0.043178 \n",
|
||
|
"0 0.031383 0.041343 0.040558 0.032107 0.067695 0.027470 \n",
|
||
|
"0 0.025782 0.033598 0.028219 0.021751 0.054383 0.021119 \n",
|
||
|
"0 0.000278 0.000463 0.000644 0.000189 0.000752 0.000168 \n",
|
||
|
"\n",
|
||
|
" MRR LAUC HR Reco in test Test coverage Shannon \\\n",
|
||
|
"0 0.629129 0.607709 0.913043 1.000000 0.275613 5.085818 \n",
|
||
|
"0 0.637590 0.606568 0.898197 1.000000 0.351371 5.366291 \n",
|
||
|
"0 0.523871 0.591709 0.889714 1.000000 0.502886 5.722957 \n",
|
||
|
"0 0.400939 0.555546 0.765642 1.000000 0.038961 3.159079 \n",
|
||
|
"0 0.337825 0.547572 0.704136 0.974973 0.264791 4.909893 \n",
|
||
|
"0 0.198193 0.515501 0.437964 1.000000 0.033911 2.836513 \n",
|
||
|
"0 0.171187 0.509546 0.384942 1.000000 0.025974 2.711772 \n",
|
||
|
"0 0.133978 0.507680 0.339343 0.986957 0.177489 5.088670 \n",
|
||
|
"0 0.001677 0.496424 0.009544 0.600530 0.005051 1.803126 \n",
|
||
|
"\n",
|
||
|
" Gini \n",
|
||
|
"0 0.913665 \n",
|
||
|
"0 0.885046 \n",
|
||
|
"0 0.827507 \n",
|
||
|
"0 0.987317 \n",
|
||
|
"0 0.926201 \n",
|
||
|
"0 0.991139 \n",
|
||
|
"0 0.992003 \n",
|
||
|
"0 0.907676 \n",
|
||
|
"0 0.996380 "
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import evaluation_measures as 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",
|
||
|
"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
|
||
|
}
|