gpt4 book ai didi

python - 套索回归 : The continuous heavy step function

转载 作者:行者123 更新时间:2023-11-30 09:43:09 25 4
gpt4 key购买 nike

从很多文档中,我了解到岭回归的秘诀是:

loss_Ridge = loss_function + lambda x L2 norm of slope

Lasso 回归的秘诀是:

loss_Lasso = loss_function + lambda x L1 norm of slope

当我读到“TensorFlow Machine Learning Cookbook”中的主题“实现套索和岭回归”时,其作者解释说:

"...we will use a continuous approximation to a step function, called the continuous heavy step function..."

及其作者还提供了代码行 here 。我不明白在这种情况下哪个被称为“连续重阶跃函数”。请帮助我。

最佳答案

从您提供的链接中,

if regression_type == 'LASSO':
# Declare Lasso loss function
# Lasso Loss = L2_Loss + heavyside_step,
# Where heavyside_step ~ 0 if A < constant, otherwise ~ 99
lasso_param = tf.constant(0.9)
heavyside_step = tf.truediv(1., tf.add(1., tf.exp(tf.multiply(-50., tf.subtract(A, lasso_param)))))
regularization_param = tf.multiply(heavyside_step, 99.)
loss = tf.add(tf.reduce_mean(tf.square(y_target - model_output)), regularization_param)

这个heavyside_step函数非常接近逻辑函数,而逻辑函数又可以是阶跃函数的连续逼近。

您使用连续逼近,因为损失函数需要相对于模型参数可微。

要获得有关的直觉,请阅读 https://www.cs.ubc.ca/~schmidtm/Documents/2005_Notes_Lasso.pdf 中的约束公式第 1.6 节。

您可以在代码中看到,如果 A < 0.9,则regularization_param 消失,因此优化会将 A 限制在该范围内。

关于python - 套索回归 : The continuous heavy step function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56387591/

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