套索回归:连续重步函数

2024-05-16 01:29:23 发布

您现在位置:Python中文网/ 问答频道 /正文

从许多文件中,我学到了岭回归的诀窍,即:

loss_Ridge = loss_function + lambda x L2 norm of slope

套索回归的方法是:

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。 我不明白在这种情况下,哪个叫做连续重步函数。请帮帮我。你知道吗


Tags: 文件of方法lambdanormstepfunction作者
2条回答

如果要使用套索回归对特征进行规格化,这里有一个示例:

from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import Lasso
estimator = Lasso()
featureSelection = SelectFromModel(estimator)
featureSelection.fit(features_vector, target)
selectedFeatures = featureSelection.transform(features_vector)
print(selectedFeatures)

从你提供的链接中

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函数非常接近于logistic函数,而logistic函数又可以是阶跃函数的连续近似。你知道吗

使用连续近似是因为损失函数需要相对于模型的参数是可微的。你知道吗

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

您可以在代码中看到,如果A<;0.9,则正则化参数消失,因此优化将在该范围内约束A。你知道吗

相关问题 更多 >