import numpy as np
# mse,rmse == sqrt(mse) 均方差
def mse(y, t):
return 0.5 * np.sum((y - t)**2)
# cross entropy error
def cee(y, t):
return -np.sum(t * np.log(y + 1e-7)) # 1e7防止log(0)出现
y = np.array([0.1, 0.2, 0.6, 0.1]) # 模拟神经网络输出
t = np.array([0, 0, 0, 1]) # one-hot表示
print("y:", y, "t", t)
r = mse(y, t)
print("mse:", r) # 结果越小越准确
r = cee(y, t)
print("cee:", r) # 结果越接近1越准确


5347

被折叠的 条评论
为什么被折叠?



