我正在运行GridSearchCV
函数来搜索Lasso回归模型的最佳alpha
(正则化项系数)。
当我像这样运行网格搜索时,
_model = Lasso()
param_dict = {'alpha': [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1]}
gsearch = GridSearchCV(_model, param_dict, cv=5, scoring='neg_mean_squared_error', n_jobs=5)
相同ConvergenceWarning
出现约20次,如下所示。
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
ConvergenceWarning)
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
ConvergenceWarning)
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
ConvergenceWarning)
/home/user/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.
ConvergenceWarning)
....
ConvergenceWarning
很重要,但是当它显示这么多次时,它会非常烦人。
有没有其他方法只显示此ConvergenceWarning
一次?
答案 0 :(得分:2)
我认为您应该使用import warnings
warnings.warn("once")
模块来处理它
SSLContextBuilder builder = SSLContexts.custom();
SSLContext sslContext = builder.useProtocol("SSLv3").build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() {
@Override
public void verify(String host, SSLSocket ssl) throws IOException {
}
....
....);
return sslsf;
}
上述代码只会打印一次警告。
您可以浏览警告模块here