user11619814
user11619814

Reputation: 439

How to build the dataset.build_item_features for LightFM recommendation model?

I am working on modeling a recommendation system using LightFM and trying to build the dataset on Steam data. My initial part of the code is as below:

 dataset = Dataset()
 dataset.fit(users = users_data['userID'], items = games_data['id'])
 num_users, num_items = dataset.interactions_shape()
 print('Num users: {}, num_items {}.'.format(num_users, num_items))

 fea_cols = [x for x in games_data.columns[15:24]]
 fea_cols  #these are my games feature cols:['app_name','price','early_access','release_year','release_month','genre_list','specs_list','total_positive_recommendation','total_negative_recommendation']
 dataset.fit_partial(items = games_data['id'],
                item_features = fea_cols)

 user_cols = [x for x in users_data[["items_count", "playtime_forever", "playtime_2weeks"]]]
 dataset.fit_partial(users = users_data['id'],
                user_features = user_cols)

 (interactions, weights) = dataset.build_interactions(((row['userID'], row['id'])
                                                  for id,row in   users_data.iterrows()))

 item_features = dataset.build_item_features(((row['id'], 
                                          [row['app_name'], row['early_access'], row['price'], 
                                           row["release_year"], row["release_month"],
                                           [row['genres'].split(',')],
                                           [row['specs'].split(',')]])
                                          for id,row in games_data.iterrows()))

When I run the dataset.builf_item_features I get the below error which says app_name is not fit into the dataset properly even though I called fit_partial on the feature before.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-54-591ba85acbe4> in <module>()
      4                                                [row['genres'].split(',')],
      5                                                [row['specs'].split(',')]])
----> 6                                               for id,row in  games_data.iterrows()))
      7 print(repr(item_features))

2 frames
/usr/local/lib/python3.7/dist-packages/lightfm/data.py in _process_features(self, datum)
    101                 raise ValueError(
    102                     "Feature {} not in feature mapping. "
--> 103                     "Call fit first.".format(feature)
    104                 )
    105 

ValueError: Feature Lost Summoner Kitty not in feature mapping. Call fit first.

Can anyone pls help me on this?

Upvotes: 2

Views: 1083

Answers (0)

Related Questions