从许多文献中,我了解了岭回归的方法,即:
loss_Ridge = loss_function + lambda x L2 norm of slope拉索回归的方法是:
loss_Lasso = loss_function + lambda x L1 norm of slope当我读到"TensorFlow机器学习手册“中的”实施Lasso和Ridge回归“时,作者解释说:
"...we将使用连续逼近阶跃函数,称为连续重步长函数.“
它的作者还提供了代码这里行。我不明白在这个上下文中,哪个叫做‘,连续的重步长函数’。请帮帮我。
发布于 2019-05-31 01:48:25
从你提供的链接来看,
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函数又可以是阶跃函数的连续逼近。
您使用连续逼近,因为损失函数对于模型的参数需要是可微的。
要获得关于阅读Lasso.pdf中约束公式1.6节的直觉
您可以在代码中看到,如果A< 0.9,regularization_param就会消失,因此优化将限制A在该范围内。
发布于 2019-05-31 01:54:53
如果您想使用Lasso回归来规范功能,这里有一个例子:
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)https://stackoverflow.com/questions/56387591
复制相似问题