如何使我的网格搜索简历与SVC工作?
我想执行我在管道中写的步骤,但这给了我以下错误:
All intermediate steps should be transformers and implement fit and transform or be the string
'passthrough' 'IsolationForest ()' (type <class 'sklearn.ensemble._iforest.IsolationForest'>)
doesn't
我的代码如下:
pipe = Pipeline([
('scaling', None),
('anomaly', IsolationForest() ),
('balancing',None),
('classificator', SVC())
])
params = {'scaling': [StandardScaler(), RobustScaler(), MinMaxScaler()],
'balancing':[RandomUnderSampler(),SMOTE()], 'balancing__random_state':45, 'balancing__k_neighbors':[3, 5, 7, 10],
'classificator__C': np.logspace(-2,1,4)}
gs = GridSearchCV(estimator=pipe, param_grid = params)
gs.fit(x_tr, y_tr)
I would like to perform the steps I wrote in the pipeline but it gives me the following error:
All intermediate steps should be transformers and implement fit and transform or be the string
'passthrough' 'IsolationForest ()' (type <class 'sklearn.ensemble._iforest.IsolationForest'>)
doesn't
my code is as follows:
pipe = Pipeline([
('scaling', None),
('anomaly', IsolationForest() ),
('balancing',None),
('classificator', SVC())
])
params = {'scaling': [StandardScaler(), RobustScaler(), MinMaxScaler()],
'balancing':[RandomUnderSampler(),SMOTE()], 'balancing__random_state':45, 'balancing__k_neighbors':[3, 5, 7, 10],
'classificator__C': np.logspace(-2,1,4)}
gs = GridSearchCV(estimator=pipe, param_grid = params)
gs.fit(x_tr, y_tr)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中提到的那样,
selimationforest
确实没有transform()
方法。但是,您可能可以写一个转换的包装纸(请参阅类似的问题)。但是,您可能必须求助于使用Imblearn管道,否则功能和目标长度可能不匹配。As it was mentioned in the comments,
IsolationForest
has notransform()
method indeed. However, you can likely write a transforming wrapper thyself (see the similar question). You'd likely have to resort to using imblearn pipeline however, otherwise the features and target length could mismatch.