L1-L2 正则化的不同系数
Different coefficients for L1-L2 regularisation
我想用 L1 和 L2 正则化来正则化网络的权重。但是,我找不到独立改变正则化强度的方法。 Keras documentation 也不提供任何信息。
那么,有没有办法在 l1_l2
正则化器中使用不同的强度? 或者可能有另一种方法来达到相同的结果?
我现在的模型很简单:
stren = 0.001
model = Sequential()
model.add(Dense(64, input_dim=148, activation='relu', kernel_regularizer=reg.l2(stren)))
model.add(Dense(1, activation='sigmoid', kernel_regularizer=reg.l2(stren)))
而且我希望能够有一些类似的东西:
kernel_regularizer=reg.l1_l2(l1_str, l2_str)
或许你可以尝试根据你的损失函数自定义正则化,在Keras框架中设计一个用户自定义的正则化函数。像这样:
def l1_l2(l1=0.01, l2=0.01):
return L1L2(l1=l1, l2=l2)
或者层与层之间使用dropout函数如Dropout(0.2)
.
当然你可以独立改变 regularizers 的强度:
from keras import regularizers
regularizers.l1_l2(l1=0.001, l2=0.1) # the strength of l1 is set to 0.001 and l2 to 0.1
我想用 L1 和 L2 正则化来正则化网络的权重。但是,我找不到独立改变正则化强度的方法。 Keras documentation 也不提供任何信息。
那么,有没有办法在 l1_l2
正则化器中使用不同的强度? 或者可能有另一种方法来达到相同的结果?
我现在的模型很简单:
stren = 0.001
model = Sequential()
model.add(Dense(64, input_dim=148, activation='relu', kernel_regularizer=reg.l2(stren)))
model.add(Dense(1, activation='sigmoid', kernel_regularizer=reg.l2(stren)))
而且我希望能够有一些类似的东西:
kernel_regularizer=reg.l1_l2(l1_str, l2_str)
或许你可以尝试根据你的损失函数自定义正则化,在Keras框架中设计一个用户自定义的正则化函数。像这样:
def l1_l2(l1=0.01, l2=0.01):
return L1L2(l1=l1, l2=l2)
或者层与层之间使用dropout函数如Dropout(0.2)
.
当然你可以独立改变 regularizers 的强度:
from keras import regularizers
regularizers.l1_l2(l1=0.001, l2=0.1) # the strength of l1 is set to 0.001 and l2 to 0.1