SMOTE function not working in make_pipeline
Asked Answered
H

1

7

I wanna simultaneously apply cross-validation and over-sampling. I get the following error from this code:

from sklearn.pipeline import Pipeline, make_pipeline
imba_pipeline = make_pipeline(SMOTE(random_state=42), 
                              LogisticRegression(C=3.4))
cross_val_score(imba_pipeline, X_train_tf, y_train, scoring='f1-weighted', cv=kf)

ll intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'SMOTE(k_neighbors=5, kind='deprecated', m_neighbors='deprecated', n_jobs=1, out_step='deprecated', random_state=42, ratio=None, sampling_strategy='auto', svm_estimator='deprecated')' (type ) doesn't

PS. I get the same error using imblearn.over_sampling.RandomOverSampler rather than SMOTE.

Hypsometer answered 12/11, 2019 at 19:0 Comment(0)
D
28

You should import make_pipeline from imblearn.pipeline and not from sklearn.pipeline: make_pipeline from sklearn needs the transformers to implement fit and transform methods but SMOTE does not implement transform.

Drear answered 12/11, 2019 at 21:2 Comment(1)
Thx, you've literally saved my day, seriously didn't know this and was stuck in a bad mannerSalman

© 2022 - 2024 — McMap. All rights reserved.