pipelinehelper icon indicating copy to clipboard operation
pipelinehelper copied to clipboard

Proposal for a simpler syntax of "pipeline" and "params_grid"

Open Elijas opened this issue 3 years ago • 2 comments

Description

I'd like to propose a simpler syntax for the pipeline description.

It is made simpler by having a choice function, which signifies, that either a pipeline element or some parameter needs to be hotswapped.

Example

pipeline and param_grid produced by this code:

simple_pipeline = [
    ('sc', StandardScaler),
    ('clf', choice(
        ('lr', LogisticRegression, dict(
            max_iter=1e5,
            C=choice(0.1, 0.01)
        }),
        ('mlp', MLPClassifier, dict(
            activation='tanh',
            hidden_layer_sizes=choice((4,), (8,), (8, 8,))
        ))
    ))
]

pipeline, param_grid = parse(simple_pipeline)

is identical to the pipeline and param_grid produced by the original code:

pipeline = Pipeline(steps=[
    ('sc', StandardScaler()),
    ('clf', PipelineHelper([
        ('lr', LogisticRegression(
            max_iter=1e5
        )),
        ('mlp', MLPClassifier(
            activation='tanh'
        ))
    ]))
])
param_grid = {
    'clf__selected_model': pipeline.named_steps['clf'].generate({
        'lr__C': [0.1, 0.01],
        'mlp__hidden_layer_sizes': [(4,), (8,), (8, 8,)]
    })
}

Elijas avatar May 12 '21 10:05 Elijas

You might want to take a look at my other lib pyparts, which follows this approach, but also supports FeatureUnions, StackingClassifiers and ColumnTransformers.

While it doesn't necessarily make the syntax simpler, it removes the need to call the generate method explicitly.

bmurauer avatar May 12 '21 13:05 bmurauer

You might want to take a look at my other lib pyparts, which follows this approach, but also supports FeatureUnions, StackingClassifiers and ColumnTransformers.

While it doesn't necessarily make the syntax simpler, it removes the need to call the generate method explicitly.

Will take a look, thanks!

Elijas avatar May 12 '21 15:05 Elijas