Example #1
0
        (
            MultVAEOptimizer,
            1,
            dict(dim_z=200, enc_hidden_dims=600, kl_anneal_goal=0.2
                 ),  # nothing to tune, use the parameters used in the paper.
        ),
        # (SLIMOptimizer, 40, dict()), # Note: this is a heavy one.
    ]
    for optimizer_class, n_trials, config in test_configs:
        recommender_name = optimizer_class.recommender_class.__name__
        optimizer: BaseOptimizer = optimizer_class(
            data_train.X_all,
            valid_evaluator,
            fixed_params=config,
        )
        (best_param,
         validation_result_df) = optimizer.optimize(n_trials=n_trials)
        validation_result_df["recommender_name"] = recommender_name
        validation_results.append(validation_result_df)
        pd.concat(validation_results).to_csv(f"validation_scores.csv")
        test_recommender = optimizer.recommender_class(X_train_val_all,
                                                       **best_param)
        test_recommender.learn()
        test_scores = test_evaluator.get_scores(test_recommender,
                                                [20, 50, 100])

        test_results.append(
            dict(name=recommender_name, best_param=best_param, **test_scores))
        with open("test_results.json", "w") as ofs:
            json.dump(test_results, ofs, indent=2)
Example #2
0
        (TopPopOptimizer, 1),
        (CosineKNNOptimizer, 40),
        (AsymmetricCosineKNNOptimizer, 40),
        (TverskyIndexKNNOptimizer, 40),
        (P3alphaOptimizer, 40),
        (RP3betaOptimizer, 40),
        (IALSOptimizer, 40),
        (DenseSLIMOptimizer, 20),
        # (SLIMOptimizer, 40), time consuming
        # (MultVAEOptimizer, 5),
    ]
    for optimizer_class, n_trials in test_configs:
        recommender_name = optimizer_class.recommender_class.__name__
        optimizer: BaseOptimizer = optimizer_class(data_train.X_all,
                                                   valid_evaluator)
        (best_param,
         validation_result_df) = optimizer.optimize(timeout=14400,
                                                    n_trials=n_trials)
        validation_result_df["recommender_name"] = recommender_name
        validation_results.append(validation_result_df)
        pd.concat(validation_results).to_csv(f"validation_scores.csv")
        test_recommender = optimizer.recommender_class(X_train_val_all,
                                                       **best_param)
        test_recommender.learn()
        test_scores = test_evaluator.get_scores(test_recommender, [5, 10, 20])

        test_results.append(
            dict(name=recommender_name, best_param=best_param, **test_scores))
        with open("test_results.json", "w") as ofs:
            json.dump(test_results, ofs, indent=2)