recommenders-team/recommenders

[ASK] How to predict new user score?

Open

#2,040 opened on Nov 20, 2023

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (2,972 forks)batch import
help wanted

Repository metrics

Stars
 (17,706 stars)
PR merge metrics
 (Avg merge 6d 16h) (10 merged PRs in 30d)

Description

Description

I already save the NeuMF model, then I want to use it, it can be load, but when I add new user in test.csv, it will get Exception has occurred: KeyError, 101.0, this 101.0 is the 101 user as the same I was add in test.csv Does this method is wrong to predict new user? and How to do it? Thank you everyone

code:

data = NCFDataset(
    train_file=train_file,
    test_file=leave_one_out_test_file,
    seed=SEED,
    overwrite_test_file_full=True,
    col_user="user_id",
    col_item="location_id",
    col_rating="score"
)

model = NCF(
    n_users=data.n_users,
    n_items=data.n_items,
    model_type="NeuMF",
    n_factors=3,
    layer_sizes=[64,32,16,8,4],
    n_epochs=50,
    batch_size=1024,
    learning_rate=0.001,
    verbose=10,
    seed=SEED
)
model.load(neumf_dir="./NeuMFmodel")
model.user2id=data.user2id
model.item2is=data.item2id
model.id2user=data.id2user
model.id2item=data.id2item

predictions = [[row.user_id, row.location_id, model.predict(row.user_id, row.location_id)]
                        for(_, row) in test.iterrows()]
predictions = pd.DataFrame(predictions, columns=['user_id', 'location_id', 'prediction'])
predictions.to_csv("./prediction.csv")

Other Comments

Contributor guide