【问题标题】:Add constraint to mean square error cost function in multi output regression在多输出回归中为均方误差成本函数添加约束
【发布时间】:2017-01-31 09:54:03
【问题描述】:

我正在使用均方误差来计算多输出回归器的损失函数。我使用了具有一对多架构的递归神经网络模型。我的输出向量大小为 6 (1*6),值是单调的(非递减)。

示例: y_i = [1,3,6,13,30,57,201]

我想强制模型学习这种依赖关系。因此,为成本函数添加了一个约束。我在验证集上得到一个等于 300 的错误。我相信在编辑了均方误差损失函数后,我将能够获得更好的性能。

我正在使用 keras 来实现。这是核心模型。

batchSize = 256
epochs = 20

samplesData = trainX
samplesLabels = trainY

print("Compiling neural network model...")

Model = Sequential()
Model.add(LSTM(input_shape = (98,),input_dim=98, output_dim=128, return_sequences=True))
Model.add(Dropout(0.2))
#Model.add(LSTM(128, return_sequences=True))
#Model.add(Dropout(0.2))
Model.add(TimeDistributedDense(7))  
#rmsprop = rmsprop(lr=0.0, decay=0.0)
Model.compile(loss='mean_squared_error', optimizer='rmsprop')
Model.summary()
print("Training model...")
# learning schedule callback
#lrate = LearningRateScheduler(step_decay)
#callbacks_list = [lrate]
history = Model.fit(samplesData, samplesLabels, batch_size=batchSize, nb_epoch= epochs, verbose=1,
                             validation_split=0.2, show_accuracy=True)
print("model training has been completed.")

任何其他关于学习率、衰减等的提示都值得赞赏。

【问题讨论】:

    标签: python optimization machine-learning keras mean-square-error


    【解决方案1】:

    保持均方误差只是一个指标。改用平滑 L1 损失。这是我的实现。

    #Define Smooth L1 Loss
    def l1_smooth_loss(y_true, y_pred):
        abs_loss = tf.abs(y_true - y_pred)
        sq_loss = 0.5 * (y_true - y_pred)**2
        l1_loss = tf.where(tf.less(abs_loss, 1.0), sq_loss, abs_loss - 0.5)
        return tf.reduce_sum(l1_loss, -1)    
    #And
    
    Model.compile(loss='l1_smooth_loss', optimizer='rmsprop')
    

    【讨论】:

      猜你喜欢
      • 2017-01-04
      • 1970-01-01
      • 2021-04-10
      • 2018-10-31
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多