You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
15 KiB
Plaintext
182 lines
15 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## User and product embeddings\n",
|
|
"\n",
|
|
"We calculate user and product embeddings based on the training set, and evaluate the results on the unseen test set. We will evaluate the results by plotting the user and product similarity versus the review score. The dataset is created in the [Obtain_dataset Notebook](Obtain_dataset.ipynb)."
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 1. Calculate user and product embeddings\n",
|
|
"\n",
|
|
"We calculate these embeddings simply by averaging all the reviews about the same product or written by the same user within the training set."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(24502, 19035)"
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"from ast import literal_eval\n",
|
|
"\n",
|
|
"df = pd.read_csv('output/embedded_babbage_similarity_50k.csv', index_col=0) # note that you will need to generate this file to run the code below\n",
|
|
"df['babbage_similarity'] = df.babbage_similarity.apply(literal_eval).apply(np.array)\n",
|
|
"X_train, X_test, y_train, y_test = train_test_split(df, df.Score, test_size = 0.2, random_state=42)\n",
|
|
"\n",
|
|
"user_embeddings = X_train.groupby('UserId').babbage_similarity.apply(np.mean)\n",
|
|
"prod_embeddings = X_train.groupby('ProductId').babbage_similarity.apply(np.mean)\n",
|
|
"len(user_embeddings), len(prod_embeddings)\n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We can see that most of the users and products appear within the 50k examples only once."
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 2. Evaluate the embeddings\n",
|
|
"\n",
|
|
"To evaluate the recommendations, we look at the similarity of the user and product embeddings amongst the reviews in the unseen test set. We calculate the cosine distance between the user and product embeddings, which gives us a similarity score between 0 and 1. We then normalize the scores to be evenly split between 0 and 1, by calculating the percentile of the similarity score amongst all predicted scores."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from openai.embeddings_utils import cosine_similarity\n",
|
|
"\n",
|
|
"# evaluate embeddings as recommendations on X_test\n",
|
|
"def evaluate_single_match(row):\n",
|
|
" user_id = row.UserId\n",
|
|
" product_id = row.ProductId\n",
|
|
" try:\n",
|
|
" user_embedding = user_embeddings[user_id]\n",
|
|
" product_embedding = prod_embeddings[product_id]\n",
|
|
" similarity = cosine_similarity(user_embedding, product_embedding)\n",
|
|
" return similarity\n",
|
|
" except Exception as e:\n",
|
|
" return np.nan\n",
|
|
"\n",
|
|
"X_test['cosine_similarity'] = X_test.apply(evaluate_single_match, axis=1)\n",
|
|
"X_test['percentile_cosine_similarity'] = X_test.cosine_similarity.rank(pct=True)\n"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### 2.1 Visualize cosine similarity by review score\n",
|
|
"\n",
|
|
"We group the cosine similarity scores by the review score, and plot the distribution of cosine similarity scores for each review score."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Correlation between user&vector similarity percentile metric and review number of stars (score): 22.11%\n"
|
|
]
|
|
},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Rdk9neMLbsAszKIOlE4KPAsRHxmqSDgfFNHG9sRPQXVqBZC3nEb6k6BHg2Il4DiIhnI+IpScdJ+kl+//17JR2Q35P/G/l91h+UNA9A0tmS1ki6G7gr/+Tmyvx5D0paVOYLNBuMR/yWqjuByyT9O/B94CayT3HfBPxJRNwn6Z3Aq8BSsjs0HyXpt8juvvi+/DjHAr8dEc9L+p9kty84J7/Nw72Svh8RL+/l12Y2JI/4LUn5PfZnA93AM2SB/0ng6Yi4L2+zPZ+++QBwQ77tl8AmYE/wfy8i9nynwynA8vwWzhVgH+DwvfF6zN4Kj/gtWRGxmyygK5J+DnzqbRymejQv4A8j4vECyjNrGY/4LUmSZkiaXrXpaLJvHDtE0nF5mwMkjQX+DfhYvu19ZKP4euF+B/Dn+V1OkXRM616B2dvnEb+lan/g6nwuvh/YQDbt8418+75k8/snA38H/H3+V0E/cHZ+JdDAY36O7JupHpE0BniS7Mohs7biu3OamSXGUz1mZolx8JuZJcbBb2aWGAe/mVliHPxmZolx8JuZJcbBb2aWGAe/mVli/j93vt+d34eekwAAAABJRU5ErkJggg==",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"needs_background": "light"
|
|
},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import statsmodels.api as sm\n",
|
|
"\n",
|
|
"\n",
|
|
"correlation = X_test[['percentile_cosine_similarity', 'Score']].corr().values[0,1]\n",
|
|
"print('Correlation between user & vector similarity percentile metric and review number of stars (score): %.2f%%' % (100*correlation))\n",
|
|
"\n",
|
|
"# boxplot of cosine similarity for each score\n",
|
|
"X_test.boxplot(column='percentile_cosine_similarity', by='Score')\n",
|
|
"plt.title('')\n",
|
|
"plt.show()\n",
|
|
"plt.close()"
|
|
]
|
|
},
|
|
{
|
|
"attachments": {},
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We can observe a weak trend, showing that the higher the similarity score between the user and the product embedding, the higher the review score. Therefore, the user and product embeddings can weakly predict the review score - even before the user receives the product!\n",
|
|
"\n",
|
|
"Because this signal works in a different way than the more commonly used collaborative filtering, it can act as an additional feature to slightly improve the performance on existing problems."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"interpreter": {
|
|
"hash": "be4b5d5b73a21c599de40d6deb1129796d12dc1cc33a738f7bac13269cfcafe8"
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3.7.3 64-bit ('base': conda)",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.7.3"
|
|
},
|
|
"orig_nbformat": 4
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|