python的sklearn机器学习SVM中的NuSVC运行报错:ValueError: b'specified nu is infeasible'
发布日期:2022-03-18 18:19:20 浏览次数:2 分类:技术文章

本文共 1396 字,大约阅读时间需要 4 分钟。

早上在使用NuSVC进行模型训练的时候,报错如下

Reloaded modules: __mp_main__Traceback (most recent call last):  File "
", line 1, in
runfile File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace) File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/TfidfVectorizer-svm.py", line 58, in
clf = svm.NuSVC(nu=0.1).fit(X_train, y_train) File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\svm\base.py", line 187, in fit fit(X, y, sample_weight, solver_type, kernel, random_seed=seed) File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\svm\base.py", line 276, in _sparse_fit random_seed) File "sklearn/svm/libsvm_sparse.pyx", line 144, in sklearn.svm.libsvm_sparse.libsvm_sparse_trainValueError: b'specified nu is infeasible'

我查阅资料后发现是因为NuSVC参数nu的设置问题,使用如下代码一个个尝试nu参数的合适的值。

nus =[_/10 for _ in range(1,11,1)]for nu in nus:     clf = svm.NuSVC(nu=nu)     try:         clf.fit(X_train, y_train)#替换成自己的训练模型     except ValueError as e:         print("nu {} not feasible".format(nu))

当然另外一种解决方案就是把NuSVC换成LinearSVC,我发现LinearSVC训练的效果更好。

转载地址:https://zhang0peter.blog.csdn.net/article/details/86064931 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Latex报错Missing $ inserted.inserted text
下一篇:Chrome与chromedriver版本对应

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月14日 23时00分57秒