From be55252fc43cec0dc067ad9b18ef30deaa788b85 Mon Sep 17 00:00:00 2001 From: Y-oHr-N Date: Sat, 21 Mar 2020 04:38:31 +0900 Subject: [PATCH] Fix test_sklearn.py --- tests/test_sklearn.py | 72 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/test_sklearn.py b/tests/test_sklearn.py index d91f757..6eb0305 100644 --- a/tests/test_sklearn.py +++ b/tests/test_sklearn.py @@ -128,45 +128,30 @@ def test_fit_with_params( objective=objective, ) + # See https://github.com/microsoft/LightGBM/issues/2328 if boosting_type == "rf" and callable(objective): - # See https://github.com/microsoft/LightGBM/issues/2328 with pytest.raises(lgb.basic.LightGBMError): clf.fit(X, y) else: clf.fit(X, y) -@pytest.mark.parametrize("callbacks", [None, [callback]]) -@pytest.mark.parametrize("eval_metric", [None, "auc", zero_one_loss]) -def test_fit_with_fit_params( - callbacks: Optional[List[Callable]], eval_metric: Union[Callable, str] -) -> None: - X, y = load_breast_cancer(return_X_y=True) - - clf = OGBMClassifier(n_estimators=n_estimators, n_trials=n_trials) - - clf.fit(X, y, callbacks=callbacks, eval_metric=eval_metric) - - -def test_fit_with_unused_fit_params() -> None: - X, y = load_breast_cancer(return_X_y=True) - - clf = OGBMClassifier(n_estimators=n_estimators, n_trials=n_trials) - - clf.fit(X, y, eval_set=None) - - -def test_fit_with_group_k_fold() -> None: +def test_fit_with_empty_param_distributions() -> None: X, y = load_breast_cancer(return_X_y=True) clf = OGBMClassifier( - cv=GroupKFold(5), n_estimators=n_estimators, n_trials=n_trials + colsample_bytree=0.1, + n_estimators=n_estimators, + n_trials=n_trials, + param_distributions={}, ) - n_samples, _ = X.shape - groups = np.random.choice(10, size=n_samples) + clf.fit(X, y) - clf.fit(X, y, groups=groups) + df = clf.study_.trials_dataframe() + values = df["value"] + + assert values.nunique() == 1 def test_fit_with_pruning() -> None: @@ -186,22 +171,37 @@ def test_fit_with_pruning() -> None: assert len(pruned_trials) > 0 -def test_fit_with_empty_param_distributions() -> None: +@pytest.mark.parametrize("callbacks", [None, [callback]]) +@pytest.mark.parametrize("eval_metric", [None, "auc", zero_one_loss]) +def test_fit_with_fit_params( + callbacks: Optional[List[Callable]], eval_metric: Union[Callable, str] +) -> None: + X, y = load_breast_cancer(return_X_y=True) + + clf = OGBMClassifier(n_estimators=n_estimators, n_trials=n_trials) + + clf.fit(X, y, callbacks=callbacks, eval_metric=eval_metric) + + +def test_fit_with_unused_fit_params() -> None: + X, y = load_breast_cancer(return_X_y=True) + + clf = OGBMClassifier(n_estimators=n_estimators, n_trials=n_trials) + + clf.fit(X, y, eval_set=None) + + +def test_fit_with_group_k_fold() -> None: X, y = load_breast_cancer(return_X_y=True) clf = OGBMClassifier( - colsample_bytree=0.1, - n_estimators=n_estimators, - n_trials=n_trials, - param_distributions={}, + cv=GroupKFold(5), n_estimators=n_estimators, n_trials=n_trials ) - clf.fit(X, y) - - df = clf.study_.trials_dataframe() - values = df["value"] + n_samples, _ = X.shape + groups = np.random.choice(10, size=n_samples) - assert values.nunique() == 1 + clf.fit(X, y, groups=groups) @pytest.mark.parametrize("n_jobs", [-1, 1])