Advertisement

MSE: Mean Squared Error (L2 loss)

阅读量:

MSE均方误差(L2 loss)

1.代码展示MAE和MSE图片特性
复制代码
    import tensorflow as tf
    import matplotlib.pyplot as plt
    sess = tf.Session()
    x_val = tf.linspace(-1.,-1.,500)
    target = tf.constant(0.)
    
    #计算L2_loss
    l2_y_val = tf.square(target - x_val)
    l2_y_out = sess.run(l2_y_val)#用这个函数打开计算图
    
    #计算L1_loss
    l1_y_val = tf.abs(target - x_val)
    l1_y_out = sess.run(l1_y_val)#用这个函数打开计算图
    
    #打开计算图输出x_val,用来画图
    #用画图来体现损失函数的特点
    x_array = sess.run(x_val)
    plt.plot(x_array, l1_y_out, 'b--', lable = 'L1_loss')
    plt.plot(x_array, l2_y_out, 'r--', lable = 'L

全部评论 (0)

还没有任何评论哟~