如何使我的网格搜索简历与SVC工作?

发布于 2025-02-13 05:17:03 字数 804 浏览 2 评论 0原文

我想执行我在管道中写的步骤,但这给了我以下错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2025-02-20 05:17:04

正如评论中提到的那样,selimationforest确实没有transform()方法。但是,您可能可以写一个转换的包装纸(请参阅类似的问题)。但是,您可能必须求助于使用Imblearn管道,否则功能和目标长度可能不匹配。

As it was mentioned in the comments, IsolationForest has no transform() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文