Search code examples
amazon-web-servicesmachine-learningrecommendation-engineamazon-sagemaker

Amazon SageMaker factorisation machine rating matrix and endpoint


I am building a recommender system using sagemaker's built-in factorisation machine model.

My desired result is to have a rating matrix where I can look up a predicted score by a user id and an item id.

I understand that there is a predict API provided by the model:

result = fm_predictor.predict(X_test[1000:1010].toarray())

But I am not sure how I can use it to achieve the desired purpose. If I want to know, say, if user#123 is interested in movie#456, how can I use the above API?

Reference: https://medium.com/@julsimon/building-a-movie-recommender-with-factorization-machines-on-amazon-sagemaker-cedbfc8c93d8

https://www.slideshare.net/AmazonWebServices/building-a-recommender-system-on-aws-aws-summit-sydney-2018 (p.41,43)


Updated:

I think I understand how to use the API now, you have to build another one-hot encoded dataset as input, for example:

X_new = lil_matrix((1, nbFeatures)).astype('float32')
X_new[0, 935] = 1
X_new[0, 1600] = 1

prediction2 = X_new[0].toarray()
result2 = fm_predictor.predict(prediction2)

print(result2)

But it seems it would be quite inefficient to fill out the recommendation matrix this way. What would be the best practice?


Solution

  • I think one could think about 2 scenarios:

    1) if you need very low latency, you can fill up the matrix indeed, i.e. compute all recos for all users, and store it in a key/value backend queried by your app. You can definitely predict multiple users at a time, using the one-hot encoded technique above.

    2) predict on-demand by invoking the endpoint directly from the app. This is quite simpler, at the cost of a little latency.

    Hope this helps.