Exemplo n.º 1
0
    def test_call(self):
        # type: () -> None

        target_param_names = ["lambda_l1"]
        lgbm_params = {}  # type: Dict[str, Any]
        train_set = lgb.Dataset(None)
        val_set = lgb.Dataset(None)

        lgbm_kwargs = {"valid_sets": val_set}
        best_score = -np.inf

        with turnoff_train():
            objective = OptunaObjective(
                target_param_names,
                lgbm_params,
                train_set,
                lgbm_kwargs,
                best_score,
                "tune_lambda_l1",
                None,
            )
            study = optuna.create_study(direction="minimize")
            study.optimize(objective, n_trials=10)

            assert study.best_value == 0.5
Exemplo n.º 2
0
    def test_init_(self):
        # type: () -> None

        target_param_names = ["learning_rate"]  # Invalid parameter name.

        with pytest.raises(NotImplementedError) as execinfo:
            OptunaObjective(target_param_names, {}, None, {}, 0, "tune_learning_rate", None)

        assert execinfo.type is NotImplementedError