recommenders-team / recommenders

Best Practices on Recommendation Systems
https://recommenders-team.github.io/recommenders/intro.html
MIT License
18.71k stars 3.06k forks source link

[ASK] How to predict new user score? #2040

Open rivercat0930 opened 9 months ago

rivercat0930 commented 9 months ago

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