Exemplo n.º 1
0
def test_make_recipe_defence():
    X, y = cars_data()

    with pytest.raises(ValueError):
        (X_train, X_valid, X_test, y_train, y_valid,
         y_test) = mealprep.make_recipe(
             X=X,
             y=y,
             recipe="ohe_and_standard_scaler",
             splits_to_return="INVALID SPLIT COMMAND",
             train_valid_prop=0.5,
         )

    return None
Exemplo n.º 2
0
def test_make_recipe_split_prop():
    X, y = cars_data()

    # check OHE behavior when one categorical column
    (X_train, X_valid, X_test, y_train, y_valid,
     y_test) = mealprep.make_recipe(
         X=X,
         y=y,
         recipe="ohe_and_standard_scaler",
         splits_to_return="train_test",
         train_valid_prop=0.5,
     )

    assert X_train.shape[0] == X_test.shape[0]

    return None
Exemplo n.º 3
0
def test_make_recipe_splits_train():
    X, y = cars_data()

    # Test on splits_to_return="train_test"
    X_train, X_valid, X_test, y_train, y_valid, y_test = mealprep.make_recipe(
        X=X, y=y, recipe="ohe_and_standard_scaler", splits_to_return="train")

    assert type(X_train) == pd.DataFrame
    assert X_test is None
    assert type(y_train) == np.ndarray
    assert y_test is None
    assert X_valid is None
    assert y_valid is None

    assert X.shape[0] == X_train.shape[0]

    return None
Exemplo n.º 4
0
def test_make_recipe_splits_traintestvalid():
    X, y = cars_data()

    # Test on splits_to_return="train_test_valid"
    X_train, X_valid, X_test, y_train, y_valid, y_test = mealprep.make_recipe(
        X=X,
        y=y,
        recipe="ohe_and_standard_scaler",
        splits_to_return="train_test_valid")

    assert type(X_train) == pd.DataFrame
    assert type(X_test) == pd.DataFrame
    assert type(X_valid) == pd.DataFrame
    assert type(y_train) == np.ndarray
    assert type(y_test) == np.ndarray
    assert type(y_valid) == np.ndarray

    return None
Exemplo n.º 5
0
def test_make_recipe_ohe():
    X, y = cars_data()

    # check OHE behavior when one categorical column
    X_train, X_valid, X_test, y_train, y_valid, y_test = mealprep.make_recipe(
        X=X,
        y=y,
        recipe="ohe_and_standard_scaler",
        splits_to_return="train_test",
        random_seed=1993,
    )
    assert list(X_train.columns) == [
        "Miles_per_Gallon",
        "Cylinders",
        "Displacement",
        "Horsepower",
        "Weight_in_lbs",
        "Acceleration",
        "x0_Europe",
        "x0_Japan",
        "x0_USA",
    ]

    # check OHE behavior when two categorical column
    X["Cylinders"] = X["Cylinders"].apply(str)
    X_train, X_valid, X_test, y_train, y_valid, y_test = mealprep.make_recipe(
        X=X,
        y=y,
        recipe="ohe_and_standard_scaler",
        splits_to_return="train_test",
        random_seed=1993,
    )

    assert list(X_train.columns) == [
        "Miles_per_Gallon",
        "Displacement",
        "Horsepower",
        "Weight_in_lbs",
        "Acceleration",
        "x0_3",
        "x0_4",
        "x0_5",
        "x0_6",
        "x0_8",
        "x1_Europe",
        "x1_Japan",
        "x1_USA",
    ]

    # check that error is thrown if bad recipe select
    with pytest.raises(ValueError):
        (X_train, X_valid, X_test, y_train, y_valid,
         y_test) = mealprep.make_recipe(
             X=X,
             y=y,
             recipe="not_a_recipe",
             splits_to_return="train_test",
             random_seed=1993,
         )

    return None