numpy矩阵求MSE

MSE loss

#官方示例
from sklearn.metrics import mean_squared_error
y_true = [[0.5, 1],[-1, 1],[7, -6]]
y_pred = [[0, 2],[-1, 2],[8, -5]]
mean_squared_error(y_true, y_pred) #0.708

numpy矩阵求MSE_第1张图片验证

import numpy as np 
A = np.array(y_true)
B = np.array(y_pred)

mse = (np.square(A - B)).mean(axis=None)
mse 

结果如下
numpy矩阵求MSE_第2张图片

你可能感兴趣的:(numpy,矩阵,线性代数)