gpt4 book ai didi

python - Lasso 回归目标未收敛

转载 作者:行者123 更新时间:2023-11-30 08:50:39 24 4
gpt4 key购买 nike

这是我的代码。当我运行它时,山脊很好,但是对于套索,我收到错误消息:

ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations.

请帮忙。

from sklearn.linear_model import LinearRegression, Lasso, Ridge, RidgeCV, LassoCV
from sklearn.model_selection import cross_val_score
import numpy as np
import sys

dataset = np.loadtxt(sys.argv[1], delimiter = ',')
X = dataset[:,:10]
y = dataset[:,10]

ridge_cv = RidgeCV(alphas=[1e-3, 1e-2, 1e-1, 1, 10, 100]).fit(X,y)

lasso_cv = LassoCV(alphas=[1e-3, 1e-2, 1e-1, 1, 10, 100]).fit(X,y)

lin_reg = LinearRegression()
ridge_reg = Ridge(alpha = ridge_cv.alpha_)
lasso_reg = Lasso(alpha = lasso_cv.alpha_)

print(cross_val_score(lin_reg, X, y, cv=2).mean())
print(cross_val_score(ridge_reg, X, y, cv=2).mean())
print(cross_val_score(lasso_reg, X, y, cv=2).mean())

最佳答案

提高耐受性。

检查documentation 优化的容差:如果更新小于 tol,优化代码将检查对偶间隙的最优性并继续,直到它小于 tol

主要负责收敛

关于python - Lasso 回归目标未收敛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59396620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com