sunspots
sunspots

Reputation: 1057

Access attributes with sklearn Pipeline and MultiOutputRegressor

Suppose a machine learning model, such as LightGBM's LGBMRegressor, has an attribute best_iteration_. How is this attribute accessible after calling the fit method, whereby sklearn's Pipeline and MultiOutputRegressor were utilized?

For Pipeline I've tried named_steps:

foo.named_steps['reg']

which returns the following object sklearn.multioutput.MultiOutputRegressor.

Then, I've tried .estimators_:

foo.named_steps['reg'].estimators_

which returns a list. However, the list contains the initial parameters that were supplied to the model.

Could someone please explain the ideal way to access a model's attributes?

Upvotes: 0

Views: 340

Answers (1)

Alex Ramses
Alex Ramses

Reputation: 577

I assume foo is a sklearn pipeline object, if so, you can probably do this:

for e in foo.named_steps['reg'].estimators_:
    print(e.best_iteration_)
  • foo.named_steps['reg'].estimators_ returns a list of estimators inside of MultiOutputRegressor.
  • e is the LGBMRegressor you used inside of your MultiOutputRegressor.

You can replace best_iteration_ with any attributes of the model you wanted to access.

Upvotes: 1

Related Questions