Exemplo n.º 1
0
def test_search_patience(c, s, a, b):
    X, y = make_classification(n_samples=100, n_features=5, chunks=(10, 5))

    class ConstantClassifier(SGDClassifier):
        def score(*args, **kwargs):
            return 0.5

    model = ConstantClassifier(tol=1e-3)

    params = {
        "alpha": np.logspace(-2, 10, 100),
        "l1_ratio": np.linspace(0.01, 1, 200)
    }

    search = IncrementalSearch(model,
                               params,
                               n_initial_parameters=10,
                               patience=2)
    yield search.fit(X, y, classes=[0, 1])

    assert search.history_results_
    for d in search.history_results_:
        assert d["partial_fit_calls"] <= 3
    assert isinstance(search.best_estimator_, SGDClassifier)
    assert search.best_score_ > 0
    assert "visualize" not in search.__dict__

    X_test, y_test = yield c.compute([X, y])

    search.predict(X_test)
    search.score(X_test, y_test)
Exemplo n.º 2
0
def test_small(c, s, a, b):
    X, y = make_classification(n_samples=100, n_features=5, chunks=(10, 5))
    model = SGDClassifier(tol=1e-3, penalty="elasticnet")
    params = {"alpha": [0.1, 0.5, 0.75, 1.0]}
    search = IncrementalSearch(model, params, n_initial_parameters="grid")
    yield search.fit(X, y, classes=[0, 1])
    X_, = yield c.compute([X])
    search.predict(X_)