How to use the neuraxle.pipeline.Pipeline function in neuraxle

To help you get started, we’ve selected a few neuraxle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Neuraxio / Neuraxle / testing / steps / test_for_each.py View on Github external
def test_fit_for_each_should_fit_all_steps_for_each_data_inputs_expected_outputs():
    tape = TapeCallbackFunction()
    p = Pipeline([
        ForEachDataInput(Pipeline([
            FitCallbackStep(tape.callback, ["1"]),
            FitCallbackStep(tape.callback, ["2"]),
        ]))
    ])
    data_inputs = [[0, 1], [1, 2]]
    expected_outputs = [[2, 3], [4, 5]]

    p = p.fit(data_inputs, expected_outputs)

    assert isinstance(p, Pipeline)
    assert tape.get_name_tape() == ["1", "2", "1", "2"]
    assert tape.data == [([0, 1], [2, 3]), ([0, 1], [2, 3]), ([1, 2], [4, 5]), ([1, 2], [4, 5])]
github Neuraxio / Neuraxle / testing / steps / test_choose_one_or_many_steps_of.py View on Github external
def create_test_case_multiple_steps_choosen():
    a_callback = TapeCallbackFunction()
    b_callback = TapeCallbackFunction()

    return NeuraxleTestCase(
        pipeline=Pipeline([
            ChooseOneOrManyStepsOf([
                ('a', TransformCallbackStep(a_callback, transform_function=lambda di: di * 2)),
                ('b', TransformCallbackStep(b_callback, transform_function=lambda di: di * 2))
            ]),
        ]),
        callbacks=[a_callback, b_callback],
        expected_callbacks_data=[DATA_INPUTS, DATA_INPUTS],
        hyperparams={
            'ChooseOneOrManyStepsOf__a__enabled': True,
            'ChooseOneOrManyStepsOf__b__enabled': True
        },
        hyperparams_space={
            'ChooseOneOrManyStepsOf__a__enabled': Boolean(),
            'ChooseOneOrManyStepsOf__b__enabled': Boolean()
        },
        expected_processed_outputs=np.array([0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
github Neuraxio / Neuraxle / testing / test_pipeline.py View on Github external
@pytest.mark.parametrize("steps_list", steps_lists)
@pytest.mark.parametrize("pipeline_runner", pipeline_runners)
def test_pipeline_fit_transform(steps_list, pipeline_runner):
    data_input_ = [AN_INPUT]
    expected_output_ = [AN_EXPECTED_OUTPUT]
    p = Pipeline(steps_list, pipeline_runner=pipeline_runner())

    result = p.fit_transform(data_input_, expected_output_)

    assert tuple(result) == tuple(expected_output_)
github Neuraxio / Neuraxle / testing / test_pipeline.py View on Github external
def test_pipeline_nested_mutate_inverse_transform():
    expected_tape = ["1", "2", "3", "4", "5", "6", "7", "7", "6", "5", "4", "3", "2", "1"]
    tape = TapeCallbackFunction()

    p = Pipeline([
        Identity(),
        TransformCallbackStep(tape.callback, ["1"]),
        TransformCallbackStep(tape.callback, ["2"]),
        Pipeline([
            Identity(),
            TransformCallbackStep(tape.callback, ["3"]),
            TransformCallbackStep(tape.callback, ["4"]),
            TransformCallbackStep(tape.callback, ["5"]),
            Identity()
        ]),
        TransformCallbackStep(tape.callback, ["6"]),
        TransformCallbackStep(tape.callback, ["7"]),
        Identity()
    ])

    p, _ = p.fit_transform(np.ones((1, 1)))  # will add range(1, 8) to tape.
github Neuraxio / Neuraxle / testing / test_truncable_steps.py View on Github external
def test_set_train_should_set_train_to_true():
    pipeline = Pipeline([
        SomeStep(),
        SomeStep(),
        Pipeline([
            SomeStep(),
        ])
    ])

    assert pipeline.is_train
    assert pipeline[0].is_train
    assert pipeline[1].is_train
    assert pipeline[2].is_train
    assert pipeline[2][0].is_train
github Neuraxio / Neuraxle / testing / test_pipeline.py View on Github external
def test_pipeline_slicing_both():
    p = Pipeline([
        ("a", SomeStep()),
        ("b", SomeStep()),
        ("c", SomeStep())
    ])

    r = p["b":"c"]

    assert "a" not in r
    assert "b" in r
    assert "c" not in r
github Neuraxio / Neuraxle / testing / test_pipeline.py View on Github external
def test_pipeline_update_hyperparam_level_two_flat():
    p = Pipeline([
        ("a", SomeStep()),
        ("b", Pipeline([
            ("a", SomeStep()),
            ("b", SomeStep()),
            ("c", SomeStep())
        ])),
        ("c", SomeStep())
    ])
    p.set_hyperparams({
        "b__a__learning_rate": 7,
        "b__a__other_hp": 8,
    })

    p.update_hyperparams({
        "b__a__learning_rate": 0.01
    })

    assert p["b"]["a"].hyperparams["learning_rate"] == 0.01
github Neuraxio / Neuraxle / testing / test_pipeline.py View on Github external
def test_pipeline_update_hyperparam_level_one_flat():
    p = Pipeline([
        ("a", SomeStep()),
        ("b", SomeStep()),
        ("c", SomeStep())
    ])
    p.set_hyperparams({
        "a__learning_rate": 7,
        "a__other_hp": 8
    })

    p.update_hyperparams({
        "a__learning_rate": 0.01
    })

    assert p["a"].hyperparams["learning_rate"] == 0.01
    assert p["a"].hyperparams["other_hp"] == 8
    assert p["b"].hyperparams == dict()
github Neuraxio / Neuraxle / examples / easy_rest_api_serving.py View on Github external
def main():
    boston = load_boston()
    X, y = shuffle(boston.data, boston.target, random_state=13)
    X = X.astype(np.float32)
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, shuffle=False)

    pipeline = Pipeline([
        AddFeatures([
            PCA(n_components=2),
            FastICA(n_components=2),
        ]),
        RidgeModelStacking([
            GradientBoostingRegressor(),
            KMeans(),
        ]),
    ])

    print("Fitting on train:")
    pipeline = pipeline.fit(X_train, y_train)
    print("")
    print("Transforming train and test:")
    y_train_predicted = pipeline.transform(X_train)
    y_test_predicted = pipeline.transform(X_test)