def test_gp_search():
    # Test that the best estimator contains the right value for foo_param
    clf = MockDiscreteClassifier()
    gp_search = GPSearchCV(clf, {'foo_param': ['int', [1, 3]]})
    # make sure it selects the smallest parameter in case of ties
    old_stdout = sys.stdout
    sys.stdout = StringIO()
    gp_search.fit(X, y)
    sys.stdout = old_stdout
    assert_equal(gp_search.best_estimator_.foo_param, 2)

    clf = MockContinuousClassifier()
    gp_search = GPSearchCV(clf, {'foo_param': ['float', [-3, 3]]}, verbose=3)
    # make sure it selects the smallest parameter in case of ties
    old_stdout = sys.stdout
    sys.stdout = StringIO()
    gp_search.fit(X, y)
    sys.stdout = old_stdout
    assert_almost_equal(gp_search.best_estimator_.foo_param, 0, decimal=1)

    # Smoke test the score etc:
    gp_search.score(X, y)
    gp_search.predict_proba(X)
    gp_search.decision_function(X)
    gp_search.transform(X)

    # Test exception handling on scoring
    gp_search.scoring = 'sklearn'
    assert_raises(ValueError, gp_search.fit, X, y)
Beispiel #2
0
def test_gp_search():
    clf = MockClassifier()
    gp_search = GPSearchCV(clf, {'foo_param': ['int', [1, 3]]}, verbose=3)
    # make sure it selects the smallest parameter in case of ties
    old_stdout = sys.stdout
    sys.stdout = StringIO()
    gp_search.fit(X, y)
    sys.stdout = old_stdout
    assert_equal(gp_search.best_estimator_.foo_param, 2)

    for i, foo_i in enumerate([1, 2, 3]):
        assert_true(gp_search.scores_[i][0]
                    == {'foo_param': foo_i})
    # Smoke test the score etc:
    gp_search.score(X, y)
    gp_search.predict_proba(X)
    gp_search.decision_function(X)
    gp_search.transform(X)

    # Test exception handling on scoring
    gp_search.scoring = 'sklearn'
    assert_raises(ValueError, gp_search.fit, X, y)