zoukankan      html  css  js  c++  java
  • Keras MAE和MSE source code

    def mean_squared_error(y_true, y_pred):
        if not K.is_tensor(y_pred):
            y_pred = K.constant(y_pred)
        y_true = K.cast(y_true, y_pred.dtype)
        return K.mean(K.square(y_pred - y_true), axis=-1)
    
    
    def mean_absolute_error(y_true, y_pred):
        if not K.is_tensor(y_pred):
            y_pred = K.constant(y_pred)
        y_true = K.cast(y_true, y_pred.dtype)
        return K.mean(K.abs(y_pred - y_true), axis=-1)
    
    
    def mean_absolute_percentage_error(y_true, y_pred):
        if not K.is_tensor(y_pred):
            y_pred = K.constant(y_pred)
        y_true = K.cast(y_true, y_pred.dtype)
        diff = K.abs((y_true - y_pred) / K.clip(K.abs(y_true),
                                                K.epsilon(),
                                                None))
        return 100. * K.mean(diff, axis=-1)
    
    
    def mean_squared_logarithmic_error(y_true, y_pred):
        if not K.is_tensor(y_pred):
            y_pred = K.constant(y_pred)
        y_true = K.cast(y_true, y_pred.dtype)
        first_log = K.log(K.clip(y_pred, K.epsilon(), None) + 1.)
        second_log = K.log(K.clip(y_true, K.epsilon(), None) + 1.)
    return K.mean(K.square(first_log - second_log), axis=-1)
    
  • 相关阅读:
    动态数组arraylist的使用
    第一次
    layui.mobile.css
    index.html
    Ansible部署配置
    微服务项目配置文件
    镜像挂载
    网卡设置
    获取内存信息
    超时方法
  • 原文地址:https://www.cnblogs.com/yaos/p/11715001.html
Copyright © 2011-2022 走看看