首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:__init__()获得意外的关键字参数'n_folds',sentiment_analysis_with_SVM

TypeError:__init__()获得意外的关键字参数'n_folds',sentiment_analysis_with_SVM
EN

Stack Overflow用户
提问于 2019-03-30 20:19:33
回答 1查看 10.1K关注 0票数 1

我正在尝试实现情感分析的支持向量机,我试图实现这个gitlink https://github.com/jatinwarade/Sentiment-analysis-using-SVM/blob/master/SVM.ipynb

代码语言:javascript
复制
from sklearn.model_selection import ShuffleSplit
from sklearn.model_selection import StratifiedKFold

我引用了它,因为它说要将交叉原点更改为model_selection,因为它是废弃的Error: __init__() got an unexpected keyword argument 'n_splits',所以我将其替换为

代码语言:javascript
复制
grid_svm = GridSearchCV(
    pipeline_svm, #object used to fit the data
    param_grid=param_svm, 
    refit=True,  # fit using all data, on the best detected classifier
    n_jobs=-1,  # number of cores to use for parallelization; -1 for "all cores" i.e. to run on all CPUs
    scoring='accuracy',#optimizing parameter
    cv=StratifiedKFold(liked_train,n_folds=5),
)

这将返回错误:

代码语言:javascript
复制
TypeError                                 Traceback (most recent call last)
<ipython-input-49-61dd1e818fa4> in <module>
      5     n_jobs=-1,  # number of cores to use for parallelization; -1 for "all cores" i.e. to run on all CPUs
      6     scoring='accuracy',#optimizing parameter
----> 7     cv=StratifiedKFold(liked_train,n_folds=5),
      8 )

TypeError: __init__() got an unexpected keyword argument 'n_folds'

请帮我解决这个错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-30 21:47:12

正如您在model_selected.StrafiedKFold的文档中看到的那样,没有名为n_folds的关键字参数,您确实应该使用n_splits

但是请注意,数据不应该作为参数传递给验证器,这样做实际上就是将liked_train作为n_splits的参数传递,这是不起作用的。相反,您应该在初始化之后只将数据传递给grid_svmfit

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55431356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档