gridsearchcvlasso-regressionconvergence

Lasso via GridSearchCV: ConvergenceWarning: Objective did not converge


I am trying to find the optimal parameter of a Lasso regression:

alpha_tune = {'alpha': np.linspace(start=0.000005, stop=0.02, num=200)}
model_tuner = Lasso(fit_intercept=True)
cross_validation = RepeatedKFold(n_splits=5, n_repeats=3, random_state=1)
        
model = GridSearchCV(estimator=model_tuner, param_grid=alpha_tune, cv=cross_validation, scoring='neg_mean_squared_error', n_jobs=-1).fit(features_train_std, labels_train)
print(model.best_params_['alpha'])
        

My variables are demeaned and standardized. But I get the following error:

ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 1.279e+02, tolerance: 6.395e-01

I know this error has been reported several times, but none of the previous posts answer how to solve it. In my case, the error is generated by the fact that the lowerbound 0.000005 is very small, but this is a reasonable value as indicated by solving the tuning problem via the information criteria:

lasso_aic = LassoLarsIC(criterion='aic', fit_intercept=True, eps=1e-16, normalize=False)
lasso_aic.fit(X_train_std, y_train)
print('Lambda: {:.8f}'.format(lasso_aic.alpha_))

lasso_bic = LassoLarsIC(criterion='bic', fit_intercept=True, eps=1e-16, normalize=False)
lasso_bic.fit(X_train_std, y_train)
print('Lambda: {:.8f}'.format(lasso_bic.alpha_))

AIC and BIC give values of around 0.000008. How can this warning be solved?


Solution

  • Increasing the default parameter max_iter=1000 in Lasso will do the job:

    alpha_tune = {'alpha': np.linspace(start=0.000005, stop=0.02, num=200)}
    model_tuner = Lasso(fit_intercept=True, max_iter=5000)
    cross_validation = RepeatedKFold(n_splits=5, n_repeats=3, random_state=1)
            
    model = GridSearchCV(estimator=model_tuner, param_grid=alpha_tune, cv=cross_validation, scoring='neg_mean_squared_error', n_jobs=-1).fit(features_train_std, labels_train)
    print(model.best_params_['alpha'])