TypeError:__ init __()得到了一个意外的关键字参数'n_folds',sentiment_analysis_with_SVM

问题描述 投票:0回答:1

我正在尝试实现svm用于情绪分析,我试图实现这个gitlink https://github.com/jatinwarade/Sentiment-analysis-using-SVM/blob/master/SVM.ipynb

from sklearn.model_selection import ShuffleSplit
from sklearn.model_selection import StratifiedKFold

我提到这是因为它说交叉原点改为model_selection,因为它是被删除的Error: __init__() got an unexpected keyword argument 'n_splits'所以我用这个替换

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),
)

这返回错误:

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'

请帮我解决这个错误

python-3.x scikit-learn svm sentiment-analysis sklearn-pandas
1个回答
0
投票

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

但请注意,数据不应作为参数传递给验证器,通过这样做,您实际上将liked_train作为n_splits的参数传递,这将无效。相反,您应该在初始化后将数据仅传递给fitgrid_svm

© www.soinside.com 2019 - 2024. All rights reserved.