'How to write code for Cold Start scenarios with LightFM library

I don't know how to write code to manage cold start recommendation with LightFM library.

Introduction

Suppose to have the following datasets:

  • rating_dataset
userId movieId rating
1 1 4
1 3 4
2 318 3

etc...

  • movie_features
movieId genres
1 Adventure, Animation, Children, Comedy, Fantasy
2 Adventure, Children, Fantasy
3 Comedy, Romance

etc...

  • user_features
userId location age
1 new york 12
2 moscow 37
3 rio de janeiro 20

etc...

There are different scenarios where userId ad movieId may be:

  1. both present
  2. one new and the other already present (item or user cold start, the new one is not present in it's corresponding feature matrix)
  3. both new (item and user cold start, not present in both feature matrices too) N.B. New only ids are new, the features are a combination of those of the corresponding feature matrix.

e.g. of new row

new_id, new york (already present), 20 (already present)

For each combination I may have user_features and item_features or None.

Code

For case 1. I wrote the following code:


    already_known_user_ids = np.array([...])
    already_known_item_ids = np.array([...])

    #with features
    model.predict(already_known_user_ids, already_known_item_ids, item_features, user_features)

    #without features
    model.predict(already_known_user_ids, already_known_item_ids)

No problems with that, I think I wrote it correctly.

For cases 2. and 3. I can't use new ids directly in .predict() function because they aren't present during .fit() of the model. Furthermore, I can't add manually new ids to the corresponding feature matrix and use it in .predict() because I get the error ValueError: User id new_user_id not in user id mapping. Make sure you call the fit method.


    #not working code
    new_user = np.array([new_user_id])
    already_known_item_ids = np.array([...])
    #user_features doesn't contain new_user_id
    model.predict(new_user, already_known_item_ids, item_features, user_features)

Questions

  1. How have I to write code for cases 2. and 3.?
  2. What happens if new id has unique new feature? e.g. for user_features: new_user_id, new_city, 56 or for movie_features: new_movie_id, new_genre


Solution 1:[1]

Not a solution but a workaround: I encountered the very same error when removing Visual Studio 2019 to fully rely on Visual Studio 2022. Reinstalling a leight-weigth version of VS2019 to have access to its VSIXInstaller.exe worked for me.

enter image description here

Note: This seems not to happen on every machine. I tried same setup on a virtual machine and had no need for VS2019. So this might only occur on computers that had formerly an older version of Visual Studio installed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1