作者:zoudan的世界94129433 | 来源:互联网 | 2022-12-31 15:49
1> Vivek Kumar..:
您需要查看管道对象。不平衡学习具有管道延伸的scikit学习管道,为fit_sample()和样品适应()除了fit_predict(方法),fit_transform()和预测()的方法scikit学习。
在这里看看这个例子:
http://contrib.scikit-learn.org/imbalanced-learn/stable/auto_examples/pipeline/plot_pipeline_classification.html#sphx-glr-auto-examples-pipeline-plot-pipeline-classification-py
对于您的代码,您需要这样做:
from imblearn.pipeline import make_pipeline, Pipeline
smote_enn = SMOTEENN(smote = sm)
clf_rf = RandomForestClassifier(n_estimators=25, random_state=1)
pipeline = make_pipeline(smote_enn, clf_rf)
OR
pipeline = Pipeline([('smote_enn', smote_enn),
('clf_rf', clf_rf)])
然后,您可以将此pipeline
对象作为常规对象传递给scikit-learn中的GridSearchCV,RandomizedSearchCV或其他交叉验证工具。
kf = StratifiedKFold(n_splits=n_splits)
random_search = RandomizedSearchCV(pipeline, param_distributiOns=param_dist,
n_iter=1000,
cv = kf)