Closed mokarakaya closed 4 years ago
Correct, you can predict the next item to a session by calling predict_next_batch
multiple times feeding it the items in your session and the same user (or session) id. Keep in mind that this will be slow, because predictions for every item are computed in every step. predict_next_batch
was designed for evaluating the model (by using evaluate_sessions_batch
) and not for providing actual predictions (later it was superseded by symbolic_predict
(that is used by evaluate_gpu
) which is even harder to use for getting the actual predictions). The public version of this algorithm doesn't directly support inferring recommendations to individual sessions (because it is intended to be used for reproducing earlier results, or as a baseline for other session-based algorithms).
In the above code, the first and second parameters of predict_next_batch
should be numpy arrays and not lists. It might work with lists of only one ID, but its best to stick with numpy arrays here.
As for which one is better item-to-item or item-to-session recommendations: item-to-item recommendations are not personalized at all and can't differentiate between different intents. Session-based recommenders have some capacity to do and also have some notable practical advantages over fully personalized recommenders as well. So, I'd definitely go with predicting items to the session (in practical scenarios, you might want to limit the maximal length of your session to the last X items of the user).
thanks for the reply.
I have a session (
sequence
) of a user (user_id
)sequence
is a list of items([1, 2, 3]
) anduser_id
is an integerI'd like to predict the next item of the session by using the all items in the session so far. I don't want to use only the last item in the session.
If I understand correctly from the documentation, in order to predict the next item of the session so far, I need to call predict_next_batch subsequently with the items in the session and return the last prediction as below;
Is my understanding correct that the code below uses all the items in the sequence to produce final predictions?
Finally, which one do you think is better? Using all items in the session or only the last item of the session?
Thanks for sharing the code.