gpt4 book ai didi

python-3.x - 为什么 sklearn 中的岭回归和套索回归需要 random_state?

转载 作者:行者123 更新时间:2023-11-30 08:40:45 29 4
gpt4 key购买 nike

在 scikit-learn 中,Lasso 和 Ridge 回归是两种具有 random_state 属性的回归方法。为什么这两个方法需要这个属性?

来自文档:

class sklearn.linear_model.Lasso(alpha=1.0, fit_intercept=True, normalize=False, precompute=False, copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, positive=False, random_state=None, selection=’cyclic’)


class sklearn.linear_model.Ridge(alpha=1.0, fit_intercept=True, normalize=False, copy_X=True, max_iter=None, tol=0.001, solver=’auto’, random_state=None)

最佳答案

两种方法都涉及在模型的某些阶段生成随机数。

对于 Lasso,这是由于每个变量的回归系数的拟合所致。这可以以“循环”方式完成,或者在每次迭代时随机选择变量。第一个属性为 selection = 'circular',后一个属性为 selection = 'random。后者涉及随机数。作为documentation状态:

If set to ‘random’, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting to ‘random’) often leads to significantly faster convergence especially when tol is higher than 1e-4.

对于岭回归,如果您想使用随机梯度下降(利用子采样)来拟合模型,则需要它。为此,您需要在模型初始化期间声明 solver = 'sag'solver = 'saga'documentation random_state 读取:

The seed of the pseudo random number generator to use when shuffling the data. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random. Used when solver == ‘sag’.

关于python-3.x - 为什么 sklearn 中的岭回归和套索回归需要 random_state?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48909927/

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