imblearn pipeline与Pipeline的区别

我想使用sklearn.pipeline而不是imblearn.pipeline来整合`RandomUnderSampler()`。我的原始数据需要缺失值填补和缩放。这里我使用乳腺癌数据作为一个示例。然而,它给我返回了以下错误信息。我很感激您的建议。感谢您的时间!

from numpy.random import seedseed(12)from sklearn.datasets import load_breast_cancerimport timefrom sklearn.metrics import make_scorerfrom imblearn.metrics import geometric_mean_scorefrom sklearn.linear_model import LogisticRegressionfrom sklearn.model_selection import cross_validatefrom sklearn.pipeline import Pipelinefrom sklearn.impute import SimpleImputerfrom sklearn.preprocessing import MaxAbsScalerfrom imblearn.under_sampling import RandomUnderSamplergmean = make_scorer(geometric_mean_score, greater_is_better=True)X, y = load_breast_cancer(return_X_y=True)start_time1 = time.time()scoring = {'G-mean': gmean}LR_pipe =  Pipeline([("impute", SimpleImputer(strategy='constant',fill_value= 0)),("scale", MaxAbsScaler()),("rus", RandomUnderSampler()),("LR", LogisticRegression(solver='lbfgs', random_state=0, class_weight='balanced', max_iter=100000))])LRscores = cross_validate(LR_pipe,X, y, cv=5,scoring=scoring)end_time1 = time.time()print ("Computational time in seconds = " +str(end_time1 - start_time1) )sorted(LRscores.keys())LR_Gmean = LRscores['test_G-mean'].mean()print("G-mean: %f" % (LR_Gmean))

错误信息:

TypeError: All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'RandomUnderSampler()' (type <class 'imblearn.under_sampling._prototype_selection._random_under_sampler.RandomUnderSampler'>) doesn't

回答:

我们应该从imblearn.pipeline而不是sklearn.pipeline导入make_pipeline:来自sklearn的make_pipeline需要转换器实现fittransform方法。来自sklearn.pipelinePipeline导入与来自imblearn.pipelinePipeline导入发生了冲突!

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注