SMOTE 功能在 make_pipeline 中不起作用
SMOTE function not working in make_pipeline
我想同时应用交叉验证和过采样。
我从这段代码中得到以下错误:
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。我使用 imblearn.over_sampling.RandomOverSampler rather than SMOTE.
得到同样的错误
您应该从 imblearn.pipeline
而不是从 sklearn.pipeline
导入 make_pipeline
:来自 sklearn 的 make_pipeline
需要转换器来实现 fit
和 transform
方法,但 SMOTE
未实现 transform
.
我想同时应用交叉验证和过采样。 我从这段代码中得到以下错误:
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。我使用 imblearn.over_sampling.RandomOverSampler rather than SMOTE.
得到同样的错误您应该从 imblearn.pipeline
而不是从 sklearn.pipeline
导入 make_pipeline
:来自 sklearn 的 make_pipeline
需要转换器来实现 fit
和 transform
方法,但 SMOTE
未实现 transform
.