introduction_to_recommender.../P6. WRMF (Implicit ALS).ipynb

1712 lines
562 KiB
Plaintext
Raw Normal View History

2021-05-07 22:16:28 +02:00
{
"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": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:Intel MKL BLAS detected. Its highly recommend to set the environment variable 'export MKL_NUM_THREADS=1' to disable its internal multithreading\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6e84e82f11dc47abaf13854009e82657",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HTML(value=''), 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": 4,
"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": 5,
"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": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"943it [00:00, 10362.14it/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.266922</td>\n",
" <td>3.066824</td>\n",
" <td>0.25175</td>\n",
" <td>0.182636</td>\n",
" <td>0.173211</td>\n",
" <td>0.197806</td>\n",
" <td>0.160086</td>\n",
" <td>0.201137</td>\n",
" <td>0.299236</td>\n",
" <td>0.167611</td>\n",
" <td>0.513715</td>\n",
" <td>0.588679</td>\n",
" <td>0.878049</td>\n",
" <td>0.999894</td>\n",
" <td>0.504329</td>\n",
" <td>5.74491</td>\n",
" <td>0.82298</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" RMSE MAE precision recall F_1 F_05 \\\n",
"0 3.266922 3.066824 0.25175 0.182636 0.173211 0.197806 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.160086 0.201137 0.299236 0.167611 0.513715 0.588679 \n",
"\n",
" HR Reco in test Test coverage Shannon Gini \n",
"0 0.878049 0.999894 0.504329 5.74491 0.82298 "
]
},
"execution_count": 6,
"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": [
"### Hyperparameters tuning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Number of latent factors"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/15 [00:00<?, ?it/s]\n",
"943it [00:00, 11340.25it/s]\n",
" 7%|▋ | 1/15 [00:01<00:14, 1.04s/it]\n",
"943it [00:00, 10730.67it/s]\n",
" 13%|█▎ | 2/15 [00:02<00:13, 1.05s/it]\n",
"943it [00:00, 10477.79it/s]\n",
" 20%|██ | 3/15 [00:03<00:12, 1.05s/it]\n",
"943it [00:00, 10807.02it/s]\n",
" 27%|██▋ | 4/15 [00:04<00:11, 1.06s/it]\n",
"943it [00:00, 10688.45it/s]\n",
" 33%|███▎ | 5/15 [00:05<00:11, 1.11s/it]\n",
"943it [00:00, 10635.28it/s]\n",
" 40%|████ | 6/15 [00:06<00:10, 1.16s/it]\n",
"943it [00:00, 10505.79it/s]\n",
" 47%|████▋ | 7/15 [00:08<00:09, 1.21s/it]\n",
"943it [00:00, 10545.25it/s]\n",
" 53%|█████▎ | 8/15 [00:09<00:08, 1.25s/it]\n",
"943it [00:00, 9917.03it/s]\n",
" 60%|██████ | 9/15 [00:11<00:08, 1.37s/it]\n",
"943it [00:00, 10496.31it/s]\n",
" 67%|██████▋ | 10/15 [00:12<00:07, 1.45s/it]\n",
"943it [00:00, 10709.20it/s]\n",
" 73%|███████▎ | 11/15 [00:14<00:06, 1.52s/it]\n",
"943it [00:00, 9853.29it/s]\n",
" 80%|████████ | 12/15 [00:15<00:04, 1.54s/it]\n",
"943it [00:00, 10531.27it/s]\n",
" 87%|████████▋ | 13/15 [00:17<00:03, 1.61s/it]\n",
"943it [00:00, 10173.25it/s]\n",
" 93%|█████████▎| 14/15 [00:19<00:01, 1.68s/it]\n",
"943it [00:00, 10148.30it/s]\n",
"100%|██████████| 15/15 [00:21<00:00, 1.43s/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.845245</td>\n",
" <td>2.619957</td>\n",
" <td>0.105514</td>\n",
" <td>0.110613</td>\n",
" <td>0.092224</td>\n",
" <td>0.094515</td>\n",
" <td>0.062768</td>\n",
" <td>0.123849</td>\n",
" <td>0.121996</td>\n",
" <td>0.053640</td>\n",
" <td>0.219607</td>\n",
" <td>0.552021</td>\n",
" <td>0.621421</td>\n",
" <td>0.997455</td>\n",
" <td>0.727994</td>\n",
" <td>6.472770</td>\n",
" <td>0.642577</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>50</td>\n",
" <td>2.898919</td>\n",
" <td>2.677354</td>\n",
" <td>0.140933</td>\n",
" <td>0.137985</td>\n",
" <td>0.117747</td>\n",
" <td>0.123156</td>\n",
" <td>0.082511</td>\n",
" <td>0.145669</td>\n",
" <td>0.162052</td>\n",
" <td>0.073554</td>\n",
" <td>0.285402</td>\n",
" <td>0.565861</td>\n",
" <td>0.745493</td>\n",
" <td>0.999576</td>\n",
" <td>0.647186</td>\n",
" <td>6.259111</td>\n",
" <td>0.704468</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>75</td>\n",
" <td>2.943577</td>\n",
" <td>2.724779</td>\n",
" <td>0.171792</td>\n",
" <td>0.152722</td>\n",
" <td>0.135926</td>\n",
" <td>0.146013</td>\n",
" <td>0.104399</td>\n",
" <td>0.166191</td>\n",
" <td>0.199634</td>\n",
" <td>0.096243</td>\n",
" <td>0.354423</td>\n",
" <td>0.573366</td>\n",
" <td>0.798515</td>\n",
" <td>0.999788</td>\n",
" <td>0.607504</td>\n",
" <td>6.083777</td>\n",
" <td>0.751040</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>100</td>\n",
" <td>2.983831</td>\n",
" <td>2.766847</td>\n",
" <td>0.189926</td>\n",
" <td>0.165349</td>\n",
" <td>0.146647</td>\n",
" <td>0.158954</td>\n",
" <td>0.119313</td>\n",
" <td>0.182702</td>\n",
" <td>0.218971</td>\n",
" <td>0.107420</td>\n",
" <td>0.376826</td>\n",
" <td>0.579747</td>\n",
" <td>0.828208</td>\n",
" <td>0.999894</td>\n",
" <td>0.565657</td>\n",
" <td>5.898606</td>\n",
" <td>0.790453</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>125</td>\n",
" <td>3.014973</td>\n",
" <td>2.800528</td>\n",
" <td>0.199576</td>\n",
" <td>0.161300</td>\n",
" <td>0.148262</td>\n",
" <td>0.163874</td>\n",
" <td>0.128433</td>\n",
" <td>0.178498</td>\n",
" <td>0.232551</td>\n",
" <td>0.116528</td>\n",
" <td>0.413058</td>\n",
" <td>0.577770</td>\n",
" <td>0.854719</td>\n",
" <td>0.999894</td>\n",
" <td>0.518759</td>\n",
" <td>5.803240</td>\n",
" <td>0.814069</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>150</td>\n",
" <td>3.041675</td>\n",
" <td>2.829052</td>\n",
" <td>0.212619</td>\n",
" <td>0.164436</td>\n",
" <td>0.153355</td>\n",
" <td>0.171659</td>\n",
" <td>0.134979</td>\n",
" <td>0.185299</td>\n",
" <td>0.245491</td>\n",
" <td>0.124203</td>\n",
" <td>0.427261</td>\n",
" <td>0.579394</td>\n",
" <td>0.853659</td>\n",
" <td>0.999894</td>\n",
" <td>0.502165</td>\n",
" <td>5.744393</td>\n",
" <td>0.824284</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>175</td>\n",
" <td>3.067174</td>\n",
" <td>2.855569</td>\n",
" <td>0.214846</td>\n",
" <td>0.166922</td>\n",
" <td>0.154441</td>\n",
" <td>0.172930</td>\n",
" <td>0.139700</td>\n",
" <td>0.190809</td>\n",
" <td>0.248702</td>\n",
" <td>0.126277</td>\n",
" <td>0.436082</td>\n",
" <td>0.580625</td>\n",
" <td>0.864263</td>\n",
" <td>0.999894</td>\n",
" <td>0.492063</td>\n",
" <td>5.635818</td>\n",
" <td>0.839712</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>200</td>\n",
" <td>3.084254</td>\n",
" <td>2.874435</td>\n",
" <td>0.219512</td>\n",
" <td>0.166470</td>\n",
" <td>0.154820</td>\n",
" <td>0.174500</td>\n",
" <td>0.140021</td>\n",
" <td>0.186647</td>\n",
" <td>0.256716</td>\n",
" <td>0.135486</td>\n",
" <td>0.449810</td>\n",
" <td>0.580443</td>\n",
" <td>0.862142</td>\n",
" <td>0.999788</td>\n",
" <td>0.491342</td>\n",
" <td>5.626358</td>\n",
" <td>0.843260</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>225</td>\n",
" <td>3.098310</td>\n",
" <td>2.888885</td>\n",
" <td>0.221527</td>\n",
" <td>0.162908</td>\n",
" <td>0.153271</td>\n",
" <td>0.174652</td>\n",
" <td>0.143348</td>\n",
" <td>0.184742</td>\n",
" <td>0.254314</td>\n",
" <td>0.132189</td>\n",
" <td>0.436970</td>\n",
" <td>0.578659</td>\n",
" <td>0.851538</td>\n",
" <td>1.000000</td>\n",
" <td>0.484848</td>\n",
" <td>5.660195</td>\n",
" <td>0.839240</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>250</td>\n",
" <td>3.109233</td>\n",
" <td>2.900359</td>\n",
" <td>0.230011</td>\n",
" <td>0.170018</td>\n",
" <td>0.160018</td>\n",
" <td>0.181677</td>\n",
" <td>0.147210</td>\n",
" <td>0.187002</td>\n",
" <td>0.271292</td>\n",
" <td>0.145652</td>\n",
" <td>0.476179</td>\n",
" <td>0.582272</td>\n",
" <td>0.861082</td>\n",
" <td>1.000000</td>\n",
" <td>0.471861</td>\n",
" <td>5.598262</td>\n",
" <td>0.847443</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>275</td>\n",
" <td>3.123987</td>\n",
" <td>2.915849</td>\n",
" <td>0.223118</td>\n",
" <td>0.163987</td>\n",
" <td>0.155116</td>\n",
" <td>0.176334</td>\n",
" <td>0.141845</td>\n",
" <td>0.181169</td>\n",
" <td>0.259294</td>\n",
" <td>0.137734</td>\n",
" <td>0.445071</td>\n",
" <td>0.579225</td>\n",
" <td>0.851538</td>\n",
" <td>1.000000</td>\n",
" <td>0.479076</td>\n",
" <td>5.552331</td>\n",
" <td>0.852713</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>300</td>\n",
" <td>3.134676</td>\n",
" <td>2.927118</td>\n",
" <td>0.233510</td>\n",
" <td>0.171744</td>\n",
" <td>0.160625</td>\n",
" <td>0.183479</td>\n",
" <td>0.152039</td>\n",
" <td>0.192844</td>\n",
" <td>0.269165</td>\n",
" <td>0.143070</td>\n",
" <td>0.460571</td>\n",
" <td>0.583120</td>\n",
" <td>0.879109</td>\n",
" <td>0.999894</td>\n",
" <td>0.466811</td>\n",
" <td>5.571515</td>\n",
" <td>0.849595</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>325</td>\n",
" <td>3.142248</td>\n",
" <td>2.935562</td>\n",
" <td>0.235949</td>\n",
" <td>0.165707</td>\n",
" <td>0.160148</td>\n",
" <td>0.184367</td>\n",
" <td>0.154185</td>\n",
" <td>0.186690</td>\n",
" <td>0.274583</td>\n",
" <td>0.151069</td>\n",
" <td>0.465910</td>\n",
" <td>0.580147</td>\n",
" <td>0.841994</td>\n",
" <td>1.000000</td>\n",
" <td>0.463203</td>\n",
" <td>5.546160</td>\n",
" <td>0.853593</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>350</td>\n",
" <td>3.150288</td>\n",
" <td>2.944923</td>\n",
" <td>0.241676</td>\n",
" <td>0.173680</td>\n",
" <td>0.165615</td>\n",
" <td>0.189653</td>\n",
" <td>0.159549</td>\n",
" <td>0.191868</td>\n",
" <td>0.283226</td>\n",
" <td>0.154631</td>\n",
" <td>0.489850</td>\n",
" <td>0.584151</td>\n",
" <td>0.868505</td>\n",
" <td>1.000000</td>\n",
" <td>0.449495</td>\n",
" <td>5.486488</td>\n",
" <td>0.861326</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>375</td>\n",
" <td>3.155423</td>\n",
" <td>2.949564</td>\n",
" <td>0.242418</td>\n",
" <td>0.169734</td>\n",
" <td>0.164664</td>\n",
" <td>0.189489</td>\n",
" <td>0.163519</td>\n",
" <td>0.201145</td>\n",
" <td>0.275921</td>\n",
" <td>0.150416</td>\n",
" <td>0.459599</td>\n",
" <td>0.582149</td>\n",
" <td>0.847296</td>\n",
" <td>1.000000</td>\n",
" <td>0.443001</td>\n",
" <td>5.521482</td>\n",
" <td>0.858563</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Factors RMSE MAE precision recall F_1 F_05 \\\n",
"0 25 2.845245 2.619957 0.105514 0.110613 0.092224 0.094515 \n",
"0 50 2.898919 2.677354 0.140933 0.137985 0.117747 0.123156 \n",
"0 75 2.943577 2.724779 0.171792 0.152722 0.135926 0.146013 \n",
"0 100 2.983831 2.766847 0.189926 0.165349 0.146647 0.158954 \n",
"0 125 3.014973 2.800528 0.199576 0.161300 0.148262 0.163874 \n",
"0 150 3.041675 2.829052 0.212619 0.164436 0.153355 0.171659 \n",
"0 175 3.067174 2.855569 0.214846 0.166922 0.154441 0.172930 \n",
"0 200 3.084254 2.874435 0.219512 0.166470 0.154820 0.174500 \n",
"0 225 3.098310 2.888885 0.221527 0.162908 0.153271 0.174652 \n",
"0 250 3.109233 2.900359 0.230011 0.170018 0.160018 0.181677 \n",
"0 275 3.123987 2.915849 0.223118 0.163987 0.155116 0.176334 \n",
"0 300 3.134676 2.927118 0.233510 0.171744 0.160625 0.183479 \n",
"0 325 3.142248 2.935562 0.235949 0.165707 0.160148 0.184367 \n",
"0 350 3.150288 2.944923 0.241676 0.173680 0.165615 0.189653 \n",
"0 375 3.155423 2.949564 0.242418 0.169734 0.164664 0.189489 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.062768 0.123849 0.121996 0.053640 0.219607 0.552021 \n",
"0 0.082511 0.145669 0.162052 0.073554 0.285402 0.565861 \n",
"0 0.104399 0.166191 0.199634 0.096243 0.354423 0.573366 \n",
"0 0.119313 0.182702 0.218971 0.107420 0.376826 0.579747 \n",
"0 0.128433 0.178498 0.232551 0.116528 0.413058 0.577770 \n",
"0 0.134979 0.185299 0.245491 0.124203 0.427261 0.579394 \n",
"0 0.139700 0.190809 0.248702 0.126277 0.436082 0.580625 \n",
"0 0.140021 0.186647 0.256716 0.135486 0.449810 0.580443 \n",
"0 0.143348 0.184742 0.254314 0.132189 0.436970 0.578659 \n",
"0 0.147210 0.187002 0.271292 0.145652 0.476179 0.582272 \n",
"0 0.141845 0.181169 0.259294 0.137734 0.445071 0.579225 \n",
"0 0.152039 0.192844 0.269165 0.143070 0.460571 0.583120 \n",
"0 0.154185 0.186690 0.274583 0.151069 0.465910 0.580147 \n",
"0 0.159549 0.191868 0.283226 0.154631 0.489850 0.584151 \n",
"0 0.163519 0.201145 0.275921 0.150416 0.459599 0.582149 \n",
"\n",
" HR Reco in test Test coverage Shannon Gini \n",
"0 0.621421 0.997455 0.727994 6.472770 0.642577 \n",
"0 0.745493 0.999576 0.647186 6.259111 0.704468 \n",
"0 0.798515 0.999788 0.607504 6.083777 0.751040 \n",
"0 0.828208 0.999894 0.565657 5.898606 0.790453 \n",
"0 0.854719 0.999894 0.518759 5.803240 0.814069 \n",
"0 0.853659 0.999894 0.502165 5.744393 0.824284 \n",
"0 0.864263 0.999894 0.492063 5.635818 0.839712 \n",
"0 0.862142 0.999788 0.491342 5.626358 0.843260 \n",
"0 0.851538 1.000000 0.484848 5.660195 0.839240 \n",
"0 0.861082 1.000000 0.471861 5.598262 0.847443 \n",
"0 0.851538 1.000000 0.479076 5.552331 0.852713 \n",
"0 0.879109 0.999894 0.466811 5.571515 0.849595 \n",
"0 0.841994 1.000000 0.463203 5.546160 0.853593 \n",
"0 0.868505 1.000000 0.449495 5.486488 0.861326 \n",
"0 0.847296 1.000000 0.443001 5.521482 0.858563 "
]
},
"execution_count": 7,
"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": 8,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "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uzJ/fsUtxUVEgmVmG4OOIVI0DotINIqlcRg0FotIdDqWsVhLMERERERERESkxikBISIiIiIiIiI1TgkIEREREREREalxUVkDojLFxcVkZGSwf//+oEOJuMTERDp27EhCQkLQoYhIDIuFcVjjrYhEu1gYi2uSxnmRYNWaBERGRgZJSUl07doVMws6nIhxd3JycsjIyKBbt25BhyMiMayuj8Mab0WkNqjrY3FN0jgvErxaswRj//79JCcnx9xAa2YkJycryy0igavr47DGWxGpDer6WFyTNM6LBK/WJCCAmB1oY/V9i0j0qevjUV1/fyJSN2isOnr67ESCVasSEEGLi4tj6NChDBw4kHPPPZe8vDwANmzYgJnxf//3f1/1zc7OJiEhgTvuuAOA1NRUTj75ZIYOHUq/fv245ZZbAJg+fTrNmjVj6NChX92mTZsW8fcmIlIbmBnXXHPNV49LSkpISUnhnHPO+Vq/888/n+OOO+5rx371q1/RoUOHr423B8ZxEREJzvz587nrrrsO2r5161YuueSSCEYkIjVFCYgj0LBhQxYvXszy5ctp2bIljz/++Fdt3bt355133vnq8euvv86AAQO+enzXXXfx/e9/n8WLF7Nq1SruvPPOr9rGjx/P4sWLv7qddtppkXlDIiK1TOPGjVm+fDn79u0D4KOPPqJDhw5f65OXl8fChQvJy8tj/fr1X2s7MA4fuDVv3jxSoYuIxIzS0tIj6j9y5EgeffTRg7a3b9+eyZMnH2tYIhIFlIA4Sscddxxbtmz56nHDhg3p168f8+fPB+DVV1/l29/+9lft27Zto2PHjl89HjRoUOSCFZFazcw6mdmnZrbKzFaY2d2V9GlhZlPNbKmZzTWzgeXaNpjZMjNbbGbzIxt99TvzzDP573//C8CkSZO44oorvtY+ZcoUzj33XC6//HJeeeWVIEIUEamzNmzYQN++fbnuuusYPHgwl1xyCXv37qVr16488MADnHDCCbz++ut8+OGHHHfccQwfPpxLL72U3bt3AzBv3jyOP/54hgwZwujRoykoKGD69OlfzWT77LPPvpqlNmzYMAoKCtiwYQMDB4b+W9u/fz/XX389gwYNYtiwYXz66acAPPfcc1x00UVMnDiRXr168eMf/ziYD0hEDqnW7IJR3q/fXsHKrfnV+pz92zfll+cOOHxHQlndjz/+mBtvvPFrxw9c7LZt25a4uDjat2/P1q1bgdC3bqeccgrHH388Z5xxBtdff/1X37zNmDGDoUOHfvU8U6ZMoUePHtXyvkSkTigB7nX3hWaWBCwws4/cfWW5Pj8FFrv7hWbWF3gcOLVc+wR3z66ugIIchy+//HIeeOABzjnnHJYuXcoNN9zAjBkzvmqfNGkSv/zlL2nTpg2XXHIJP/nJT75q+9vf/saLL74IQIsWLb66cBURqY2CGotTU1N55plnGDduHDfccAP/+Mc/gNAWlzNnziQ7O5uLLrqIadOm0bhxYx588EH++te/cv/993PZZZfx6quvMmrUKPLz82nYsOHXnvuhhx7i8ccfZ9y4cezevZvExMSvtR+Ygbxs2TJWr17NGWecwZo1awBYvHgxixYtokGDBvTp04c777yTTp06VddHIyLVQDMgjsC+ffsYOnQoycnJ5Obmcvrpp3+tfeLEiXz00UdMmjS
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"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": 9,
"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, 8224.09it/s]\u001b[A\n",
" 8%|▊ | 1/13 [00:02<00:31, 2.65s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 8183.27it/s]\u001b[A\n",
" 15%|█▌ | 2/13 [00:05<00:29, 2.69s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 8725.68it/s]\u001b[A\n",
" 23%|██▎ | 3/13 [00:08<00:27, 2.76s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 7268.33it/s]\u001b[A\n",
" 31%|███ | 4/13 [00:11<00:25, 2.80s/it]\n",
"943it [00:00, 10261.14it/s]\n",
" 38%|███▊ | 5/13 [00:13<00:20, 2.62s/it]\n",
"943it [00:00, 9896.61it/s]\n",
" 46%|████▌ | 6/13 [00:15<00:17, 2.49s/it]\n",
"943it [00:00, 10718.46it/s]\n",
" 54%|█████▍ | 7/13 [00:17<00:14, 2.42s/it]\n",
"943it [00:00, 10274.26it/s]\n",
" 62%|██████▏ | 8/13 [00:19<00:11, 2.29s/it]\n",
"943it [00:00, 9995.22it/s]\n",
" 69%|██████▉ | 9/13 [00:21<00:08, 2.22s/it]\n",
"943it [00:00, 9917.87it/s]\n",
" 77%|███████▋ | 10/13 [00:23<00:06, 2.16s/it]\n",
"0it [00:00, ?it/s]\u001b[A\n",
"943it [00:00, 8459.01it/s]\u001b[A\n",
" 85%|████████▍ | 11/13 [00:26<00:04, 2.18s/it]\n",
"943it [00:00, 9801.50it/s]\n",
" 92%|█████████▏| 12/13 [00:28<00:02, 2.16s/it]\n",
"943it [00:00, 10547.39it/s]\n",
"100%|██████████| 13/13 [00:30<00:00, 2.35s/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.667148</td>\n",
" <td>3.489102</td>\n",
" <td>0.097137</td>\n",
" <td>0.074715</td>\n",
" <td>0.068521</td>\n",
" <td>0.077218</td>\n",
" <td>0.054185</td>\n",
" <td>0.072066</td>\n",
" <td>0.118156</td>\n",
" <td>0.052060</td>\n",
" <td>0.265020</td>\n",
" <td>0.534088</td>\n",
" <td>0.591729</td>\n",
" <td>0.993107</td>\n",
" <td>0.735931</td>\n",
" <td>6.695607</td>\n",
" <td>0.541029</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3</td>\n",
" <td>3.626815</td>\n",
" <td>3.447637</td>\n",
" <td>0.146023</td>\n",
" <td>0.103810</td>\n",
" <td>0.098579</td>\n",
" <td>0.113005</td>\n",
" <td>0.086588</td>\n",
" <td>0.104527</td>\n",
" <td>0.177685</td>\n",
" <td>0.087408</td>\n",
" <td>0.359707</td>\n",
" <td>0.548837</td>\n",
" <td>0.705196</td>\n",
" <td>0.994592</td>\n",
" <td>0.711400</td>\n",
" <td>6.648019</td>\n",
" <td>0.563589</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>7</td>\n",
" <td>3.554143</td>\n",
" <td>3.373172</td>\n",
" <td>0.221633</td>\n",
" <td>0.147120</td>\n",
" <td>0.144749</td>\n",
" <td>0.169109</td>\n",
" <td>0.145172</td>\n",
" <td>0.166481</td>\n",
" <td>0.267707</td>\n",
" <td>0.148986</td>\n",
" <td>0.493567</td>\n",
" <td>0.570812</td>\n",
" <td>0.827147</td>\n",
" <td>0.996819</td>\n",
" <td>0.634921</td>\n",
" <td>6.311365</td>\n",
" <td>0.695948</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>10</td>\n",
" <td>3.508457</td>\n",
" <td>3.325837</td>\n",
" <td>0.251007</td>\n",
" <td>0.166736</td>\n",
" <td>0.164552</td>\n",
" <td>0.192116</td>\n",
" <td>0.165343</td>\n",
" <td>0.194423</td>\n",
" <td>0.303119</td>\n",
" <td>0.175620</td>\n",
" <td>0.534907</td>\n",
" <td>0.580745</td>\n",
" <td>0.851538</td>\n",
" <td>0.998197</td>\n",
" <td>0.593074</td>\n",
" <td>6.096903</td>\n",
" <td>0.751151</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>30</td>\n",
" <td>3.353356</td>\n",
" <td>3.161808</td>\n",
" <td>0.278685</td>\n",
" <td>0.193472</td>\n",
" <td>0.186691</td>\n",
" <td>0.215998</td>\n",
" <td>0.185944</td>\n",
" <td>0.222512</td>\n",
" <td>0.329472</td>\n",
" <td>0.193259</td>\n",
" <td>0.549576</td>\n",
" <td>0.594207</td>\n",
" <td>0.878049</td>\n",
" <td>0.999894</td>\n",
" <td>0.476912</td>\n",
" <td>5.592693</td>\n",
" <td>0.842470</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>50</td>\n",
" <td>3.275296</td>\n",
" <td>3.077720</td>\n",
" <td>0.257688</td>\n",
" <td>0.182688</td>\n",
" <td>0.174922</td>\n",
" <td>0.200926</td>\n",
" <td>0.168991</td>\n",
" <td>0.210621</td>\n",
" <td>0.305865</td>\n",
" <td>0.174495</td>\n",
" <td>0.517754</td>\n",
" <td>0.588738</td>\n",
" <td>0.874867</td>\n",
" <td>0.999894</td>\n",
" <td>0.467532</td>\n",
" <td>5.519136</td>\n",
" <td>0.854988</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>70</td>\n",
" <td>3.218980</td>\n",
" <td>3.017945</td>\n",
" <td>0.256734</td>\n",
" <td>0.186377</td>\n",
" <td>0.175456</td>\n",
" <td>0.200517</td>\n",
" <td>0.167382</td>\n",
" <td>0.210579</td>\n",
" <td>0.305096</td>\n",
" <td>0.172828</td>\n",
" <td>0.520099</td>\n",
" <td>0.590554</td>\n",
" <td>0.889714</td>\n",
" <td>0.999894</td>\n",
" <td>0.456710</td>\n",
" <td>5.470766</td>\n",
" <td>0.859839</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>90</td>\n",
" <td>3.176763</td>\n",
" <td>2.973046</td>\n",
" <td>0.244539</td>\n",
" <td>0.172512</td>\n",
" <td>0.166475</td>\n",
" <td>0.191058</td>\n",
" <td>0.159871</td>\n",
" <td>0.192965</td>\n",
" <td>0.287939</td>\n",
" <td>0.160423</td>\n",
" <td>0.493221</td>\n",
" <td>0.583590</td>\n",
" <td>0.866384</td>\n",
" <td>1.000000</td>\n",
" <td>0.448773</td>\n",
" <td>5.443263</td>\n",
" <td>0.865034</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>110</td>\n",
" <td>3.143349</td>\n",
" <td>2.936711</td>\n",
" <td>0.238070</td>\n",
" <td>0.171926</td>\n",
" <td>0.162405</td>\n",
" <td>0.186262</td>\n",
" <td>0.153541</td>\n",
" <td>0.187256</td>\n",
" <td>0.279234</td>\n",
" <td>0.151951</td>\n",
" <td>0.487754</td>\n",
" <td>0.583242</td>\n",
" <td>0.860021</td>\n",
" <td>0.999788</td>\n",
" <td>0.465368</td>\n",
" <td>5.469029</td>\n",
" <td>0.862758</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>130</td>\n",
" <td>3.110754</td>\n",
" <td>2.901935</td>\n",
" <td>0.234995</td>\n",
" <td>0.167103</td>\n",
" <td>0.160274</td>\n",
" <td>0.183921</td>\n",
" <td>0.150536</td>\n",
" <td>0.186330</td>\n",
" <td>0.272901</td>\n",
" <td>0.146686</td>\n",
" <td>0.472357</td>\n",
" <td>0.580823</td>\n",
" <td>0.853659</td>\n",
" <td>1.000000</td>\n",
" <td>0.457431</td>\n",
" <td>5.467972</td>\n",
" <td>0.863449</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>150</td>\n",
" <td>3.092232</td>\n",
" <td>2.881814</td>\n",
" <td>0.220573</td>\n",
" <td>0.156457</td>\n",
" <td>0.150352</td>\n",
" <td>0.172703</td>\n",
" <td>0.144421</td>\n",
" <td>0.184490</td>\n",
" <td>0.252383</td>\n",
" <td>0.133966</td>\n",
" <td>0.434369</td>\n",
" <td>0.575430</td>\n",
" <td>0.835631</td>\n",
" <td>1.000000</td>\n",
" <td>0.456710</td>\n",
" <td>5.478962</td>\n",
" <td>0.861605</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>170</td>\n",
" <td>3.070960</td>\n",
" <td>2.858602</td>\n",
" <td>0.215164</td>\n",
" <td>0.152678</td>\n",
" <td>0.145957</td>\n",
" <td>0.167671</td>\n",
" <td>0.135086</td>\n",
" <td>0.162270</td>\n",
" <td>0.251273</td>\n",
" <td>0.132605</td>\n",
" <td>0.444772</td>\n",
" <td>0.573533</td>\n",
" <td>0.829268</td>\n",
" <td>1.000000</td>\n",
" <td>0.455267</td>\n",
" <td>5.480218</td>\n",
" <td>0.863607</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>190</td>\n",
" <td>3.055291</td>\n",
" <td>2.841800</td>\n",
" <td>0.203818</td>\n",
" <td>0.145412</td>\n",
" <td>0.139214</td>\n",
" <td>0.159774</td>\n",
" <td>0.131760</td>\n",
" <td>0.164304</td>\n",
" <td>0.232864</td>\n",
" <td>0.118939</td>\n",
" <td>0.411554</td>\n",
" <td>0.569834</td>\n",
" <td>0.814422</td>\n",
" <td>0.999894</td>\n",
" <td>0.475469</td>\n",
" <td>5.516410</td>\n",
" <td>0.856805</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Alpha RMSE MAE precision recall F_1 F_05 \\\n",
"0 1 3.667148 3.489102 0.097137 0.074715 0.068521 0.077218 \n",
"0 3 3.626815 3.447637 0.146023 0.103810 0.098579 0.113005 \n",
"0 7 3.554143 3.373172 0.221633 0.147120 0.144749 0.169109 \n",
"0 10 3.508457 3.325837 0.251007 0.166736 0.164552 0.192116 \n",
"0 30 3.353356 3.161808 0.278685 0.193472 0.186691 0.215998 \n",
"0 50 3.275296 3.077720 0.257688 0.182688 0.174922 0.200926 \n",
"0 70 3.218980 3.017945 0.256734 0.186377 0.175456 0.200517 \n",
"0 90 3.176763 2.973046 0.244539 0.172512 0.166475 0.191058 \n",
"0 110 3.143349 2.936711 0.238070 0.171926 0.162405 0.186262 \n",
"0 130 3.110754 2.901935 0.234995 0.167103 0.160274 0.183921 \n",
"0 150 3.092232 2.881814 0.220573 0.156457 0.150352 0.172703 \n",
"0 170 3.070960 2.858602 0.215164 0.152678 0.145957 0.167671 \n",
"0 190 3.055291 2.841800 0.203818 0.145412 0.139214 0.159774 \n",
"\n",
" precision_super recall_super NDCG mAP MRR LAUC \\\n",
"0 0.054185 0.072066 0.118156 0.052060 0.265020 0.534088 \n",
"0 0.086588 0.104527 0.177685 0.087408 0.359707 0.548837 \n",
"0 0.145172 0.166481 0.267707 0.148986 0.493567 0.570812 \n",
"0 0.165343 0.194423 0.303119 0.175620 0.534907 0.580745 \n",
"0 0.185944 0.222512 0.329472 0.193259 0.549576 0.594207 \n",
"0 0.168991 0.210621 0.305865 0.174495 0.517754 0.588738 \n",
"0 0.167382 0.210579 0.305096 0.172828 0.520099 0.590554 \n",
"0 0.159871 0.192965 0.287939 0.160423 0.493221 0.583590 \n",
"0 0.153541 0.187256 0.279234 0.151951 0.487754 0.583242 \n",
"0 0.150536 0.186330 0.272901 0.146686 0.472357 0.580823 \n",
"0 0.144421 0.184490 0.252383 0.133966 0.434369 0.575430 \n",
"0 0.135086 0.162270 0.251273 0.132605 0.444772 0.573533 \n",
"0 0.131760 0.164304 0.232864 0.118939 0.411554 0.569834 \n",
"\n",
" HR Reco in test Test coverage Shannon Gini \n",
"0 0.591729 0.993107 0.735931 6.695607 0.541029 \n",
"0 0.705196 0.994592 0.711400 6.648019 0.563589 \n",
"0 0.827147 0.996819 0.634921 6.311365 0.695948 \n",
"0 0.851538 0.998197 0.593074 6.096903 0.751151 \n",
"0 0.878049 0.999894 0.476912 5.592693 0.842470 \n",
"0 0.874867 0.999894 0.467532 5.519136 0.854988 \n",
"0 0.889714 0.999894 0.456710 5.470766 0.859839 \n",
"0 0.866384 1.000000 0.448773 5.443263 0.865034 \n",
"0 0.860021 0.999788 0.465368 5.469029 0.862758 \n",
"0 0.853659 1.000000 0.457431 5.467972 0.863449 \n",
"0 0.835631 1.000000 0.456710 5.478962 0.861605 \n",
"0 0.829268 1.000000 0.455267 5.480218 0.863607 \n",
"0 0.814422 0.999894 0.475469 5.516410 0.856805 "
]
},
"execution_count": 9,
"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": 10,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"image/png": "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DoPGYhEJTjUZi4OyANG6dWumT6+6pbiIiLfMbI3XGQJF47CIBKNwGodBY7GIBKeajMVagiEiIiIiIiIidU4FCBERERERERGpcypAiIiIiIiIiEidC8oeECLivZKSEvLy8igsLPQ6SsDFxcWRlZVFdHS011FERKoV6mO0xmERqQ2hPlbWtboYi1WAEJFq5eXlkZiYSOvWrTEzr+MEjHOObdu2kZeXR5s2bbyO85PMLA6YCMTiG9NHO+fur3LOycB7wCr/oTHOuQcDGFNEalkoj9H1bRwWkeAVymNlXaursVhLMESkWoWFhaSkpITdYG1mpKSk1KdKeRFwqnOuJ5ADDDazftWcN8k5l+O/qPggUs+F8hhdD8dhEQlSoTxW1rW6Gos1A0JEDilcB+v69HM75xyw138z2n9x3iUSkUCpT2PV0Qrln01EAkvjybGri/dOMyBEJGhFRkaSk5NDt27dOO+889i5cycAq1evxsz4/e9/f+DcrVu3Eh0dzU033QTAkiVLOPnkk8nJyaFLly5ce+21AEyYMIHk5GRycnIOXD7//POA/2y1ycwizWw2sBkY75z7vprT+pvZHDP72My6BjahiIQiM+Pyyy8/cLu0tJS0tDTOPffcg84bOnQo/fv3P+jYH/7wBzIzMw8aiyvGeBERObzp06dzyy23HPL+9evXM3z48AAmOnIqQIhI0GrQoAGzZ89m/vz5NGnShKeffvrAfW3btuXDDz88cPvtt9+ma9cf/l99yy23cPvttzN79mwWLVrEzTfffOC+QYMGMXv27AOX008/PTA/UB1xzpU553KALKCvmXWrcspMoJV/mcaTwLvVPY+ZXWtm081s+pYtW+oysoiEgISEBObPn8/+/fsBGD9+PJmZmQeds3PnTmbOnMnOnTtZtWrVQfdVjNEVl0aNGgUquohIUCkrKzuq83Nzc3niiScOeX/z5s0ZPXp0TWPVCRUgRKRe6N+/P/n5+QduN2jQgC5dujB9+nQA3nzzTS6++OID92/YsIGsrKwDt7t37x64sB5xzu0EJgCDqxzf7Zzb678+Dog2s9RqHv+Ccy7XOZeblpYWgMQiUt8NGTKEjz76CIBRo0Zx2WWXHXT/O++8w3nnncell17KG2+84UVEERFPrV69ms6dOzNy5Eh69OjB8OHDKSgooHXr1jz44IMMHDiQt99+m88++4z+/fvTu3dvRowYwd69vhW206ZN44QTTqBnz5707duXPXv2MGHChAOzzb7++usDM8l69erFnj17WL16Nd26+b6PKiws5Morr6R79+706tWLr776CoBXX32VCy+8kMGDB9OhQwf+3//7fwF5P9QDQkR+0gMfLGDh+t21+pzZzZO4/7wjWwlQVlbGF198wdVXX33Q8YoPtBkZGURGRtK8eXPWr18P+L5ZO/XUUznhhBM488wzufLKKw98uzZp0iRycnIOPM8777xDu3btauXnCjQzSwNKnHM7zawBcDrwUJVzMoBNzjlnZn3xFZ+3BT6tiNQFL8foSy+9lAcffJBzzz2XuXPnctVVVzFp0qQD948aNYr777+fpk2bMnz4cO65554D9z366KP897//BaBx48YHPhSLiNQFL8fKJUuW8PLLLzNgwACuuuoqnnnmGcC3zeXkyZPZunUrF154IZ9//jkJCQk89NB
"text/plain": [
"<Figure size 1296x3024 with 18 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"metrics=list(result.columns[[i not in ['Alpha'] for i in result.columns]])\n",
"\n",
"charts_per_row=6\n",
"charts_per_column=3\n",
"\n",
"fig, axes = plt.subplots(nrows=charts_per_row, ncols=charts_per_column,figsize=(18, 7*charts_per_row ))\n",
"import itertools\n",
"to_iter=[i for i in itertools.product(range(charts_per_row), range(charts_per_column))]\n",
"\n",
"for i in range(len(metrics)):\n",
" df=result[['Alpha', metrics[i]]]\n",
" df.plot(ax=axes[to_iter[i]], title=metrics[i], x=0, y=1)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"943it [00:00, 10250.34it/s]\n",
"943it [00:00, 10771.14it/s]\n",
"943it [00:00, 9255.61it/s]\n",
"943it [00:00, 10086.42it/s]\n",
"943it [00:00, 12019.93it/s]\n",
"943it [00:00, 11892.13it/s]\n",
"943it [00:00, 11185.60it/s]\n",
"943it [00:00, 11252.04it/s]\n",
"943it [00:00, 11415.63it/s]\n",
"943it [00:00, 10757.58it/s]\n",
"943it [00:00, 10367.98it/s]\n",
"943it [00:00, 10480.68it/s]\n",
"943it [00:00, 11926.02it/s]\n",
"943it [00:00, 9976.49it/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>Self_P3</td>\n",
" <td>3.702446</td>\n",
" <td>3.527273</td>\n",
" <td>0.282185</td>\n",
" <td>0.192092</td>\n",
" <td>0.186749</td>\n",
" <td>0.216980</td>\n",
" <td>0.204185</td>\n",
" <td>0.240096</td>\n",
" <td>0.339114</td>\n",
" <td>0.204905</td>\n",
" <td>0.572157</td>\n",
" <td>0.593544</td>\n",
" <td>0.875928</td>\n",
" <td>1.000000</td>\n",
" <td>0.077201</td>\n",
" <td>3.875892</td>\n",
" <td>0.974947</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Ready_ImplicitALS</td>\n",
" <td>3.266922</td>\n",
" <td>3.066824</td>\n",
" <td>0.251750</td>\n",
" <td>0.182636</td>\n",
" <td>0.173211</td>\n",
" <td>0.197806</td>\n",
" <td>0.160086</td>\n",
" <td>0.201137</td>\n",
" <td>0.299236</td>\n",
" <td>0.167611</td>\n",
" <td>0.513715</td>\n",
" <td>0.588679</td>\n",
" <td>0.878049</td>\n",
" <td>0.999894</td>\n",
" <td>0.504329</td>\n",
" <td>5.744910</td>\n",
" <td>0.822980</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_SVD</td>\n",
" <td>0.950347</td>\n",
" <td>0.749312</td>\n",
" <td>0.100636</td>\n",
" <td>0.050514</td>\n",
" <td>0.055794</td>\n",
" <td>0.070753</td>\n",
" <td>0.091202</td>\n",
" <td>0.082734</td>\n",
" <td>0.114054</td>\n",
" <td>0.053200</td>\n",
" <td>0.248803</td>\n",
" <td>0.521983</td>\n",
" <td>0.517497</td>\n",
" <td>0.992153</td>\n",
" <td>0.210678</td>\n",
" <td>4.418683</td>\n",
" <td>0.952848</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Self_SVD</td>\n",
" <td>0.914143</td>\n",
" <td>0.717131</td>\n",
" <td>0.101803</td>\n",
" <td>0.042134</td>\n",
" <td>0.051610</td>\n",
" <td>0.068543</td>\n",
" <td>0.091953</td>\n",
" <td>0.071255</td>\n",
" <td>0.104015</td>\n",
" <td>0.048817</td>\n",
" <td>0.193027</td>\n",
" <td>0.517784</td>\n",
" <td>0.471898</td>\n",
" <td>0.867232</td>\n",
" <td>0.147908</td>\n",
" <td>3.871296</td>\n",
" <td>0.971820</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>Ready_SVDBiased</td>\n",
" <td>0.939472</td>\n",
" <td>0.739816</td>\n",
" <td>0.085896</td>\n",
" <td>0.036073</td>\n",
" <td>0.043528</td>\n",
" <td>0.057643</td>\n",
" <td>0.077039</td>\n",
" <td>0.057463</td>\n",
" <td>0.097753</td>\n",
" <td>0.045546</td>\n",
" <td>0.219839</td>\n",
" <td>0.514709</td>\n",
" <td>0.431601</td>\n",
" <td>0.997455</td>\n",
" <td>0.168831</td>\n",
" <td>4.217578</td>\n",
" <td>0.962577</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Ready_Random</td>\n",
" <td>1.521845</td>\n",
" <td>1.225949</td>\n",
" <td>0.047190</td>\n",
" <td>0.020753</td>\n",
" <td>0.024810</td>\n",
" <td>0.032269</td>\n",
" <td>0.029506</td>\n",
" <td>0.023707</td>\n",
" <td>0.050075</td>\n",
" <td>0.018728</td>\n",
" <td>0.121957</td>\n",
" <td>0.506893</td>\n",
" <td>0.329799</td>\n",
" <td>0.986532</td>\n",
" <td>0.184704</td>\n",
" <td>5.099706</td>\n",
" <td>0.907217</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Ready_I-KNN</td>\n",
" <td>1.030386</td>\n",
" <td>0.813067</td>\n",
" <td>0.026087</td>\n",
" <td>0.006908</td>\n",
" <td>0.010593</td>\n",
" <td>0.016046</td>\n",
" <td>0.021137</td>\n",
" <td>0.009522</td>\n",
" <td>0.024214</td>\n",
" <td>0.008958</td>\n",
" <td>0.048068</td>\n",
" <td>0.499885</td>\n",
" <td>0.154825</td>\n",
" <td>0.402333</td>\n",
" <td>0.434343</td>\n",
" <td>5.133650</td>\n",
" <td>0.877999</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Ready_I-KNNBaseline</td>\n",
" <td>0.935327</td>\n",
" <td>0.737424</td>\n",
" <td>0.002545</td>\n",
" <td>0.000755</td>\n",
" <td>0.001105</td>\n",
" <td>0.001602</td>\n",
" <td>0.002253</td>\n",
" <td>0.000930</td>\n",
" <td>0.003444</td>\n",
" <td>0.001362</td>\n",
" <td>0.011760</td>\n",
" <td>0.496724</td>\n",
" <td>0.021209</td>\n",
" <td>0.482821</td>\n",
" <td>0.059885</td>\n",
" <td>2.232578</td>\n",
" <td>0.994487</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Ready_U-KNN</td>\n",
" <td>1.023495</td>\n",
" <td>0.807913</td>\n",
" <td>0.000742</td>\n",
" <td>0.000205</td>\n",
" <td>0.000305</td>\n",
" <td>0.000449</td>\n",
" <td>0.000536</td>\n",
" <td>0.000198</td>\n",
" <td>0.000845</td>\n",
" <td>0.000274</td>\n",
" <td>0.002744</td>\n",
" <td>0.496441</td>\n",
" <td>0.007423</td>\n",
" <td>0.602121</td>\n",
" <td>0.010823</td>\n",
" <td>2.089186</td>\n",
" <td>0.995706</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Self_TopRated</td>\n",
" <td>1.030712</td>\n",
" <td>0.820904</td>\n",
" <td>0.000954</td>\n",
" <td>0.000188</td>\n",
" <td>0.000298</td>\n",
" <td>0.000481</td>\n",
" <td>0.000644</td>\n",
" <td>0.000223</td>\n",
" <td>0.001043</td>\n",
" <td>0.000335</td>\n",
" <td>0.003348</td>\n",
" <td>0.496433</td>\n",
" <td>0.009544</td>\n",
" <td>0.699046</td>\n",
" <td>0.005051</td>\n",
" <td>1.945910</td>\n",
" <td>0.995669</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Self_BaselineUI</td>\n",
" <td>0.967585</td>\n",
" <td>0.762740</td>\n",
" <td>0.000954</td>\n",
" <td>0.000170</td>\n",
" <td>0.000278</td>\n",
" <td>0.000463</td>\n",
" <td>0.000644</td>\n",
" <td>0.000189</td>\n",
" <td>0.000752</td>\n",
" <td>0.000168</td>\n",
" <td>0.001677</td>\n",
" <td>0.496424</td>\n",
" <td>0.009544</td>\n",
" <td>0.600530</td>\n",
" <td>0.005051</td>\n",
" <td>1.803126</td>\n",
" <td>0.996380</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Self_IKNN</td>\n",
" <td>1.018363</td>\n",
" <td>0.808793</td>\n",
" <td>0.000318</td>\n",
" <td>0.000108</td>\n",
" <td>0.000140</td>\n",
" <td>0.000189</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000214</td>\n",
" <td>0.000037</td>\n",
" <td>0.000368</td>\n",
" <td>0.496391</td>\n",
" <td>0.003181</td>\n",
" <td>0.392153</td>\n",
" <td>0.115440</td>\n",
" <td>4.174741</td>\n",
" <td>0.965327</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Model RMSE MAE precision recall F_1 \\\n",
"0 Self_P3 3.702446 3.527273 0.282185 0.192092 0.186749 \n",
"0 Ready_ImplicitALS 3.266922 3.066824 0.251750 0.182636 0.173211 \n",
"0 Self_TopPop 2.508258 2.217909 0.188865 0.116919 0.118732 \n",
"0 Ready_SVD 0.950347 0.749312 0.100636 0.050514 0.055794 \n",
"0 Self_SVD 0.914143 0.717131 0.101803 0.042134 0.051610 \n",
"0 Ready_Baseline 0.949459 0.752487 0.091410 0.037652 0.046030 \n",
"0 Ready_SVDBiased 0.939472 0.739816 0.085896 0.036073 0.043528 \n",
"0 Ready_Random 1.521845 1.225949 0.047190 0.020753 0.024810 \n",
"0 Ready_I-KNN 1.030386 0.813067 0.026087 0.006908 0.010593 \n",
"0 Ready_I-KNNBaseline 0.935327 0.737424 0.002545 0.000755 0.001105 \n",
"0 Ready_U-KNN 1.023495 0.807913 0.000742 0.000205 0.000305 \n",
"0 Self_TopRated 1.030712 0.820904 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.216980 0.204185 0.240096 0.339114 0.204905 0.572157 \n",
"0 0.197806 0.160086 0.201137 0.299236 0.167611 0.513715 \n",
"0 0.141584 0.130472 0.137473 0.214651 0.111707 0.400939 \n",
"0 0.070753 0.091202 0.082734 0.114054 0.053200 0.248803 \n",
"0 0.068543 0.091953 0.071255 0.104015 0.048817 0.193027 \n",
"0 0.061286 0.079614 0.056463 0.095957 0.043178 0.198193 \n",
"0 0.057643 0.077039 0.057463 0.097753 0.045546 0.219839 \n",
"0 0.032269 0.029506 0.023707 0.050075 0.018728 0.121957 \n",
"0 0.016046 0.021137 0.009522 0.024214 0.008958 0.048068 \n",
"0 0.001602 0.002253 0.000930 0.003444 0.001362 0.011760 \n",
"0 0.000449 0.000536 0.000198 0.000845 0.000274 0.002744 \n",
"0 0.000481 0.000644 0.000223 0.001043 0.000335 0.003348 \n",
"0 0.000463 0.000644 0.000189 0.000752 0.000168 0.001677 \n",
"0 0.000189 0.000000 0.000000 0.000214 0.000037 0.000368 \n",
"\n",
" LAUC HR Reco in test Test coverage Shannon Gini \n",
"0 0.593544 0.875928 1.000000 0.077201 3.875892 0.974947 \n",
"0 0.588679 0.878049 0.999894 0.504329 5.744910 0.822980 \n",
"0 0.555546 0.765642 1.000000 0.038961 3.159079 0.987317 \n",
"0 0.521983 0.517497 0.992153 0.210678 4.418683 0.952848 \n",
"0 0.517784 0.471898 0.867232 0.147908 3.871296 0.971820 \n",
"0 0.515501 0.437964 1.000000 0.033911 2.836513 0.991139 \n",
"0 0.514709 0.431601 0.997455 0.168831 4.217578 0.962577 \n",
"0 0.506893 0.329799 0.986532 0.184704 5.099706 0.907217 \n",
"0 0.499885 0.154825 0.402333 0.434343 5.133650 0.877999 \n",
"0 0.496724 0.021209 0.482821 0.059885 2.232578 0.994487 \n",
"0 0.496441 0.007423 0.602121 0.010823 2.089186 0.995706 \n",
"0 0.496433 0.009544 0.699046 0.005051 1.945910 0.995669 \n",
"0 0.496424 0.009544 0.600530 0.005051 1.803126 0.996380 \n",
"0 0.496391 0.003181 0.392153 0.115440 4.174741 0.965327 "
]
},
"execution_count": 11,
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# project task 7: Check how number of iterations of WRMF model influence the evaluation metrics"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# we already checked how parameters alpha and factors influence the model performance\n",
"# your task is to do a similar thing with param iterations\n",
"\n",
"# expected output is a table reporting the evaluation metrics"
]
}
],
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}