一、MSE


python
# 损失函数
# 均方误差
def mse(y,t):
return np.mean((y-t)**2)
二、交叉熵损失函数

python
# 交叉熵损失函数
def cross_entropy(y,t):
# 将y转化为二维
if y.ndim==1:
y=y.reshape(1,y.size)
t=t.reshape(1,t.size)
# 将t转化为顺序编码类别标签
if t.size==y.size:
# 按行取出 t中对应的类别标签
t=t.argmax(axis=1)
# y的所有索引值n
n=y.shape[0]
return -np.sum(np.log(y[np.arange(n),t]+1e-10))/n
三、二分类任务损失函数


四、多分类任务损失函数

五、回归任务损失函数
MAE

MSE

Smooth L1

