Skip to content

Commit

Permalink
Fix test_sklearn.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-oHr-N committed Mar 20, 2020
1 parent 94389b8 commit be55252
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions tests/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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])
Expand Down

0 comments on commit be55252

Please sign in to comment.