GridSearchCV函数提供了太多警告

时间:2018-03-08 07:19:40

标签: python scikit-learn warnings

我正在运行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一次?

1 个答案:

答案 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