1

I designed my sklearn pipeline in the following way:

transf_pipe = make_column_transformer(
    (binning_pipe, ['na', 'nc']),
    (OneHotEncoder(drop='if_binary'), ['site_type']),
    (make_pipeline(
        common_country,
        OneHotEncoder()), 'visitor_country'),
    (make_pipeline(imputing_pipe,
                    StandardScaler()
                  ), ['window', 'day_of_week', 'los']),
    remainder='passthrough',
    n_jobs=-1
)

full_pipe = make_pipeline(
    transf_pipe,
    RandomForestClassifier(random_state=3, min_samples_leaf=8), 
)

I called full_pipe.fit(X_train, y_train and all works smoothly.

However, I want to inspect some of the transformers or estimators, such as the one hot encoder, when I access it through full_pipe.named_steps I am not able to see the fitted attributes. It is like the estimator was not fitted.

How can I access the fitted estimators of a pipeline?

TomDLT
  • 4,346
  • 1
  • 20
  • 26
3nomis
  • 1,175
  • 1
  • 9
  • 30

1 Answers1

3
  • You can access steps in a Pipeline with full_pipe.named_steps or with indices full_pipe[0].
  • You can access fitted transformers in a ColumnTransformer with transf_pipe.transformers_.

In your example, use full_pipe[0].transformers_[1][1] to access the fitted OneHotEncoder.

TomDLT
  • 4,346
  • 1
  • 20
  • 26