zoukankan      html  css  js  c++  java
  • keras_6_损失函数Losses

    1. keras中使用loss

    # 损失函数(或称目标函数、优化评分函数)是编译模型时所需的两个参数之一:
    #你可以传递一个现有的损失函数名,
    model.compile(loss='mean_squared_error', optimizer='sgd')
    
    # 或者一个TensorFlow/Theano符号函数,有以下两个参数:
    # y_true: 真实标签. TensorFlow/Theano张量。
    # y_pred: 预测值. TensorFlow/Theano张量,其shape与y_true相同。
    # 该符号函数为每个数据点返回一个标量,
    from keras import losses
    model.compile(loss=losses.mean_squared_error, optimizer='sgd')
    

    2. keras官方支持的

    1. mean_squared_error

    2. mean_absolute_error

    3. mean_absolute_percentage_error

    4. mean_squared_logarithmic_error

    5. squared_hinge

    6. hinge

    7. categorical_hinge

    8. logcosh

      • 预测误差的双曲余弦的对数。对于小的xlog(cosh(x))近似等于(x ** 2) / 2。对于大的x,近似于abs(x) - log(2)。这表示logcosh与均方误差大致相同,但是不会受到偶尔疯狂的错误预测的强烈影响。
    9. categorical_crossentropy

      • 注意: 当使用categorical_crossentropy损失时,你的目标值应该是分类格式 (即,如果你有10个类,每个样本的目标值应该是一个10维的向量,这个向量除了表示类别的那个索引为1,其他均为0,即one-hot编码)。 为了将 整数目标值 转换为 分类目标值,你可以使用Keras实用函数to_categorical

        from keras.utils.np_utils import to_categorical
        categorical_labels = to_categorical(int_labels, num_classes=None) # 转化为one-hot encoding
        
    10. sparse_categorical_crossentropy

    11. binary_crossentropy

    12. kullback_leibler_divergence

    13. poisson

    14. cosine_proximity

  • 相关阅读:
    通过域名方式决定使用哪个数据库
    OpenERP/Odoo命令行参数
    修改pip源
    解决python "Non-ASCII character"错误
    Synergy 鼠标和键盘共享软件
    java 线程复习笔记
    常用设计模式--代理模式
    数据结构--二叉树
    mysql 索引的数据结构(B树和B+树)
    JS更改树型json的key键
  • 原文地址:https://www.cnblogs.com/LS1314/p/10380623.html
Copyright © 2011-2022 走看看