Get feature names and coefficients from sklearn pipeline

Viewed 62

I have a pipeline that uses mlflow in Databricks and I would like to get the feature names and coefficients after I run the pipeline:

My pipeline looks like this:

sklr_classifier = LogisticRegression(
  C=97.24899142002924,
  penalty="l2",
  random_state=956273824,
)

model = Pipeline([
    ("column_selector", col_selector),
    ("preprocessor", preprocessor),
    ("classifier", sklr_classifier),
])

pipe = model.fit(X_train, y_train)

I know I can access the coefficients with:

pipe.named_steps["classifier"].coef_.flatten()

But I would like to have the associated feature names.

0 Answers
Related