Skip to content

How to predict in sequential models ? #172

@kshitijyad

Description

@kshitijyad

I am trying to predict the implicit sequential model.

data=[['useID','docid','timestamp']]

from sklearn import preprocessing
le_usr = preprocessing.LabelEncoder() # user encoder
le_itm = preprocessing.LabelEncoder() # item encoder

# shift item_ids with +1 (but not user_ids):
item_ids = (le_itm.fit_transform(data['docid'])+1).astype('int32')
user_ids = (le_usr.fit_transform(data['userID'])).astype('int32')


from spotlight.interactions import Interactions
implicit_interactions = Interactions(user_ids, item_ids, timestamps=data.timestamp)

from spotlight.cross_validation import user_based_train_test_split, random_train_test_split
train, test = user_based_train_test_split(implicit_interactions, 0.3)

Now I use the following code to train:

from spotlight.sequence.implicit import ImplicitSequenceModel

sequential_interaction = train.to_sequence()
implicit_sequence_model = ImplicitSequenceModel(use_cuda=False, n_iter=1, loss='bpr', representation='pooling')
implicit_sequence_model.fit(sequential_interaction, verbose=True)

But after this lets say i want to predict for "user_ids" (one hot encoded at the top) 1000, I dont know how to use the predict function.

As per my understanding, predict function should take the input of sequence for that user, but how to find out that sequence for that user?

sequential_interaction when used with .sequences() doesnt give me which row belongs to which user.

Can you please provide an example to use predict on this data ? Any example using implicit sequence model would be helpful.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions