This section describes how to generate recommendations for similar users.
For known users, the output includes a list of predicted users that have similar behavior and taste.
The predictions are expressed in cosine similarity, and range from 0, very dissimilar, to 1, very similar.
For a new user, there is no information to provide a prediction. This will produce an error.
Connect to your HeatWave DB System.
Complete the steps for training the recommendation model. See Section 3.11.2, “Training a Recommendation Model”.
To generate recommendations for similar users:
-
Use the
ML_MODEL_LOAD
routine to load the trained model with recommendations. For example:mysql> CALL sys.ML_MODEL_LOAD(@model, NULL);
-
Run the
ML_PREDICT_TABLE
orML_PREDICT_ROW
routine to generate predictions. You must set therecommend
option tousers_to_users
.The following example uses explicit feedback and runs the
ML_PREDICT_ROW
routine to predict the top three users similar to another user.mysql> SELECT sys.ML_PREDICT_ROW('{"user_id": "846"}', @model, JSON_OBJECT("recommend", "users_to_users", "topk", 3)); +--------------------------------------------------------------------------------------------------------------------------------+ | sys.ML_PREDICT_ROW('{"user_id": "846"}', @model, JSON_OBJECT("recommend", "users_to_users", "topk", 3)) | +--------------------------------------------------------------------------------------------------------------------------------+ | {"user_id": "846", "ml_results": "{"predictions": {"user_id": ["62", "643", "172"], "similarity": [0.7413, 0.7275, 0.6709]}}"} | +--------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.2373 sec)
User 846 is predicted to be most similar to users 62, 643, and 172.
For user 846, user 62 has similarity value of 0.7413, user 643 has a similarity value of 0.7275, and user 172 has a similarity value of 0.6709.
The following example uses implicit feedback and runs the
ML_PREDICT_TABLE
routine to predict the top three users similar to other users.mysql> CALL sys.ML_PREDICT_TABLE('mlcorpus.test_sample', @model, 'mlcorpus.users_to_users_recommendation', JSON_OBJECT("recommend", "users_to_users", "topk", 3)); Query OK, 0 rows affected (3.4959 sec) mysql> SELECT * FROM mlcorpus.users_to_users_recommendation LIMIT 3; +-------------------+---------+---------+--------+------------------------------------------------------------------------------------------------+ | _4aad19ca6e_pk_id | user_id | item_id | rating | ml_results | +-------------------+---------+---------+--------+------------------------------------------------------------------------------------------------+ | 1 | 1026 | 13763 | 1 | {"predictions": {"user_id": ["2215", "1992", "4590"], "similarity": [1.0, 1.0, 1.0]}} | | 2 | 992 | 16114 | 1 | {"predictions": {"user_id": ["2092", "1809", "5174"], "similarity": [0.8576, 0.8068, 0.7533]}} | | 3 | 1863 | 4527 | 1 | {"predictions": {"user_id": ["4895", "1405", "2972"], "similarity": [0.9845, 0.8666, 0.8623]}} | +-------------------+---------+---------+--------+------------------------------------------------------------------------------------------------+ 3 rows in set (0.0004 sec)
Users 2215, 1992, and 4590 are predicted to be most similar to user 1026.
Users 2092, 1809, and 5174 are predicted to be most similar to user 992.
Users 4895, 1405, and 2972 are predicted to be most similar to user 1863.
The similarity values for each item-item pair are in
ml_results
aftersimilarity
. For example, for user 1026, users 2215, 1992, and 4590 have a similarity value of 1.0.
The values in columns
item_id
andrating
can be disregarded as they are part of the data that was trained from the input table.