Ejemplo n.º 1
0
def test_pipeline():
    X, y = make_classification(random_state=0)
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
    pipe = Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])
    pipe.fit(X_train, y_train)
    score = pipe.score(X_test, y_test)
    assert score > 0.8
Ejemplo n.º 2
0
def test_pipeline_with_classification(classification_dataset, model_key):
    X_train, X_test, y_train, y_test = classification_dataset
    model_const = models[model_key]
    if model_key == 'RandomForestClassifier':
        model = model_const(n_bins=2)
    else:
        model = model_const()
    pipe = Pipeline(steps=[('scaler', StandardScaler()), ('model', model)])
    pipe.fit(X_train, y_train)
    prediction = pipe.predict(X_test)
    assert isinstance(prediction, cupy.ndarray)
Ejemplo n.º 3
0
def test_pipeline_with_regression(regression_dataset, model_key,
                                  instantiation):
    X_train, X_test, y_train, y_test = regression_dataset
    model_const = models[model_key]
    if model_key == 'RandomForestRegressor':
        model = model_const(n_bins=2)
    else:
        model = model_const()

    if instantiation == 'Pipeline':
        pipe = Pipeline(steps=[('scaler', StandardScaler()), ('model', model)])
    elif instantiation == 'make_pipeline':
        pipe = make_pipeline(StandardScaler(), model)
    pipe.fit(X_train, y_train)
    prediction = pipe.predict(X_test)
    assert isinstance(prediction, cupy.ndarray)
    _ = pipe.score(X_test, y_test)
Ejemplo n.º 4
0
def test_pipeline_with_classification(classification_dataset, model_key,
                                      instantiation):
    X_train, X_test, y_train, y_test = classification_dataset
    model_const = models[model_key]
    if model_key == 'RandomForestClassifier':
        model = model_const(n_bins=2)
    else:
        model = model_const()
    if instantiation == 'Pipeline':
        pipe = Pipeline(steps=[('scaler', StandardScaler()), ('model', model)])
    elif instantiation == 'make_pipeline':
        pipe = make_pipeline(StandardScaler(), model)
    pipe.fit(X_train, y_train)
    prediction = pipe.predict(X_test)
    assert isinstance(prediction, cupy.ndarray)
    if model_key == 'RandomForestClassifier':
        pytest.skip("RandomForestClassifier is not yet supported"
                    "by the Pipeline utility")
    _ = pipe.score(X_test, y_test)