了解 SVR scikit-learn 收敛所需的迭代次数 [英] Knowing the number of iterations needed for convergence in SVR scikit-learn
问题描述
我正在尝试优化 SVR 模型,但由于过度拟合而面临问题,为了克服这个问题,我尝试减少迭代次数,而不是将其保留到收敛.
I am trying to optimize an SVR model and facing a problem because of overfitting, to overcome this I have tried to decrease the number of iterations instead of leaving it until convergence.
为了比较这两种模型,我需要两种情况下的迭代次数.在打开的情况下如何知道收敛所需的迭代次数(max_iter=-1)?
To compare the both models I need the number of iterations for both cases. How can I know the number of iterations needed for convergence in the case it is open (max_iter=-1)?
这是我的代码:
model_1=SVR(kernel='rbf', C=316, epsilon=0, gamma=0.003162,max_iter=2500)
model_1.fit(tr_sets[:,:2],tr_sets[:,2])
print(model_1.score)
model_2=SVR(kernel='rbf', C=316, epsilon=0, gamma=0.003162,max_iter=-1)
model_2.fit(tr_sets[:,:2],tr_sets[:,2])
print(model_2.score)
现在通过设置 verbose=2
解决了 IPython IDE 的问题,但仍需要在 Jupyter notebook、spyder 中查看或写入外部文件作为详细选项似乎只适用于 IPython IDE
the problem now is solved for IPython IDE by setting verbose=2
but still need to be viewed in Jupyter notebook, spyder or to be written to an external file as the verbose option seems only to work with IPython IDE
推荐答案
如果要查看 SVR 的进度,请在 SVR 的构造函数中输入 verbose=2
- 注意这一点可以使进度减慢一个幅度
If you want to see the progress of your SVR, enter verbose=2
to the constructor of SVR - notice this can make progress slower by a magnitude
from sklearn.svm import SVR
import numpy as np
n_samples, n_features = 10, 5
np.random.seed(0)
y = np.random.randn(n_samples)
X = np.random.randn(n_samples, n_features)
clf = SVR(C=1.0, epsilon=0.2,verbose=2)
clf.fit(X, y)
输出将是
optimization finished, #iter = 4
obj = -4.366801, rho = -0.910470
nSV = 7, nBSV = 5
#iter
是您要查找的内容
这篇关于了解 SVR scikit-learn 收敛所需的迭代次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!