社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python imblearn make_pipeline typeerror:管道的最后一步应实现fit

pythondumb • 4 年前 • 1167 次点击  

我正试图在管道中实现IMB1RY的窒息。我的数据集是存储在熊猫数据框中的文本数据。请参见下面的代码段

text_clf =Pipeline([('vect', TfidfVectorizer()),('scale', StandardScaler(with_mean=False)),('smt', SMOTE(random_state=5)),('clf', LinearSVC(class_weight='balanced'))])

在此之后,我将使用gridsearchcv。

grid = GridSearchCV(text_clf, parameters, cv=4, n_jobs=-1, scoring = 'accuracy') 

其中参数只不过是tfidfvector()的调整参数。 我得到以下错误。

 All intermediate steps should be transformers and implement fit and transform. 'SMOTE

发布这个错误后,我将代码改为如下。

vect = TfidfVectorizer(use_idf=True,smooth_idf = True, max_df = 0.25, sublinear_tf = True, ngram_range=(1,2))
X = vect.fit_transform(X).todense()
Y = vect.fit_transform(Y).todense()
X_Train,X_Test,Y_Train,y_test = train_test_split(X,Y, random_state=0, test_size=0.33, shuffle=True)
text_clf =make_pipeline([('smt', SMOTE(random_state=5)),('scale', StandardScaler(with_mean=False)),('clf', LinearSVC(class_weight='balanced'))])
grid = GridSearchCV(text_clf, parameters, cv=4, n_jobs=-1, scoring = 'accuracy')

在哪里? parameters 只是调整而已 C 在里面 SVC 分类器。 这次我遇到以下错误:

Last step of Pipeline should implement fit.SMOTE(....) doesn't

这是怎么回事?有人能帮忙吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38656
 
1167 次点击  
文章 [ 1 ]  |  最新文章 4 年前