SMOTE函数在make_pipeline中无法工作

5
我希望同时应用交叉验证和过采样。 我从这段代码中得到以下错误:
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)

所有中间步骤都应该是转换器,实现fit和transform或者是字符串'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')'(类型)不行。 PS. 我使用imblearn.over_sampling.RandomOverSampler而不是SMOTE时也出现了相同的错误。
1个回答

26
你应该从imblearn.pipeline导入make_pipeline,而不是从sklearn.pipeline导入:来自sklearnmake_pipeline需要变换器实现fittransform方法,但SMOTE没有实现transform

1
谢谢,你真的救了我的一天,我严重不知道这个,一直陷入困境。 - iamawesome

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接