test_data.build_negative_samples(data_info, item_gen_mode="random",
                                     seed=2222)

    # ========================== retrain begin =============================
    model = DeepFM("ranking", data_info, embed_size=16, n_epochs=2,
                   lr=1e-4, lr_decay=False, reg=None, batch_size=2048,
                   num_neg=1, use_bn=False, dropout_rate=None,
                   hidden_units="128,64,32", tf_sess_config=None)

    model.rebuild_graph(path="model_path", model_name="deepfm_model",
                        full_assign=True)

    model.fit(train_data, verbose=2, shuffle=True, eval_data=test_data,
              metrics=["loss", "balanced_accuracy", "roc_auc", "pr_auc",
                       "precision", "recall", "map", "ndcg"])

    print("prediction: ", model.predict(user=2211, item=110,
                                        feats={"sex": "mmm",
                                               "genre1": "crime"}))
    print("recommendation: ", model.recommend_user(
        user=2211, n_rec=7, inner_id=False, cold_start="average",
        user_feats=pd.Series({"sex": "F", "occupation": 2, "age": 23}),
        item_data=all_data.iloc[4:10]))

    eval_result = evaluate(model, test, eval_batch_size=8192, k=10,
                           metrics=["roc_auc", "pr_auc", "precision",
                                    "recall", "map", "ndcg"],
                           sample_user_num=2048, neg_sample=True,
                           update_features=False, seed=2222)
    print(eval_result)
Пример #2
0
                    reg=None,
                    batch_size=2048,
                    num_neg=1,
                    use_bn=False,
                    dropout_rate=None,
                    hidden_units="128,64,32",
                    tf_sess_config=None)
    deepfm.fit(train_data,
               verbose=2,
               shuffle=True,
               eval_data=eval_data,
               metrics=[
                   "loss", "balanced_accuracy", "roc_auc", "pr_auc",
                   "precision", "recall", "map", "ndcg"
               ])
    print("prediction: ", deepfm.predict(user=1, item=2333))
    print("recommendation: ", deepfm.recommend_user(user=1, n_rec=7))

    reset_state("AutoInt")
    autoint = AutoInt("ranking",
                      data_info,
                      embed_size=16,
                      n_epochs=2,
                      att_embed_size=(8, 8, 8),
                      num_heads=4,
                      use_residual=False,
                      lr=1e-3,
                      lr_decay=False,
                      reg=None,
                      batch_size=2048,
                      num_neg=1,
Пример #3
0
                    dropout_rate=None,
                    hidden_units="128,64,32",
                    tf_sess_config=None)
    deepfm.fit(train_data,
               verbose=2,
               shuffle=True,
               eval_data=test_data,
               metrics=[
                   "loss", "balanced_accuracy", "roc_auc", "pr_auc",
                   "precision", "recall", "map", "ndcg"
               ],
               eval_batch_size=8192,
               k=10,
               sample_user_num=2048)

    print("prediction: ", deepfm.predict(user=2211, item=110))
    print("recommendation: ", deepfm.recommend_user(user=2211, n_rec=7))

    # save data_info, specify model save folder
    data_info.save(path="model_path")
    # set manual=True will use numpy to save model
    # set manual=False will use tf.train.Saver to save model
    # set inference=True will only save the necessary variables for prediction and recommendation
    deepfm.save(path="model_path",
                model_name="deepfm_model",
                manual=True,
                inference_only=True)

    # =========================== load model ==============================
    print("\n", "=" * 50, " after load model ", "=" * 50)
    # important to reset graph if model is loaded in the same shell.