神经网络的主要特点,就是可以从数据中进行“学习”。这个学习的过程,就是让训练数据自动决定最优的权重参数。
神经网络(深度学习)也是机器学习的一种;跟传统机器学习方法相比,神经网络不需要人工设置 特征量(如 SIFT、HOG等),这样就可以用同样的流程直接处理所有问题了。
3.1 损失函数
神经网络中,需要以某个指标为线索来寻找最优权重参数;这个指标就是 损失函数(loss function)。
- 常见损失函数均方误差(MSE)
均方误差(Mean Squared Error ,MSE),也称L2 Loss:
![图片[1]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-223.png)
def mean_squared_error(y, t):
return 0.5 * np.sum((y-t)**2)
2.交叉熵误差
![图片[2]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-224.png)
def cross_entropy_error(y, t):
if y.ndim == 1:
t = t.reshape(1, t.size)
y = y.reshape(1, y.size)
# 监督数据是one-hot向量的情况下,转换为正确解标签的索引
if t.size == y.size:
t = t.argmax(axis=1)
batch_size = y.shape[0]
return -np.sum(np.log(y[np.arange(batch_size), t] + 1e-7)) / batch_size
3.1.2 分类任务损失函数
![图片[3]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-225.png)
![图片[4]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-226.png)
3.1.3回归任务损失函数
![图片[5]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-227.png)
![图片[6]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-228.png)
![图片[7]-第 3 章 神经网络的学习-大赛人网](https://www.dsrw.com/wp-content/uploads/2026/11/image-229.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END















请登录后查看评论内容