recommenders-team/recommenders

[ASK] How to predict new user score?

Open

#2040 aperta il 20 nov 2023

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Python (2972 fork)batch import
help wanted

Metriche repository

Star
 (17.706 star)
Metriche merge PR
 (Merge medio 6g 16h) (10 PR mergiate in 30 g)

Descrizione

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

Guida contributor