Skip to content

Instantly share code, notes, and snippets.

@myui
Created December 2, 2024 08:01
Show Gist options
  • Save myui/9db40d5da1a0d0ff21c67c025fb8967a to your computer and use it in GitHub Desktop.
Save myui/9db40d5da1a0d0ff21c67c025fb8967a to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "27cddd06-2fc7-4a96-aa57-226109f57442",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"\n",
"sys.path.append(\"/home/td-user/rtrec\")"
]
},
{
"cell_type": "markdown",
"id": "07765c5e-6af2-47d7-8320-38dc269a7986",
"metadata": {},
"source": [
"# Movielens 1M"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "827b4cc7-1f28-4e44-91e9-6d5cd8cde4dc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using existing ratings.dat file.\n"
]
}
],
"source": [
"from rtrec.experiments.datasets import load_dataset\n",
"\n",
"df = load_dataset(name='movielens_1m')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c89ffe93-0b31-4cac-a004-8ada940add7b",
"metadata": {},
"outputs": [],
"source": [
"df['user'] = df['user'].astype(\"category\")\n",
"df['item'] = df['item'].astype(\"category\")\n",
"df['user_id'] = df['user'].cat.codes\n",
"df['item_id'] = df['item'].cat.codes"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "499497fa",
"metadata": {},
"outputs": [],
"source": [
"iid2id = dict(enumerate(df['item'].cat.categories))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "52bcecc2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user</th>\n",
" <th>item</th>\n",
" <th>rating</th>\n",
" <th>tstamp</th>\n",
" <th>user_id</th>\n",
" <th>item_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>1193</td>\n",
" <td>5</td>\n",
" <td>978300760</td>\n",
" <td>0</td>\n",
" <td>1104</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>661</td>\n",
" <td>3</td>\n",
" <td>978302109</td>\n",
" <td>0</td>\n",
" <td>639</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1</td>\n",
" <td>914</td>\n",
" <td>3</td>\n",
" <td>978301968</td>\n",
" <td>0</td>\n",
" <td>853</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1</td>\n",
" <td>3408</td>\n",
" <td>4</td>\n",
" <td>978300275</td>\n",
" <td>0</td>\n",
" <td>3177</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1</td>\n",
" <td>2355</td>\n",
" <td>5</td>\n",
" <td>978824291</td>\n",
" <td>0</td>\n",
" <td>2162</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000204</th>\n",
" <td>6040</td>\n",
" <td>1091</td>\n",
" <td>1</td>\n",
" <td>956716541</td>\n",
" <td>6039</td>\n",
" <td>1019</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000205</th>\n",
" <td>6040</td>\n",
" <td>1094</td>\n",
" <td>5</td>\n",
" <td>956704887</td>\n",
" <td>6039</td>\n",
" <td>1022</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000206</th>\n",
" <td>6040</td>\n",
" <td>562</td>\n",
" <td>5</td>\n",
" <td>956704746</td>\n",
" <td>6039</td>\n",
" <td>548</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000207</th>\n",
" <td>6040</td>\n",
" <td>1096</td>\n",
" <td>4</td>\n",
" <td>956715648</td>\n",
" <td>6039</td>\n",
" <td>1024</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000208</th>\n",
" <td>6040</td>\n",
" <td>1097</td>\n",
" <td>4</td>\n",
" <td>956715569</td>\n",
" <td>6039</td>\n",
" <td>1025</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000209 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" user item rating tstamp user_id item_id\n",
"0 1 1193 5 978300760 0 1104\n",
"1 1 661 3 978302109 0 639\n",
"2 1 914 3 978301968 0 853\n",
"3 1 3408 4 978300275 0 3177\n",
"4 1 2355 5 978824291 0 2162\n",
"... ... ... ... ... ... ...\n",
"1000204 6040 1091 1 956716541 6039 1019\n",
"1000205 6040 1094 5 956704887 6039 1022\n",
"1000206 6040 562 5 956704746 6039 548\n",
"1000207 6040 1096 4 956715648 6039 1024\n",
"1000208 6040 1097 4 956715569 6039 1025\n",
"\n",
"[1000209 rows x 6 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"id": "74f06c6c-535c-45bd-8fe0-d59f8d369656",
"metadata": {},
"source": [
"# Temporal User Split"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7b2e53b8-b1e8-4dc2-90c9-40b00d9f9826",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/td-user/rtrec/rtrec/experiments/split.py:104: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
" for user, user_df in df.groupby('user'):\n"
]
}
],
"source": [
"from rtrec.experiments.split import temporal_user_split\n",
"train_df, test_df = temporal_user_split(df)"
]
},
{
"cell_type": "markdown",
"id": "8213db54",
"metadata": {},
"source": [
"# Irspack evaluation"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "2023a533",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user</th>\n",
" <th>item</th>\n",
" <th>rating</th>\n",
" <th>tstamp</th>\n",
" <th>user_id</th>\n",
" <th>item_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>6040</td>\n",
" <td>858</td>\n",
" <td>4</td>\n",
" <td>956703932</td>\n",
" <td>6039</td>\n",
" <td>802</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>6040</td>\n",
" <td>593</td>\n",
" <td>5</td>\n",
" <td>956703954</td>\n",
" <td>6039</td>\n",
" <td>579</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6040</td>\n",
" <td>2384</td>\n",
" <td>4</td>\n",
" <td>956703954</td>\n",
" <td>6039</td>\n",
" <td>2191</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>6040</td>\n",
" <td>1961</td>\n",
" <td>4</td>\n",
" <td>956703977</td>\n",
" <td>6039</td>\n",
" <td>1781</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>6040</td>\n",
" <td>2019</td>\n",
" <td>5</td>\n",
" <td>956703977</td>\n",
" <td>6039</td>\n",
" <td>1839</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>797753</th>\n",
" <td>736</td>\n",
" <td>1278</td>\n",
" <td>4</td>\n",
" <td>1045711206</td>\n",
" <td>735</td>\n",
" <td>1186</td>\n",
" </tr>\n",
" <tr>\n",
" <th>797754</th>\n",
" <td>736</td>\n",
" <td>3671</td>\n",
" <td>4</td>\n",
" <td>1045711217</td>\n",
" <td>735</td>\n",
" <td>3429</td>\n",
" </tr>\n",
" <tr>\n",
" <th>797755</th>\n",
" <td>3840</td>\n",
" <td>1196</td>\n",
" <td>3</td>\n",
" <td>1046106127</td>\n",
" <td>3839</td>\n",
" <td>1106</td>\n",
" </tr>\n",
" <tr>\n",
" <th>797756</th>\n",
" <td>3840</td>\n",
" <td>1225</td>\n",
" <td>3</td>\n",
" <td>1046106162</td>\n",
" <td>3839</td>\n",
" <td>1135</td>\n",
" </tr>\n",
" <tr>\n",
" <th>797757</th>\n",
" <td>3840</td>\n",
" <td>2502</td>\n",
" <td>5</td>\n",
" <td>1046106198</td>\n",
" <td>3839</td>\n",
" <td>2308</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>797758 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" user item rating tstamp user_id item_id\n",
"0 6040 858 4 956703932 6039 802\n",
"1 6040 593 5 956703954 6039 579\n",
"2 6040 2384 4 956703954 6039 2191\n",
"3 6040 1961 4 956703977 6039 1781\n",
"4 6040 2019 5 956703977 6039 1839\n",
"... ... ... ... ... ... ...\n",
"797753 736 1278 4 1045711206 735 1186\n",
"797754 736 3671 4 1045711217 735 3429\n",
"797755 3840 1196 3 1046106127 3839 1106\n",
"797756 3840 1225 3 1046106162 3839 1135\n",
"797757 3840 2502 5 1046106198 3839 2308\n",
"\n",
"[797758 rows x 6 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_df"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e6cb85a0",
"metadata": {},
"outputs": [],
"source": [
"from irspack import df_to_sparse\n",
"\n",
"X_train, _, _ = df_to_sparse(\n",
" train_df, 'user_id', 'item_id'\n",
")\n",
"X_test, _, _ = df_to_sparse(\n",
" test_df, 'user_id', 'item_id'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "62bcdbe4",
"metadata": {},
"outputs": [],
"source": [
"import scipy.sparse as sp\n",
"X_train = sp.csr_matrix((train_df['rating'].astype(float), (train_df['user_id'], train_df['item_id'])))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "8f5430f3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(6040, 3706)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_train.shape"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5f6d1527",
"metadata": {},
"outputs": [],
"source": [
"import scipy.sparse as sp\n",
"X_test = sp.csr_matrix((test_df['rating'].astype(float), (test_df['user_id'], test_df['item_id'])))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d1a4ccc5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(6040, 3706)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_test.shape"
]
},
{
"cell_type": "markdown",
"id": "54d46d7b",
"metadata": {},
"source": [
"# SLIM"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "8167af99",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from irspack import rowwise_train_test_split, Evaluator\n",
"import scipy.sparse as sps\n",
"\n",
"# Split users into train and validation users.\n",
"X_train_user, X_valid_user = train_test_split(X_train, test_size=0.3, random_state=0)\n",
"\n",
"# Split the validation users' interaction into learning 50% and predcition 50%.\n",
"X_valid_learn, X_valid_predict = rowwise_train_test_split(\n",
" X_valid_user, test_ratio=.5, random_state=0\n",
")\n",
"\n",
"X_train_val_learn = sps.vstack([X_train_user, X_valid_learn])\n",
"evaluator = Evaluator(X_valid_predict, offset=X_train_user.shape[0], target_metric='ndcg', cutoff=20)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "14ad7ce1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[I 2024-12-02 07:59:04,272] A new study created in memory with name: no-name-029ae9d8-ebe5-4d5c-a685-81c6cc7abf5e\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:04,272]\u001b[0m \u001b[34mStart parameter search for SLIMRecommender\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:04,273]\u001b[0m \u001b[34mTrial 0:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:04,273]\u001b[0m \u001b[34mparameter = {'alpha': 0.014908048013494027, 'l1_ratio': 0.37738197725317135}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:05,751]\u001b[0m \u001b[34mConfig 0 obtained the following scores: {'appeared_item': 1506.0, 'entropy': 6.182864905677792, 'gini_index': 0.8938336079312945, 'hit': 0.9817880794701986, 'map': 0.11794014238746109, 'n_items': 3706.0, 'ndcg': 0.48922213262838643, 'precision': 0.43435430463576163, 'recall': 0.19621328779238129, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.478053 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:05,751] Trial 0 finished with value: -0.48922213262838643 and parameters: {'alpha': 0.014908048013494027, 'l1_ratio': 0.37738197725317135}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:05,752]\u001b[0m \u001b[34mTrial 1:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:05,752]\u001b[0m \u001b[34mparameter = {'alpha': 0.015640305603387635, 'l1_ratio': 0.7935706212888572}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:07,241]\u001b[0m \u001b[34mConfig 1 obtained the following scores: {'appeared_item': 1402.0, 'entropy': 6.161430302577109, 'gini_index': 0.8968125490672604, 'hit': 0.9834437086092715, 'map': 0.1174606428187973, 'n_items': 3706.0, 'ndcg': 0.4878229249819098, 'precision': 0.4324503311258278, 'recall': 0.19657139959869144, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.489512 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:07,242] Trial 1 finished with value: -0.4878229249819098 and parameters: {'alpha': 0.015640305603387635, 'l1_ratio': 0.7935706212888572}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:07,242]\u001b[0m \u001b[34mTrial 2:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:07,242]\u001b[0m \u001b[34mparameter = {'alpha': 0.0040618682521947405, 'l1_ratio': 0.07591575009465157}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:08,936]\u001b[0m \u001b[34mConfig 2 obtained the following scores: {'appeared_item': 1709.0, 'entropy': 6.230188136237217, 'gini_index': 0.8869623151526848, 'hit': 0.9746136865342163, 'map': 0.11493926280657187, 'n_items': 3706.0, 'ndcg': 0.48224755153924387, 'precision': 0.42886313465783665, 'recall': 0.1918326753162034, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.693991 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:08,937] Trial 2 finished with value: -0.48224755153924387 and parameters: {'alpha': 0.0040618682521947405, 'l1_ratio': 0.07591575009465157}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:08,937]\u001b[0m \u001b[34mTrial 3:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:08,937]\u001b[0m \u001b[34mparameter = {'alpha': 1.8082171032910383e-05, 'l1_ratio': 0.7839694250992604}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:19,372]\u001b[0m \u001b[34mConfig 3 obtained the following scores: {'appeared_item': 1806.0, 'entropy': 6.259187132501386, 'gini_index': 0.8825181169132091, 'hit': 0.9729580573951435, 'map': 0.11242155789788592, 'n_items': 3706.0, 'ndcg': 0.47492013293109986, 'precision': 0.42163355408388525, 'recall': 0.18809047834128476, 'total_user': 1812.0, 'valid_user': 1812.0} within 10.435819 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:19,373] Trial 3 finished with value: -0.47492013293109986 and parameters: {'alpha': 1.8082171032910383e-05, 'l1_ratio': 0.7839694250992604}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:19,373]\u001b[0m \u001b[34mTrial 4:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:19,373]\u001b[0m \u001b[34mparameter = {'alpha': 0.3646974279987665, 'l1_ratio': 0.703090464103499}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:20,363]\u001b[0m \u001b[34mConfig 4 obtained the following scores: {'appeared_item': 656.0, 'entropy': 5.556977137664495, 'gini_index': 0.9471868153665257, 'hit': 0.9630242825607064, 'map': 0.09798853517019467, 'n_items': 3706.0, 'ndcg': 0.43864805458823347, 'precision': 0.38620309050772633, 'recall': 0.16791796051444036, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.989588 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:20,363] Trial 4 finished with value: -0.43864805458823347 and parameters: {'alpha': 0.3646974279987665, 'l1_ratio': 0.703090464103499}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:20,364]\u001b[0m \u001b[34mTrial 5:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:20,364]\u001b[0m \u001b[34mparameter = {'alpha': 0.0009198774630332172, 'l1_ratio': 0.14199752685871825}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:22,891]\u001b[0m \u001b[34mConfig 5 obtained the following scores: {'appeared_item': 1770.0, 'entropy': 6.2499846184089485, 'gini_index': 0.8840394253576028, 'hit': 0.9724061810154525, 'map': 0.11321952180871603, 'n_items': 3706.0, 'ndcg': 0.477609712339003, 'precision': 0.42419977924944813, 'recall': 0.18915576519657204, 'total_user': 1812.0, 'valid_user': 1812.0} within 2.527495 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:22,891] Trial 5 finished with value: -0.477609712339003 and parameters: {'alpha': 0.0009198774630332172, 'l1_ratio': 0.14199752685871825}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:22,892]\u001b[0m \u001b[34mTrial 6:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:22,892]\u001b[0m \u001b[34mparameter = {'alpha': 0.010015850232674673, 'l1_ratio': 0.16718179718227144}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:24,448]\u001b[0m \u001b[34mConfig 6 obtained the following scores: {'appeared_item': 1628.0, 'entropy': 6.209399972044884, 'gini_index': 0.8900074040187799, 'hit': 0.9790286975717439, 'map': 0.11680694706881142, 'n_items': 3706.0, 'ndcg': 0.48649061103737007, 'precision': 0.4318708609271524, 'recall': 0.1941339697144933, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.556476 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:24,449] Trial 6 finished with value: -0.48649061103737007 and parameters: {'alpha': 0.010015850232674673, 'l1_ratio': 0.16718179718227144}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:24,449]\u001b[0m \u001b[34mTrial 7:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:24,449]\u001b[0m \u001b[34mparameter = {'alpha': 0.00862119797356329, 'l1_ratio': 0.6338892611661847}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:25,949]\u001b[0m \u001b[34mConfig 7 obtained the following scores: {'appeared_item': 1549.0, 'entropy': 6.196470279509234, 'gini_index': 0.8920841627859601, 'hit': 0.9817880794701986, 'map': 0.11747572191629514, 'n_items': 3706.0, 'ndcg': 0.48827580321336855, 'precision': 0.4335540838852097, 'recall': 0.1955162594843245, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.500191 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:25,950] Trial 7 finished with value: -0.48827580321336855 and parameters: {'alpha': 0.00862119797356329, 'l1_ratio': 0.6338892611661847}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:25,950]\u001b[0m \u001b[34mTrial 8:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:25,950]\u001b[0m \u001b[34mparameter = {'alpha': 0.7181314549862668, 'l1_ratio': 0.8114450006177528}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:26,605]\u001b[0m \u001b[34mConfig 8 obtained the following scores: {'appeared_item': 417.0, 'entropy': 5.205191542110253, 'gini_index': 0.9634445335944695, 'hit': 0.9343267108167771, 'map': 0.08063500977105238, 'n_items': 3706.0, 'ndcg': 0.3905350902556412, 'precision': 0.3412527593818985, 'recall': 0.14232367607334084, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.655169 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:26,605] Trial 8 finished with value: -0.3905350902556412 and parameters: {'alpha': 0.7181314549862668, 'l1_ratio': 0.8114450006177528}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:26,606]\u001b[0m \u001b[34mTrial 9:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:26,606]\u001b[0m \u001b[34mparameter = {'alpha': 0.21758515156097707, 'l1_ratio': 0.33978421959176575}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:27,852]\u001b[0m \u001b[34mConfig 9 obtained the following scores: {'appeared_item': 992.0, 'entropy': 5.888268850916901, 'gini_index': 0.9243470703792788, 'hit': 0.977924944812362, 'map': 0.11357809432393243, 'n_items': 3706.0, 'ndcg': 0.4775268987257536, 'precision': 0.4227373068432671, 'recall': 0.19037541651163298, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.245961 seconds.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[I 2024-12-02 07:59:27,852] Trial 9 finished with value: -0.4775268987257536 and parameters: {'alpha': 0.21758515156097707, 'l1_ratio': 0.33978421959176575}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:27,856]\u001b[0m \u001b[34mTrial 10:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:27,856]\u001b[0m \u001b[34mparameter = {'alpha': 0.00029450736894697524, 'l1_ratio': 0.5014343649225794}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:33,484]\u001b[0m \u001b[34mConfig 10 obtained the following scores: {'appeared_item': 1800.0, 'entropy': 6.257252047168856, 'gini_index': 0.882912680230972, 'hit': 0.9707505518763797, 'map': 0.1128516932998326, 'n_items': 3706.0, 'ndcg': 0.476298126836487, 'precision': 0.4227649006622517, 'recall': 0.18864472978712638, 'total_user': 1812.0, 'valid_user': 1812.0} within 5.631913 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:33,485] Trial 10 finished with value: -0.476298126836487 and parameters: {'alpha': 0.00029450736894697524, 'l1_ratio': 0.5014343649225794}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:33,488]\u001b[0m \u001b[34mTrial 11:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:33,488]\u001b[0m \u001b[34mparameter = {'alpha': 0.050279066678650126, 'l1_ratio': 0.48006375420084835}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:34,873]\u001b[0m \u001b[34mConfig 11 obtained the following scores: {'appeared_item': 1238.0, 'entropy': 6.088514632559062, 'gini_index': 0.905435907882808, 'hit': 0.9806843267108167, 'map': 0.11739312567780257, 'n_items': 3706.0, 'ndcg': 0.48743966683440504, 'precision': 0.43253311258278154, 'recall': 0.19658650821723495, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.388179 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:34,874] Trial 11 finished with value: -0.48743966683440504 and parameters: {'alpha': 0.050279066678650126, 'l1_ratio': 0.48006375420084835}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:34,876]\u001b[0m \u001b[34mTrial 12:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:34,877]\u001b[0m \u001b[34mparameter = {'alpha': 0.000391106589441179, 'l1_ratio': 0.5783407725744621}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:39,755]\u001b[0m \u001b[34mConfig 12 obtained the following scores: {'appeared_item': 1801.0, 'entropy': 6.25798132823559, 'gini_index': 0.8828371509002167, 'hit': 0.9718543046357616, 'map': 0.11304656074429127, 'n_items': 3706.0, 'ndcg': 0.47704943408552003, 'precision': 0.4235099337748345, 'recall': 0.18883930371405974, 'total_user': 1812.0, 'valid_user': 1812.0} within 4.881639 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:39,756] Trial 12 finished with value: -0.47704943408552003 and parameters: {'alpha': 0.000391106589441179, 'l1_ratio': 0.5783407725744621}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:39,759]\u001b[0m \u001b[34mTrial 13:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:39,759]\u001b[0m \u001b[34mparameter = {'alpha': 0.05369005366490987, 'l1_ratio': 0.3465467779073997}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:41,186]\u001b[0m \u001b[34mConfig 13 obtained the following scores: {'appeared_item': 1264.0, 'entropy': 6.0962484448823036, 'gini_index': 0.9044551732230652, 'hit': 0.9817880794701986, 'map': 0.11817643692971473, 'n_items': 3706.0, 'ndcg': 0.4892053263131639, 'precision': 0.4339679911699778, 'recall': 0.1972204662206662, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.430239 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:41,187] Trial 13 finished with value: -0.4892053263131639 and parameters: {'alpha': 0.05369005366490987, 'l1_ratio': 0.3465467779073997}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:41,190]\u001b[0m \u001b[34mTrial 14:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:41,190]\u001b[0m \u001b[34mparameter = {'alpha': 0.05659776810462297, 'l1_ratio': 0.3764592257065008}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:42,568]\u001b[0m \u001b[34mConfig 14 obtained the following scores: {'appeared_item': 1246.0, 'entropy': 6.087762920972499, 'gini_index': 0.9054214929789888, 'hit': 0.9817880794701986, 'map': 0.11798645888172292, 'n_items': 3706.0, 'ndcg': 0.48886369690439013, 'precision': 0.4336368653421632, 'recall': 0.1969882631997034, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.380537 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:42,568] Trial 14 finished with value: -0.48886369690439013 and parameters: {'alpha': 0.05659776810462297, 'l1_ratio': 0.3764592257065008}. Best is trial 0 with value: -0.48922213262838643.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:42,571]\u001b[0m \u001b[34mTrial 15:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:42,571]\u001b[0m \u001b[34mparameter = {'alpha': 0.06822741795348723, 'l1_ratio': 0.2751064279730736}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:43,937]\u001b[0m \u001b[34mConfig 15 obtained the following scores: {'appeared_item': 1247.0, 'entropy': 6.081385497952282, 'gini_index': 0.9059891691654486, 'hit': 0.9817880794701986, 'map': 0.1184672399414291, 'n_items': 3706.0, 'ndcg': 0.4898517374986715, 'precision': 0.43451986754966887, 'recall': 0.19761598387005797, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.368065 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:43,937] Trial 15 finished with value: -0.4898517374986715 and parameters: {'alpha': 0.06822741795348723, 'l1_ratio': 0.2751064279730736}. Best is trial 15 with value: -0.4898517374986715.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:43,940]\u001b[0m \u001b[34mTrial 16:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:43,940]\u001b[0m \u001b[34mparameter = {'alpha': 0.0015262433896068405, 'l1_ratio': 0.2404952980647434}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:46,014]\u001b[0m \u001b[34mConfig 16 obtained the following scores: {'appeared_item': 1762.0, 'entropy': 6.250236141775245, 'gini_index': 0.8842053605572492, 'hit': 0.9740618101545254, 'map': 0.11388824041521078, 'n_items': 3706.0, 'ndcg': 0.47955874297078327, 'precision': 0.4262141280353201, 'recall': 0.19026682483328272, 'total_user': 1812.0, 'valid_user': 1812.0} within 2.076282 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:46,014] Trial 16 finished with value: -0.47955874297078327 and parameters: {'alpha': 0.0015262433896068405, 'l1_ratio': 0.2404952980647434}. Best is trial 15 with value: -0.4898517374986715.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:46,017]\u001b[0m \u001b[34mTrial 17:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:46,017]\u001b[0m \u001b[34mparameter = {'alpha': 0.1502179961709622, 'l1_ratio': 0.03343191271130608}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:47,385]\u001b[0m \u001b[34mConfig 17 obtained the following scores: {'appeared_item': 1234.0, 'entropy': 6.032895301721077, 'gini_index': 0.9103506752965479, 'hit': 0.9834437086092715, 'map': 0.12161861808621907, 'n_items': 3706.0, 'ndcg': 0.49682073068654276, 'precision': 0.44048013245033124, 'recall': 0.20124782978020314, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.370542 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:47,385] Trial 17 finished with value: -0.49682073068654276 and parameters: {'alpha': 0.1502179961709622, 'l1_ratio': 0.03343191271130608}. Best is trial 17 with value: -0.49682073068654276.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:47,388]\u001b[0m \u001b[34mTrial 18:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:47,389]\u001b[0m \u001b[34mparameter = {'alpha': 0.12140087798135006, 'l1_ratio': 0.005967535629752385}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:48,866]\u001b[0m \u001b[34mConfig 18 obtained the following scores: {'appeared_item': 1270.0, 'entropy': 6.04462726247312, 'gini_index': 0.9090799151545909, 'hit': 0.9834437086092715, 'map': 0.12131823407431895, 'n_items': 3706.0, 'ndcg': 0.4962694625959604, 'precision': 0.4402593818984548, 'recall': 0.20022884990569223, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.479832 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:48,866] Trial 18 finished with value: -0.4962694625959604 and parameters: {'alpha': 0.12140087798135006, 'l1_ratio': 0.005967535629752385}. Best is trial 17 with value: -0.49682073068654276.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:48,869]\u001b[0m \u001b[34mTrial 19:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:48,870]\u001b[0m \u001b[34mparameter = {'alpha': 0.9322484252213934, 'l1_ratio': 0.0028617786059698027}\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:50,065]\u001b[0m \u001b[34mConfig 19 obtained the following scores: {'appeared_item': 984.0, 'entropy': 5.768254384048738, 'gini_index': 0.932367624126022, 'hit': 0.9828918322295805, 'map': 0.12638901212695133, 'n_items': 3706.0, 'ndcg': 0.5061473525559695, 'precision': 0.44875827814569536, 'recall': 0.20768723533013395, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.198859 seconds.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[I 2024-12-02 07:59:50,066] Trial 19 finished with value: -0.5061473525559695 and parameters: {'alpha': 0.9322484252213934, 'l1_ratio': 0.0028617786059698027}. Best is trial 19 with value: -0.5061473525559695.\n"
]
}
],
"source": [
"from irspack import SLIMRecommender \n",
"\n",
"best_params, trial_dfs = SLIMRecommender.tune(X_train_val_learn, evaluator, n_trials=20)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "9262a1e9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'alpha': 0.9322484252213934, 'l1_ratio': 0.0028617786059698027}"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"best_params"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "877e52d1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<irspack.recommenders.slim.SLIMRecommender at 0xffff48fc4710>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#recommender = SLIMRecommender(X_train, alpha=0.01, l1_ratio=0.001)\n",
"recommender = SLIMRecommender(X_train)\n",
"recommender.learn()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d6229884",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([6038, 6033, 6034, ..., 5483, 735, 3839], dtype=int16)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"test_users = test_df['user_id'].unique()\n",
"test_users"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "dc7a1e7f",
"metadata": {},
"outputs": [],
"source": [
"scores = recommender.get_score(test_users)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "8e61024e",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"top_k=10\n",
"\n",
"recos = []\n",
"ground_truths = []\n",
"for row in test_df.groupby('user_id')['item'].apply(list).reset_index(name='ground_truth').itertuples():\n",
" user_scores = scores[row.user_id,:]\n",
" seen_items = X_train[row.user_id].indices\n",
" user_scores[seen_items] = -np.inf\n",
" top_items = np.argsort(user_scores)[-top_k:][::-1]\n",
" recos.append([iid2id[iid] for iid in top_items])\n",
" ground_truths.append(row.ground_truth)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "a9b3623c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'precision': 0.06569536423841121,\n",
" 'recall': 0.02407479482763474,\n",
" 'f1': 0.029115630810236683,\n",
" 'ndcg': 0.07058114063861932,\n",
" 'hit_rate': 0.34205298013245033,\n",
" 'mrr': 0.14960659098076348,\n",
" 'map': 0.03254130028728432,\n",
" 'tp': 3968,\n",
" 'auc': 0.18219713155681733}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from rtrec.utils.metrics import compute_scores\n",
"\n",
"compute_scores(zip(recos, ground_truths), recommend_size=10)"
]
},
{
"cell_type": "markdown",
"id": "6581c1af",
"metadata": {},
"source": [
"### NDCG is not good as SLIM elasticnet."
]
},
{
"cell_type": "markdown",
"id": "a50f17a9",
"metadata": {},
"source": [
"# iALS"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "f1ba8d5c",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[I 2024-12-02 07:59:53,047] A new study created in memory with name: no-name-92c92ff7-9d2f-448c-a122-0ed7c522f845\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,048]\u001b[0m \u001b[34mStart parameter search for IALSRecommender\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,049]\u001b[0m \u001b[34mTrial 0:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,049]\u001b[0m \u001b[34mparameter = {'n_components': 210, 'alpha0': 0.07509635107457344, 'reg': 0.0008692517903856388}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,737]\u001b[0m \u001b[34mConfig 0 obtained the following scores: {'appeared_item': 1835.0, 'entropy': 6.688537790154088, 'gini_index': 0.8327323450189359, 'hit': 0.9795805739514348, 'map': 0.09551246128931364, 'n_items': 3706.0, 'ndcg': 0.4020115835223948, 'precision': 0.35894039735099337, 'recall': 0.181559291232145, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.688614 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:53,738] Trial 0 finished with value: -0.4020115835223948 and parameters: {'n_components': 210, 'alpha0': 0.07509635107457344, 'reg': 0.0008692517903856388}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,738]\u001b[0m \u001b[34mTrial 1:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:53,738]\u001b[0m \u001b[34mparameter = {'n_components': 203, 'alpha0': 0.01094974773194795, 'reg': 0.0003068983624912621}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:01&lt;00:00 ndcg@20=0.3453319035864613]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,265]\u001b[0m \u001b[34mConfig 1 obtained the following scores: {'appeared_item': 1978.0, 'entropy': 6.780587663961535, 'gini_index': 0.8138268114828409, 'hit': 0.9757174392935982, 'map': 0.07628387234962332, 'n_items': 3706.0, 'ndcg': 0.3453319035864613, 'precision': 0.3141004415011037, 'recall': 0.16029053335318716, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.527348 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:55,266] Trial 1 finished with value: -0.3453319035864613 and parameters: {'n_components': 203, 'alpha0': 0.01094974773194795, 'reg': 0.0003068983624912621}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,266]\u001b[0m \u001b[34mTrial 2:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,266]\u001b[0m \u001b[34mparameter = {'n_components': 59, 'alpha0': 0.003752349438538049, 'reg': 0.0017460982133829055}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,497]\u001b[0m \u001b[34mConfig 2 obtained the following scores: {'appeared_item': 2623.0, 'entropy': 7.181818045107101, 'gini_index': 0.7112814045358103, 'hit': 0.9133554083885209, 'map': 0.039893149130262755, 'n_items': 3706.0, 'ndcg': 0.2274495633589433, 'precision': 0.21799116997792498, 'recall': 0.10838538785432784, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.231354 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:55,498] Trial 2 finished with value: -0.2274495633589433 and parameters: {'n_components': 59, 'alpha0': 0.003752349438538049, 'reg': 0.0017460982133829055}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,498]\u001b[0m \u001b[34mTrial 3:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,498]\u001b[0m \u001b[34mparameter = {'n_components': 67, 'alpha0': 0.0034957543212384428, 'reg': 0.0021468620298753342}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,761]\u001b[0m \u001b[34mConfig 3 obtained the following scores: {'appeared_item': 2591.0, 'entropy': 7.127866632942542, 'gini_index': 0.7219935395021974, 'hit': 0.9238410596026491, 'map': 0.041199605838165225, 'n_items': 3706.0, 'ndcg': 0.23065283722456315, 'precision': 0.22138520971302433, 'recall': 0.11149081702696353, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.263480 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:55,762] Trial 3 finished with value: -0.23065283722456315 and parameters: {'n_components': 67, 'alpha0': 0.0034957543212384428, 'reg': 0.0021468620298753342}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,762]\u001b[0m \u001b[34mTrial 4:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:55,762]\u001b[0m \u001b[34mparameter = {'n_components': 107, 'alpha0': 0.06583570165250556, 'reg': 0.0003092785904258536}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:00&lt;00:00 ndcg@20=0.3970191956106763]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:56,684]\u001b[0m \u001b[34mConfig 4 obtained the following scores: {'appeared_item': 1793.0, 'entropy': 6.585637352169558, 'gini_index': 0.8426126447298039, 'hit': 0.9845474613686535, 'map': 0.09673237342318411, 'n_items': 3706.0, 'ndcg': 0.39755387676322834, 'precision': 0.35733995584988953, 'recall': 0.1853015579247042, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.922008 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:56,685] Trial 4 finished with value: -0.39755387676322834 and parameters: {'n_components': 107, 'alpha0': 0.06583570165250556, 'reg': 0.0003092785904258536}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:56,685]\u001b[0m \u001b[34mTrial 5:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:56,685]\u001b[0m \u001b[34mparameter = {'n_components': 140, 'alpha0': 0.02934517363632851, 'reg': 0.00043176434704106213}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:00&lt;00:00 ndcg@20=0.37135988393954594]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:57,691]\u001b[0m \u001b[34mConfig 5 obtained the following scores: {'appeared_item': 1854.0, 'entropy': 6.639665929571466, 'gini_index': 0.8344299977722421, 'hit': 0.9762693156732892, 'map': 0.08870186925515838, 'n_items': 3706.0, 'ndcg': 0.37135988393954594, 'precision': 0.3342991169977924, 'recall': 0.17563137619369742, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.006153 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:57,691] Trial 5 finished with value: -0.37135988393954594 and parameters: {'n_components': 140, 'alpha0': 0.02934517363632851, 'reg': 0.00043176434704106213}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:57,692]\u001b[0m \u001b[34mTrial 6:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:57,692]\u001b[0m \u001b[34mparameter = {'n_components': 262, 'alpha0': 0.02337538085092951, 'reg': 0.0004606059424223731}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:02&lt;00:00 ndcg@20=0.3788358592468486]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:59,896]\u001b[0m \u001b[34mConfig 6 obtained the following scores: {'appeared_item': 1918.0, 'entropy': 6.774388168271995, 'gini_index': 0.8182000669518673, 'hit': 0.9795805739514348, 'map': 0.0863736726106061, 'n_items': 3706.0, 'ndcg': 0.37883585924684854, 'precision': 0.3380518763796909, 'recall': 0.1681910498012694, 'total_user': 1812.0, 'valid_user': 1812.0} within 2.203940 seconds.\u001b[0m\n",
"[I 2024-12-02 07:59:59,896] Trial 6 finished with value: -0.37883585924684854 and parameters: {'n_components': 262, 'alpha0': 0.02337538085092951, 'reg': 0.0004606059424223731}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:59,897]\u001b[0m \u001b[34mTrial 7:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 07:59:59,897]\u001b[0m \u001b[34mparameter = {'n_components': 269, 'alpha0': 0.0030911050525710454, 'reg': 0.001343665007301187}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:02&lt;00:00 ndcg@20=0.32187961183762176]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:02,178]\u001b[0m \u001b[34mConfig 7 obtained the following scores: {'appeared_item': 2245.0, 'entropy': 6.682051414198685, 'gini_index': 0.8151710161554141, 'hit': 0.9624724061810155, 'map': 0.06730390325056518, 'n_items': 3706.0, 'ndcg': 0.32187961183762176, 'precision': 0.2987030905077262, 'recall': 0.14819758251132564, 'total_user': 1812.0, 'valid_user': 1812.0} within 2.281503 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:02,178] Trial 7 finished with value: -0.32187961183762176 and parameters: {'n_components': 269, 'alpha0': 0.0030911050525710454, 'reg': 0.001343665007301187}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:02,179]\u001b[0m \u001b[34mTrial 8:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:02,179]\u001b[0m \u001b[34mparameter = {'n_components': 287, 'alpha0': 0.010909485238770123, 'reg': 0.00010489540797625005}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:02&lt;00:00 ndcg@20=0.32687722938353675]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:04,714]\u001b[0m \u001b[34mConfig 8 obtained the following scores: {'appeared_item': 2092.0, 'entropy': 6.971825961826902, 'gini_index': 0.7814253838117056, 'hit': 0.9486754966887417, 'map': 0.06658016625744441, 'n_items': 3706.0, 'ndcg': 0.32687722938353675, 'precision': 0.2981236203090508, 'recall': 0.1413343127860816, 'total_user': 1812.0, 'valid_user': 1812.0} within 2.535334 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:04,714] Trial 8 finished with value: -0.32687722938353675 and parameters: {'n_components': 287, 'alpha0': 0.010909485238770123, 'reg': 0.00010489540797625005}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:04,715]\u001b[0m \u001b[34mTrial 9:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:04,715]\u001b[0m \u001b[34mparameter = {'n_components': 70, 'alpha0': 0.014313044468363845, 'reg': 0.0010031549882416001}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,006]\u001b[0m \u001b[34mConfig 9 obtained the following scores: {'appeared_item': 2318.0, 'entropy': 6.996764635139591, 'gini_index': 0.7583924374172781, 'hit': 0.9624724061810155, 'map': 0.06072341965150753, 'n_items': 3706.0, 'ndcg': 0.29774053297006653, 'precision': 0.27869757174392934, 'recall': 0.14464046618927354, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.290934 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:05,006] Trial 9 finished with value: -0.29774053297006653 and parameters: {'n_components': 70, 'alpha0': 0.014313044468363845, 'reg': 0.0010031549882416001}. Best is trial 0 with value: -0.4020115835223948.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,010]\u001b[0m \u001b[34mTrial 10:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,010]\u001b[0m \u001b[34mparameter = {'n_components': 195, 'alpha0': 0.36169416662958737, 'reg': 0.011959971976019022}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,685]\u001b[0m \u001b[34mConfig 10 obtained the following scores: {'appeared_item': 1124.0, 'entropy': 6.123733707225009, 'gini_index': 0.9051887548263123, 'hit': 0.9884105960264901, 'map': 0.13972052349461, 'n_items': 3706.0, 'ndcg': 0.5256320787389526, 'precision': 0.46559050772626936, 'recall': 0.22493219212022944, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.679024 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:05,686] Trial 10 finished with value: -0.5256320787389526 and parameters: {'n_components': 195, 'alpha0': 0.36169416662958737, 'reg': 0.011959971976019022}. Best is trial 10 with value: -0.5256320787389526.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,690]\u001b[0m \u001b[34mTrial 11:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:05,690]\u001b[0m \u001b[34mparameter = {'n_components': 197, 'alpha0': 0.3617505537357373, 'reg': 0.01957682635069151}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:01&lt;00:00 ndcg@20=0.5293992234511299]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:07,167]\u001b[0m \u001b[34mConfig 11 obtained the following scores: {'appeared_item': 976.0, 'entropy': 5.828423054861862, 'gini_index': 0.9276884391280056, 'hit': 0.9867549668874173, 'map': 0.1407372730400925, 'n_items': 3706.0, 'ndcg': 0.52939922345113, 'precision': 0.468349889624724, 'recall': 0.22350245103385338, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.481448 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:07,168] Trial 11 finished with value: -0.52939922345113 and parameters: {'n_components': 197, 'alpha0': 0.3617505537357373, 'reg': 0.01957682635069151}. Best is trial 11 with value: -0.52939922345113.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:07,172]\u001b[0m \u001b[34mTrial 12:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:07,172]\u001b[0m \u001b[34mparameter = {'n_components': 198, 'alpha0': 0.5037444358742585, 'reg': 0.019129823851542417}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:01&lt;00:00 ndcg@20=0.5234309226314423]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:08,658]\u001b[0m \u001b[34mConfig 12 obtained the following scores: {'appeared_item': 836.0, 'entropy': 5.652929802467767, 'gini_index': 0.9396145829982762, 'hit': 0.9828918322295805, 'map': 0.13731392635742362, 'n_items': 3706.0, 'ndcg': 0.5234309226314423, 'precision': 0.46200331125827815, 'recall': 0.21820167602356047, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.489895 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:08,659] Trial 12 finished with value: -0.5234309226314423 and parameters: {'n_components': 198, 'alpha0': 0.5037444358742585, 'reg': 0.019129823851542417}. Best is trial 11 with value: -0.52939922345113.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:08,663]\u001b[0m \u001b[34mTrial 13:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:08,663]\u001b[0m \u001b[34mparameter = {'n_components': 156, 'alpha0': 0.6029613035555953, 'reg': 0.013366845684159679}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,413]\u001b[0m \u001b[34mConfig 13 obtained the following scores: {'appeared_item': 934.0, 'entropy': 5.855135374803448, 'gini_index': 0.9269460269070262, 'hit': 0.9856512141280354, 'map': 0.14131041454473353, 'n_items': 3706.0, 'ndcg': 0.5309357009017446, 'precision': 0.4704746136865342, 'recall': 0.22459150902380734, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.754405 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:09,414] Trial 13 finished with value: -0.5309357009017446 and parameters: {'n_components': 156, 'alpha0': 0.6029613035555953, 'reg': 0.013366845684159679}. Best is trial 13 with value: -0.5309357009017446.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,418]\u001b[0m \u001b[34mTrial 14:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,418]\u001b[0m \u001b[34mparameter = {'n_components': 14, 'alpha0': 0.23632602560448976, 'reg': 0.0624266260451173}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:00&lt;00:00 ndcg@20=0.44168616248971077]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,687]\u001b[0m \u001b[34mConfig 14 obtained the following scores: {'appeared_item': 519.0, 'entropy': 4.863843176190582, 'gini_index': 0.9726618817525188, 'hit': 0.967439293598234, 'map': 0.09946384542321929, 'n_items': 3706.0, 'ndcg': 0.44168616248971077, 'precision': 0.3875551876379691, 'recall': 0.17072871541204324, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.273168 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:09,688] Trial 14 finished with value: -0.44168616248971077 and parameters: {'n_components': 14, 'alpha0': 0.23632602560448976, 'reg': 0.0624266260451173}. Best is trial 13 with value: -0.5309357009017446.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,692]\u001b[0m \u001b[34mTrial 15:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:09,692]\u001b[0m \u001b[34mparameter = {'n_components': 150, 'alpha0': 0.990477767599734, 'reg': 0.00815943950986609}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:10,263]\u001b[0m \u001b[34mConfig 15 obtained the following scores: {'appeared_item': 919.0, 'entropy': 5.930582939663171, 'gini_index': 0.922553784865304, 'hit': 0.9845474613686535, 'map': 0.13976728000276248, 'n_items': 3706.0, 'ndcg': 0.528307488219615, 'precision': 0.4694260485651214, 'recall': 0.22419223096083, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.574929 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:10,263] Trial 15 finished with value: -0.528307488219615 and parameters: {'n_components': 150, 'alpha0': 0.990477767599734, 'reg': 0.00815943950986609}. Best is trial 13 with value: -0.5309357009017446.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:10,268]\u001b[0m \u001b[34mTrial 16:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:10,268]\u001b[0m \u001b[34mparameter = {'n_components': 234, 'alpha0': 0.12565880870680346, 'reg': 0.08801238051567212}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='16' class='' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [16/16 00:01&lt;00:00 ndcg@20=0.4256272766227759]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:12,139]\u001b[0m \u001b[34mConfig 16 obtained the following scores: {'appeared_item': 535.0, 'entropy': 4.834754456778872, 'gini_index': 0.9731404476244596, 'hit': 0.9668874172185431, 'map': 0.09288060168843314, 'n_items': 3706.0, 'ndcg': 0.4256272766227759, 'precision': 0.3744205298013245, 'recall': 0.16460275312959757, 'total_user': 1812.0, 'valid_user': 1812.0} within 1.875371 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:12,139] Trial 16 finished with value: -0.4256272766227759 and parameters: {'n_components': 234, 'alpha0': 0.12565880870680346, 'reg': 0.08801238051567212}. Best is trial 13 with value: -0.5309357009017446.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:12,144]\u001b[0m \u001b[34mTrial 17:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:12,144]\u001b[0m \u001b[34mparameter = {'n_components': 112, 'alpha0': 0.9611711231846549, 'reg': 0.029643074554602168}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[I 2024-12-02 08:00:12,255] Trial 17 pruned. \n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:12,260]\u001b[0m \u001b[34mTrial 18:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:12,260]\u001b[0m \u001b[34mparameter = {'n_components': 173, 'alpha0': 0.21910215079661377, 'reg': 0.007350777987244928}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:13,147]\u001b[0m \u001b[34mConfig 18 obtained the following scores: {'appeared_item': 1458.0, 'entropy': 6.443090573982583, 'gini_index': 0.8699657437554279, 'hit': 0.9845474613686535, 'map': 0.12088898390704118, 'n_items': 3706.0, 'ndcg': 0.4729247653541207, 'precision': 0.41757726269315676, 'recall': 0.2060070594774432, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.891730 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:13,148] Trial 18 finished with value: -0.4729247653541207 and parameters: {'n_components': 173, 'alpha0': 0.21910215079661377, 'reg': 0.007350777987244928}. Best is trial 13 with value: -0.5309357009017446.\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:13,152]\u001b[0m \u001b[34mTrial 19:\u001b[0m\n",
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:13,152]\u001b[0m \u001b[34mparameter = {'n_components': 239, 'alpha0': 0.5266530910535965, 'reg': 0.004757073505353605}\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='0' class='progress-bar-interrupted' max='16' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" Interrupted\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m[IRSPACK:I 2024-12-02 08:00:13,805]\u001b[0m \u001b[34mConfig 19 obtained the following scores: {'appeared_item': 1093.0, 'entropy': 6.193911113772355, 'gini_index': 0.8997721611276506, 'hit': 0.9823399558498896, 'map': 0.1266010957112155, 'n_items': 3706.0, 'ndcg': 0.4962741579343696, 'precision': 0.4385761589403973, 'recall': 0.20913611875325117, 'total_user': 1812.0, 'valid_user': 1812.0} within 0.656914 seconds.\u001b[0m\n",
"[I 2024-12-02 08:00:13,806] Trial 19 finished with value: -0.4962741579343696 and parameters: {'n_components': 239, 'alpha0': 0.5266530910535965, 'reg': 0.004757073505353605}. Best is trial 13 with value: -0.5309357009017446.\n"
]
}
],
"source": [
"from irspack import IALSRecommender \n",
"best_params, trial_dfs = IALSRecommender.tune(X_train_val_learn, evaluator, n_trials=20)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "2eb2c6be",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'n_components': 156,\n",
" 'alpha0': 0.6029613035555953,\n",
" 'reg': 0.013366845684159679,\n",
" 'train_epochs': 8}"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"best_params"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "35af627e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='8' class='' max='8' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.00% [8/8 00:00&lt;00:00]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<irspack.recommenders.ials.IALSRecommender at 0xffff4403ae10>"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"recommender = IALSRecommender(X_train, **best_params)\n",
"recommender.learn()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "e5859a73",
"metadata": {},
"outputs": [],
"source": [
"scores = recommender.get_score(test_users)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "79501b3c",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"top_k=10\n",
"\n",
"recos = []\n",
"ground_truths = []\n",
"for row in test_df.groupby('user_id')['item'].apply(list).reset_index(name='ground_truth').itertuples():\n",
" user_scores = scores[row.user_id,:]\n",
" seen_items = X_train[row.user_id].indices\n",
" user_scores[seen_items] = -np.inf\n",
" top_items = np.argsort(user_scores)[-top_k:][::-1]\n",
" recos.append([iid2id[iid] for iid in top_items])\n",
" ground_truths.append(row.ground_truth)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "69fdd84e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'precision': 0.06607615894039796,\n",
" 'recall': 0.02372569229115208,\n",
" 'f1': 0.028802112822632977,\n",
" 'ndcg': 0.07085222496797709,\n",
" 'hit_rate': 0.33973509933774837,\n",
" 'mrr': 0.14979810522442974,\n",
" 'map': 0.03296163643130784,\n",
" 'tp': 3991,\n",
" 'auc': 0.18196304399243124}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from rtrec.utils.metrics import compute_scores\n",
"\n",
"compute_scores(zip(recos, ground_truths), recommend_size=10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8119771",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment