0

I want to get the most buying products of a user in the history. I'm currently using USER_PERSONALIZATION recipe, but GetRecommendations always returns wrong result. Please help.

This is my interaction data for the user id: f5504cb0-0f0e-11e9-b513-bb78938fd0f8, he/she purchased 10 times and he/she didn't not purchase the product with id 1A3DTA986EEBT

enter image description here

And this is my code and the result

enter image description here

enter image description here

As you see, the top product is not the product which he/she purchased. Thank for your help.

Dao Tam
  • 503
  • 1
  • 3
  • 13
  • Please clarify your question. Are you wanting to determine the most commonly purchased products for each user or the most commonly purchased products across all users (i.e. popularity)? Also, what do you mean by GetRecommendations always returns the wrong result? – James J Jan 09 '22 at 15:09
  • I want the most commonly purchased products of the user. Input of GetRecommendations is the user_id, and i want to get back the most commonly products which the user purchased in the history, i don't want to get information of other users. Thank for your help. – Dao Tam Jan 10 '22 at 01:20
  • Based on your updated question, you're not passing the filterArn in your getRecommendations call. Therefore, the filter is not being applied. See docs here: https://docs.aws.amazon.com/personalize/latest/dg/filter-real-time.html#filter-rt-sdk – James J Jan 12 '22 at 19:28
  • Just in the case that if the user purchased 100 products before, it will be bad to get 100 product ids and pass to the filter to get result. Is there any other way to do that? Thanks. – Dao Tam Jan 13 '22 at 01:01
  • You currently cannot filter on the itemId field in filters so passing purchased product IDs as a filter value will not work. However, you could create a solution with the personalized-ranking recipe and then pass purchased product IDs in the itemList to have them ranked for the user (using a filter is not necessary in this case). The GetPersonalizedRanking API has a limit of 500 items, though. See docs here: https://docs.aws.amazon.com/personalize/latest/dg/native-recipe-search.html – James J Jan 13 '22 at 12:46

1 Answers1

0

Amazon Personalize builds machine learning based recommenders based on your data. Therefore it's designed to predict what a user would be interested in now based on their past behavior (interactions) and the attributes of the items/products they've interacted with. Some considerations:

Data driven approach

Although you can import purchase history into Personalize, it's not designed as a datastore that you can query. If you simply want a list of the most commonly purchased products for a user, a database is likely a better tool to use. For example, to get the top 10 most purchased products for user someuser from a relational database where orders are stored in Order and OrderDetail tables, the SQL might look something like this:

SELECT od.ItemID, COUNT(*) AS PurchaseCount
FROM Order AS o, OrderDetail AS od
WHERE o.UserID = 'someuser'
AND o.OrderID = od.OrderID
GROUP BY ItemID
ORDER BY PurchaseCount DESC
LIMIT 10

Recommender driven approach

If you're use case is more like, "given a user's recent purchases, what would they likely be interested in purchasing again", Personalize can be used. Here are the general steps.

  • Create a Personalize custom dataset group.
  • Create an interactions dataset in the dataset group. Your interactions dataset schema should minimally have USER_ID, ITEM_ID, TIMESTAMP, and EVENT_TYPE.
  • Create a CSV containing purchase history for all users in the columns defined in the schema above. The product ID would be ITEM_ID, purchase date would be TIMESTAMP, and something like "Purchase" would be the EVENT_TYPE.
  • Create a solution using the aws-user-personalization recipe.
  • Create a solution version for the solution.
  • Create a Personalize campaign for the solution version.
  • Create a filter that only includes products that the user has recently purchased. For example, INCLUDE ItemID WHERE Interactions.EVENT_TYPE IN ("Purchase").
  • Call the GetRecommendations API for the campaign with the filter created above.

One important caveat is that when filtering on interactions history, Personalize currently only considers the most recent 200 historical interactions (in the bulk import) and most recent 100 for real-time events (sent in via the PutEvents API) for each user.

James J
  • 621
  • 3
  • 6
  • "given a user's recent purchases, what would they likely be interested in purchasing again" is exactly what i want. I did all steps like you mentions but the GetRecommendations top product result is not the product the user purchased in the history. – Dao Tam Jan 11 '22 at 02:18
  • I just tested the approach described above and it works as expected. Make sure you are specifying the filterArn for the filter when calling GetRecommendations. – James J Jan 11 '22 at 13:35
  • I updated my question with the result. Please help me. Thanks. – Dao Tam Jan 11 '22 at 14:32