[ASK] Wide and Deep Scoring params for All Items or From Unrated items
#1,874 opened on Jan 17, 2023
Repository metrics
- Stars
- (17,706 stars)
- PR merge metrics
- (Avg merge 6d 16h) (10 merged PRs in 30d)
Description
Description
How to use the ScoreWideAndDeepRecommenderModule() and related score_params to make prediction for "new" userIds?
- I've trained a Wide and Deep model from the Studio to make item recommendation first with "From rated items" for model training and evaluation (userId with features like gender, job, religion etc and items with features like some categories ids etc)
- I registered the model (also exported) and tested it with online endpoint on Container instance -> all good
Now I want to modify the score.py to predict items for "all users" or "new users" so I have the following doubts: I've configured now the score_param as follow:
`def run(data): data = json.loads(data) input_entry = defaultdict(list) for row in data: for key, val in row.items(): input_entry[key].append(decode_nan(val))
data_frame_directory = create_dfd_from_dict(input_entry, schema_data)
score_params = dict(
trained_wide_and_deep_recommendation_model=model,
dataset_to_score=data_frame_directory,
training_data=None,
user_features=None,
item_features=None,
recommender_prediction_kind='Item Recommendation',
recommended_item_selection='From All Items',
maximum_number_of_items_to_recommend_to_a_user=3)
result_dfd, = ScoreWideAndDeepRecommenderModule().run(**score_params)
result_df = result_dfd.data
return json.dumps(result_df.to_dict("list"))`
Then i modified the _schema.json used to test the endpoint to accept "userId" and 2 other user features
Deploying these settings in an online endpoint and testing it with the appropriate json I always get the same prediction results even if I vary the features passed in, for example:
userId = 99999 (new user, not part of trained model) gender = female job = employed
result predictions = item 1: 123 item 2: 334, item 3: 887
userId = 99998 (new user, not part of trained model) gender = male job = student
result predictions = item 1: 123 item 2: 334, item 3: 887
(in json format...)
Thanks to anyone helping clarifying AGA