lyst / lyst/lightfm

Cold Star Problem New User

Open
#344 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
5.1k
Forks
724
PR merge metrics
No merged PRs in 30d

Description

I want to recommend items to user 4 with user feature ({"user_id":"4","user_city":"Z"}) who is not in training set. It's a cold star problem.
I have read similar question and answer but it is not clear as you said that set all ID 0s. which IDs ? and Where?
Please suggest what changes should i need to do in the given code and data

`import numpy as np
import json
from itertools import islice

news_features = [{"news_id":"1","car_model":"A"},
{"news_id":"2","car_model":"A"},
{"news_id":"3","car_model":"B"},
{"news_id":"4","car_model":"C"}]

user_features = [{"user_id":"1","user_city":"X"},
{"user_id":"2","user_city":"Y"},
{"user_id":"3","user_city":"Z"}]

ratings = [{"user_id":"1", "news_id":"1", "rating":"1"},
{"user_id":"1", "news_id":"2", "rating":"5"},
{"user_id":"1", "news_id":"3", "rating":"5"},
{"user_id":"1", "news_id":"4", "rating":"1"},
{"user_id":"2", "news_id":"3", "rating":"4"},
{"user_id":"2", "news_id":"1", "rating":"5"},
{"user_id":"3", "news_id":"1", "rating":"5"},
{"user_id":"3", "news_id":"3", "rating":"1"}]

from lightfm.data import Dataset
dataset = Dataset()

dataset.fit(users=(x['user_id'] for x in user_features),
items=(x['news_id'] for x in news_features),
item_features=(x['car_model'] for x in news_features),
user_features=(x['user_city'] for x in user_features))

num_users, num_items = dataset.interactions_shape()

(interactions, weights) = dataset.build_interactions(((x['user_id'], x['news_id'], int(x['rating']))
for x in ratings))

item_features = dataset.build_item_features(((x['news_id'], [x['car_model']])
for x in news_features))

user_features = dataset.build_user_features(((x['user_id'], [x['user_city']])
for x in user_features))

from lightfm import LightFM
model = LightFM(loss='warp')
model.fit(interactions, item_features=item_features, user_features=user_features, epochs=10, num_threads=4)

### Recommended items to user 3
user_features_test = dataset.build_user_features(((x['user_id'], [x['user_city']])
for x in [{"user_id":"3","user_city":"Z"}]))
scores = model.predict(2, np.arange(num_items), user_features=user_features_test)`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Dataset.fit, build_user_features, and model.predict calls shown in the issue, then compare how the training users and target user 4 are represented. Check the LightFM documentation and relevant examples for recommendations involving users absent from the training interactions. Done means the required data and code changes for this cold-start case are clearly identified and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.