pythondata-sciencerecommendation-enginelightfm

predict new user using lightfm


I want to give a recommendation to a new user using lightfm.

Hi, I've got model, interactions, item_features. The new user is not in interactions and the only information of the new user is their ratings.(list of book_id and rating pairs)

I tried to use predict() or predict_rank(), but I failed to figure out how. Could you please give me some advice?

Below is my screenshot which raised ValueError..


Solution

  • I was having the same problem, What I did was

    1. Created a user_features matrix (based on their preferences) using Dataset class

       dataset = Dataset()
       dataset.fit(user_ids,item_ids)
       user_features = build_user_features([[user_id_1,[user_features_1]],..], normalize=True)
      
    2. Provide it during training along with interaction CSR

      model = LightFM(loss='warp')
      model = model.fit(iteraction_csr,
                    user_features=user_features)
      
    3. Create user_feature matrix for new-user using their preference ( in my case genres )

      dataset.fit_partial(users=[user_id],user_features=total_genres)
      new_user_feature = [user_id,new_user_feature]
      new_user_feature = dataset.build_user_features([new_user_feature])
      
    4. Now predict item rankings with new_user feature

      scores = model.predict(<new-user-index>, np.arange(n_items),user_features=new_user_feature)
      

    This gives a pretty decent result for new users but is not as good as the pure CF model.

    This is how I implemented it.