I passed a Pipeline to RFE so scaling happens before the model, but RFE complains that the Pipeline has no coef_.
Why this happens
RFE looks for coef_ or feature_importances_ on the object you give it. A Pipeline doesn't have these attributes itself. They belong to its last step, so RFE can't find them.
Answer 1: Point importance_getter at the inner step
importance_getter accepts a dotted path to the attribute. Use it to reach into the Pipeline:
from sklearn.preprocessing import StandardScaler
model = Pipeline([
("scale", StandardScaler()),
("clf", LogisticRegression(max_iter=1000)),
])
rfe = RFE(model, n_features_to_select=5,
importance_getter="named_steps.clf.coef_")
rfe.fit(X, y)
The step name in the path (clf) must match the name you gave the step in the Pipeline. For multi-class problems, coef_ has one row per class. RFE handles this automatically by combining the rows into a single importance per feature.
This approach is nice because the scaler is re-fit on the remaining features at each elimination step.
