-1

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..

Serious
  • 13
  • 3
  • Hello and welcome to StackOverflow. please take a moment and read this article https://stackoverflow.com/help/how-to-ask about how to asking questions also read this article https://stackoverflow.com/help/minimal-reproducible-example about how to ask a good question with minimum requirement. – nima Aug 20 '21 at 08:13
  • please share with us your workout, code snippets, error logs, or any useful information to help answer your question. – nima Aug 20 '21 at 08:13
  • @novonimo thansk I added screenshot but don't know how to put it into my post directly... – Serious Aug 20 '21 at 10:50
  • thank you for your responsibility. It's better to use plain text inside of the question instead of images. If you can, edit your post and remove screenshots and copy/paste your code/error logs here. good luck – nima Aug 20 '21 at 10:57

2 Answers2

4

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.

Shubham Gupta
  • 66
  • 1
  • 6
0

This worked for me. It explains the process of formatting new user features and generating predictions for them.

fit_partial can only be used if you want to resume model training from its current state when you have newer interaction data for existing users and items. When you have newer users/items, you should retrain the model.

The existing model can be used to generate predictions for newer users though, the link above explains the process.

Ad94
  • 1
  • 1