Ejemplo n.º 1
0
def test_reproducibility():
    rng = check_random_state(0)

    # Classification
    X_train, X_test, y_train, y_test = train_test_split(iris.data,
                                                        iris.target,
                                                        random_state=rng)
    ensemble = LazyBaggingClassifier(random_state=rng)
    ensemble.fit(X_train, y_train)

    assert_array_equal(ensemble.predict(X_test), ensemble.predict(X_test))

    # Regression
    X_train, X_test, y_train, y_test = train_test_split(boston.data,
                                                        boston.target,
                                                        random_state=rng)
    ensemble = LazyBaggingRegressor(random_state=rng)
    ensemble.fit(X_train, y_train)
    assert_array_equal(ensemble.predict(X_test), ensemble.predict(X_test))
Ejemplo n.º 2
0
def test_multioutput():
    X, y = make_multilabel_classification(n_samples=100, n_labels=1,
                                          n_classes=5, random_state=0,
                                          return_indicator=True)

    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

    est = LazyBaggingClassifier(random_state=0, n_estimators=10,
                                bootstrap=False)
    est.fit(X_train, y_train)

    assert_almost_equal(est.score(X_train, y_train), 1.)

    y_proba = est.predict_proba(X_test)
    y_log_proba = est.predict_log_proba(X_test)
    for p, log_p in zip(y_proba, y_log_proba):
        assert_array_almost_equal(p, np.exp(log_p))

    est = LazyBaggingRegressor(random_state=0, n_estimators=10,
                               bootstrap=False)
    est.fit(X_train, y_train)
    assert_almost_equal(est.score(X_train, y_train), 1.)