def test_obvious_usecase():
    X = np.concatenate([
        np.random.normal(-10, 1, (100, 2)),
        np.random.normal(10, 1, (100, 2))
    ])
    y = np.concatenate([np.zeros(100), np.ones(100)])
    assert (GMMClassifier().fit(X, y).predict(X) == y).all()
def test_value_error_threshold():
    X = np.concatenate([
        np.random.normal(-10, 1, (100, 2)),
        np.random.normal(10, 1, (100, 2))
    ])
    y = np.concatenate([np.zeros(100), np.ones(100)])
    with pytest.raises(ValueError):
        GMMClassifier(megatondinosaurhead=1).fit(X, y)
def test_estimator_checks(test_fn):
    clf = GMMClassifier()
    test_fn(GMMClassifier.__name__, clf)
    clf = BayesianGMMClassifier()
    test_fn(BayesianGMMClassifier.__name__, clf)
Example #4
0

@pytest.mark.parametrize("estimator", [
    RandomRegressor(strategy="uniform"),
    RandomRegressor(strategy="normal"),
    DeadZoneRegressor(effect="linear", n_iter=100),
    DeadZoneRegressor(effect="quadratic", n_iter=100),
],
                         ids=id_func)
def test_shape_regression(estimator, random_xy_dataset_regr):
    X, y = random_xy_dataset_regr
    assert estimator.fit(X, y).predict(X).shape[0] == y.shape[0]
    pipe = Pipeline(steps=[('scaler', StandardScaler()), ('clf', estimator)])
    assert pipe.fit(X, y).predict(X).shape[0] == y.shape[0]


@pytest.mark.parametrize("estimator", [
    GMMClassifier(),
    BayesianGMMClassifier(),
    GMMOutlierDetector(threshold=0.999, method="quantile"),
    GMMOutlierDetector(threshold=2, method="stddev"),
    BayesianGMMOutlierDetector(threshold=0.999, method="quantile"),
    BayesianGMMOutlierDetector(threshold=2, method="stddev")
],
                         ids=id_func)
def test_shape_classification(estimator, random_xy_dataset_clf):
    X, y = random_xy_dataset_clf
    assert estimator.fit(X, y).predict(X).shape[0] == y.shape[0]
    pipe = Pipeline(steps=[('scaler', StandardScaler()), ('clf', estimator)])
    assert pipe.fit(X, y).predict(X).shape[0] == y.shape[0]