8000 set_params fn for pipeline to maintain order of parameters · Issue #10439 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
set_params fn for pipeline to maintain order of parameters #10439
Closed
@janvanrijn

Description

@janvanrijn

Description

When I want to use the set param method to set a bunch of parameters, I can not control the order in which these are set. As a result, sometimes the program crashes, as setting hyperparameters requires a specific order.

e.g., SGD classifier requires the eta0 hyperparameter to be set to a value higher than 0 (which is the default) if a learning rate schedule other than optimal is chosen.

Steps/Code to Reproduce

from sklearn.linear_model import SGDClassifier
from sklearn.pipeline import Pipeline
from collections import OrderedDict

model = Pipeline(steps=[('estimator', SGDClassifier())])

hyperparameters = OrderedDict()
hyperparameters['estimator__eta0'] = 10 ** -5
hyperparameters['estimator__learning_rate'] = 'constant'

model.set_params(**hyperparameters)

print(model)

Expected Results

:)

Actual Results

This code crashes in 50% of the cases (depending on the order in which the hyperparameters are 'set')

Versions

Apparently this problem only occurs when the classifier is used in a pipeline, when using vanilla sgd there is no problem.
As the codeblock demonstrates, this problem occurs both when using a regular dict and an ordered dict.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0