SMOTE函数在make_pipeline中不起作用

时间:2019-11-12 19:00:29

标签: python scikit-learn cross-validation oversampling smote

我想同时应用交叉验证和过度采样。 我从此代码中收到以下错误:

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)
  

所有中间步骤都应该是转换器,并实现拟合和转换,或者是字符串'passthrough''SMOTE(k_neighbors = 5,kind ='deprecated',m_neighbors ='deprecated',n_jobs = 1,         out_step =“已弃用”,random_state = 42,ratio = None,         sample_strategy ='auto',svm_estimator ='deprecated')'(类型)没有

PS。我使用imblearn.over_sampling.RandomOverSampler而不是SMOTE遇到了相同的错误。

1 个答案:

答案 0 :(得分:2)

您应该从make_pipeline而不是从imblearn.pipeline导入sklearn.pipeline:来自sklearn的make_pipeline需要转换器实现fittransform方法但SMOTE未实现transform