【问题标题】:Mean Absolute Error - Python平均绝对误差 - Python
【发布时间】:2015-10-27 11:36:56
【问题描述】:

我是 Python 新手

我必须实现一个可以计算 2 张图像之间的 MAE 的函数

这是我学过的MAE公式:

这是我的代码:

def calculateMAE(imageA, imageB):
    """
    Calculate MAE between 2 images
    np: numpy

    """
    mae = np.sum(imageB.astype("float") - imageA.astype("float"))
    mae /= float(imageA.shape[0] * imageA.shape[1] * 255) 

    if (mae < 0):
        return mae * -1
    else:
        return mae

谁能告诉我我的功能是否正确? 提前致谢!

【问题讨论】:

  • mae = np.absolute(np.subtract(x_true, x_pred)).mean()

标签: python numpy


【解决方案1】:

平均绝对误差中的绝对符号在 sum 中的每个条目中,因此您将其汇总后无法检查 mae &lt; 0 - 您需要将其放入 sum 中!

因此你应该有类似的东西

mae = np.sum(np.absolute((imageB.astype("float") - imageA.astype("float")))

np.absolute(matrix) 按元素计算绝对值。

【讨论】:

  • 我举了一个例子。您可以从 numpy here 中查看。
  • mae = np.sum(np.absolute(imageB.astype("float") - imageA.astype("float"))) mae /= float(imageA.shape[0] * imageA .shape[1] * 255) return mae 对吗兄弟?
猜你喜欢
  • 2019-01-02
  • 2021-04-19
  • 2018-12-28
  • 1970-01-01
  • 2019-07-10
  • 2013-12-21
  • 2018-12-18
  • 2020-01-23
  • 1970-01-01
相关资源
最近更新 更多