bmurauer / pipelinehelper

scikit-helper to hot-swap pipeline elements
GNU General Public License v3.0
21 stars 9 forks source link

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

Open Elijas opened 3 years ago

Elijas commented 3 years ago

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,)]
    })
}
bmurauer commented 3 years ago

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.

Elijas commented 3 years ago

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!