コード例 #1
0
def test_refit(tmp_path: pathlib.Path,
               early_stopping_rounds: Optional[int]) -> None:
    X, y = load_breast_cancer(return_X_y=True)

    clf = OGBMClassifier(
        n_estimators=n_estimators,
        n_trials=n_trials,
        random_state=random_state,
        refit=True,
        model_dir=tmp_path,
    )

    clf.fit(X, y, early_stopping_rounds=early_stopping_rounds)

    y_pred = clf.predict(X)

    if early_stopping_rounds is None:
        _n_estimators = n_estimators
    else:
        _n_estimators = clf.best_iteration_

    clf = lgb.LGBMClassifier(n_estimators=_n_estimators, **clf.best_params_)

    clf.fit(X, y)

    np.testing.assert_array_equal(y_pred, clf.predict(X))
コード例 #2
0
def test_predict_with_unused_predict_params(tmp_path: pathlib.Path) -> None:
    X, y = load_breast_cancer(return_X_y=True)

    clf = OGBMClassifier(n_estimators=n_estimators,
                         n_trials=n_trials,
                         model_dir=tmp_path)

    clf.fit(X, y)

    y_pred = clf.predict(X, pred_leaf=False)

    assert isinstance(y_pred, np.ndarray)
    assert y.shape == y_pred.shape
コード例 #3
0
def test_predict_with_predict_params(tmp_path: pathlib.Path,
                                     num_iteration: Optional[int]) -> None:
    X, y = load_breast_cancer(return_X_y=True)

    clf = OGBMClassifier(n_estimators=n_estimators,
                         n_trials=n_trials,
                         model_dir=tmp_path)

    clf.fit(X, y)

    y_pred = clf.predict(X, num_iteration=num_iteration)

    assert isinstance(y_pred, np.ndarray)
    assert y.shape == y_pred.shape