mirror of
https://github.com/pinecone-io/examples.git
synced 2023-10-11 20:04:54 +03:00
other adjustments
This commit is contained in:
@@ -352,7 +352,7 @@
|
||||
"index_to_user = pd.Series(users)\n",
|
||||
"\n",
|
||||
"# create reverse mappings from user/item ID to index positions\n",
|
||||
"user_to_index = pd.Series(data=index_to_user.index + 1, index=index_to_user.values)\n",
|
||||
"user_to_index = pd.Series(data=index_to_user.index+1, index=index_to_user.values)\n",
|
||||
"\n",
|
||||
"# create zero-based index position <-> item/user ID mappings\n",
|
||||
"index_to_item = pd.Series(items)\n",
|
||||
@@ -365,10 +365,10 @@
|
||||
"users_cols = data.user_id.astype(int)\n",
|
||||
"\n",
|
||||
"# Create a sparse matrix for our users and products containing number of purchases\n",
|
||||
"sparse_product_user = sparse.csr_matrix((purchases, (products_rows, users_cols)), shape=(len(items) + 1, len(users) + 1))\n",
|
||||
"sparse_product_user = sparse.csr_matrix((purchases, (products_rows, users_cols)), shape=(len(items)+1, len(users)+1))\n",
|
||||
"sparse_product_user.data = np.nan_to_num(sparse_product_user.data, copy=False)\n",
|
||||
"\n",
|
||||
"sparse_user_product = sparse.csr_matrix((purchases, (users_cols, products_rows)), shape=(len(users) + 1, len(items) + 1))\n",
|
||||
"sparse_user_product = sparse.csr_matrix((purchases, (users_cols, products_rows)), shape=(len(users)+1, len(items)+1))\n",
|
||||
"sparse_user_product.data = np.nan_to_num(sparse_user_product.data, copy=False)"
|
||||
]
|
||||
},
|
||||
@@ -400,7 +400,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install --quiet -U implicit"
|
||||
"!pip install --quiet -U implicit==0.6.0"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1070,11 +1070,16 @@
|
||||
"# Get all of the items\n",
|
||||
"all_items = [title for title in products_lookup['product_name']]\n",
|
||||
"\n",
|
||||
"# clean non-ASCII characters from item names\n",
|
||||
"def remove_non_ascii(input_string):\n",
|
||||
" return ''.join(i for i in input_string if ord(i) < 128)\n",
|
||||
"all_items = [remove_non_ascii(title) for title in all_items]\n",
|
||||
"\n",
|
||||
"# Transform items into factors\n",
|
||||
"items_factors = model.item_factors\n",
|
||||
"\n",
|
||||
"# Prepare item factors for upload\n",
|
||||
"items_to_insert = list(zip(all_items, items_factors[1:].tolist()))\n",
|
||||
"items_to_insert = list(zip(all_items, items_factors[1:].to_numpy().tolist()))\n",
|
||||
"display(items_to_insert[:2])"
|
||||
]
|
||||
},
|
||||
@@ -1327,7 +1332,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"user_ids = [206210, 206211, 103593]\n",
|
||||
"user_ids = [49687, 49688, 25010]\n",
|
||||
"user_factors = model.user_factors[user_to_index[user_ids]]\n",
|
||||
"\n",
|
||||
"display(user_factors[1:])"
|
||||
@@ -1404,9 +1409,9 @@
|
||||
"print(\"Model recommendations\\n\")\n",
|
||||
"\n",
|
||||
"start_time = time.process_time()\n",
|
||||
"recommendations0 = model.recommend(userid=user_ids[0], user_items=sparse_user_product)\n",
|
||||
"recommendations1 = model.recommend(userid=user_ids[1], user_items=sparse_user_product)\n",
|
||||
"recommendations2 = model.recommend(userid=user_ids[2], user_items=sparse_user_product)\n",
|
||||
"recommendations0 = model.recommend(userid=user_ids[0], user_items=sparse_product_user[user_ids[0]])\n",
|
||||
"recommendations1 = model.recommend(userid=user_ids[1], user_items=sparse_product_user[user_ids[1]])\n",
|
||||
"recommendations2 = model.recommend(userid=user_ids[2], user_items=sparse_product_user[user_ids[2]])\n",
|
||||
"print(\"Time needed for retrieving recommended products: \" + str(time.process_time() - start_time) + ' seconds.\\n')\n",
|
||||
"\n",
|
||||
"print('\\nRecommendations for person 0:')\n",
|
||||
|
||||
Reference in New Issue
Block a user