Chapter 5 Machine Learning Basics

《Deep Learning》 读书笔记

写这个笔记的目的有两个:一是以高层的角度把整个章节的内容联系起来,从而加深自己的理解,同时也可以供日后复习使用;二是在日后的组会中可能会降到的时候,有东西可以讲(好偷懒 -_-)。

因为是刚入门的新手,有很多东西还不了解,或者了解的不透彻,肯定会有错误和疏漏的地方,希望大家不吝赐教哈~~

5.1 Learning Algorithms

首先,提出了经典的ML的定义:

A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P , if its performance at tasks in T , as measured by P , improves with experience E.

然后,本章分 3 节分别详细的对定义中的3个实体进行 description(to provide a formal definition of what may be used for each of these entities),然后再最后一小节用 Linear Regression 的例子进行了讲解。

另外,这里引入了 design matrix 的概念。

具体内容可以参阅书籍。

5.2 Capacity, Overfitting and Underfitting

  • Machine Learning使用的是Optimization的方法进行模型的训练,但是它并不是Optimization。因为Optimization是完全的希望准确度在训练数据上尽可能的高(最终过拟合),而ML最终想要的是 generalization/test error 尽可能的低。

    这个内容在第 8 章有一小节专门对它们进行了对比,具体可以看那里。

  • How can we affect performance on the test set when we get to observe only the training set?

    Make some assumptions: These assumptions are that the examples in each dataset are independent from each other, and that the train set and test set are identically distributed, drawn from the same probability distribution as each other.

  • Capacity

    • 这里的Capacity指的是模型对 training dataset 的拟合能力,所以Capacity越高并不一定越好,可能会产生过拟合现象。

    • One way to control the capacity of a learning algorithm is by choosing its hypothesis space, the set of functions that the learning algorithm is allowed to select as being the solution. 另外,还需要注意到 functions 的具体形式也会影响到模型的Capacity

    • 关于模型的Capacity,提到了Occam’s razor原则:在模型的效果相似的情况下,选择较为简单的模型。目的是提高模型的 generalization 能力。

  • We must remember that while simpler functions are more likely to generalize (to have a small gap between training and test error) we must still choose a sufficiently complex hypothesis to achieve low training error.

    也就是总是选择复杂的模型,然后用Regularization的方法(weight decaydropoutearly stoppingcross validation等)减轻过拟合的程度。(CS231n课程中有强调这一点)。

  • CapacityGeneralization error的关系如下图所示。

    Chapter 5 Machine Learning Basics
  • Parametric models learn a function described by a parameter vector whose size is finite and fixed before any data is observed. Non-parametric models have no such limitation. 注意 Non-parametric models 并不是没有参数,只是参数数量不是固定的。

  • Note that it is possible for the model to have optimal capacity and yet still have a large gap between training and generalization error. In this situation, we may be able to reduce this gap by gathering more training examples.

5.2.1 The No Free Lunch Theorem

  • In some sense, no machine learning algorithm is universally any better than any other.

  • The no free lunch theorem implies that we must design our machine learning algorithms to perform well on a specific task.

5.2.2 Regularization

  • Regularization is any modification we make to a learning algorithm that is intended to reduce its generalization error but not its training error.

  • Regularization就是为了尽量减轻过拟合的程度,比如使用了L2/weight decay正则化的拟合结果如下图所示。

    Chapter 5 Machine Learning Basics

    从中可以看出regularization的效果是非常显著的。

  • Regularization有多种实现方式,但是必须根据要解决的具体问题进行选择使用哪一种方式(we must choose a form of regularization that is well-suited to the particular task)。

  • 第 7 章 都在讲这个,可以参考书本内容。

5.3 Hyperparameters and Validation Sets

  • Hyperparameters(如learning ratebatch sizeregularization的强度等)不需要学习,原因有两个:

    • 难于学习

    • 如果学习,可能会造成overfitting(If learned on the training set, such hyperparameters would always choose the maximum possible model capacity, resulting in overfitting (refer to figure 5.3)).

  • Hyperparameters 对应的是 parameters(如权重矩阵W、偏置项b),它们是需要学习的,它们控制着模型学习到的 features 如何影响接下来的 prediction(107页)。

  • Hyperparameters从某个角度上说也是可以学习的,比如对于learning rate,一开始不知道哪一个好,可以定义一个区间,然后使用随机搜索CS231n课程中说随机搜索会比网格搜索效果好,关于这点本书的 第 8 章 也有讲解对比,可以参阅那小节的内容)的方式从这个区间进行选择,用一个比较小的 mini-batch 去跑一个比较小的 epoch 来验证哪一个(或哪一个区间内的)learning rate比较好,然后缩小这个区间,按照同样的方式再接着进行选择(也就是学习)(CS231n课程第一个 assignment 中有一小题是关于这个的)。

  • It is important that the test examples are not used in any way to make choices about the model, including its hyperparameters.

    也就是说在训练的时候不能用模型在 test dataset 的 test error 的高低来决定选择哪一个 Hyperparameters 、或者在什么时候停止训练,因为这相当于以一种变相的方式把 test dataset 当成了 training dataset 。正确的方法是从 training dataset 中抽出一部分(disjoint subsets,通常是20%)当做 validation dataset 来完成这项工作(CS231n课程中也有强调这一点)。

  • validation set is used to “train” the hyperparameters

  • After all hyperparameter optimization is complete, the generalization error may be estimated using the test set.

5.3.1 Cross-Validation

  • 通常是k-fold cross-validationCS231n课程的第一个 assignment 中有一小题是关于 cross-validation 的)。

  • 注意分割一定要保证:non-overlapping subsets

  • 这里有一个问题,

5.4 Estimators, Bias and Variance

上面的都是用来评估机器学习算法学习到的模型的好坏的指标,分别从不同的角度对机器学习算法的性能进行衡量。

5.4.1 Point Estimation

  • Point Estimator

    • 因为对函数没有任何约束(The definition does not require that g return a value that is close to the true θ or even that the range of g is the same as the set of allowable values of θ),所以可以是任何函数(almost any function thus qualifies as an estimator)。

    • 但却有 good estimator:a good estimator is a function whose output is close to the true underlying θ that generated the training data.

    • 就是机器学习算法要学习的模型(function),当然目的是要得到 good estimator。

  • Function Estimation

    • 机器学习算法学习到的模型实际上就是一个 function,Point Estimation 做的是找到 function 的parameters,而从某种角度上说其实就是在找这个 function。

5.4.2 Bias

  • Bias
    • 衡量模型拟合训练数据的能力(训练数据不一定是整个 training dataset,而是只用于训练它的那一部分数据,例如:mini-batch)。
    • bias越小,拟合能力越高(可能产生overfitting);反之,拟合能力越低(可能产生underfitting)。
    • 注意,bias是针对一个模型来说的,这一点与variance不同。

这点还是比较好理解的,并且bias翻译成偏差,从字面意思也可以看出是和某个值的偏离程度,而这个某个值在机器学习算法中就是整个数据的期望值

5.4.3 Variance and Standard Error

  • Variance

    • 衡量模型的 generalization 的能力。
    • variance越小,模型的 generalization 的能力越高;反之,模型的 generalization 的能力越低。
    • 它是针对多个模型来说的,针对多个模型来说是什么意思?看下面的分析。
  • 在训练模型的时候不是一下子在整个 training dataset 上进行训练,而是采用从 training dataset 中 sample 数据点的方式来进行训练(例如:mini-batch)。

    因为都是从同一个数据集 sample 数据点,所以 sample 的数据点可以保证都是同分布的。但是也正因为 sample 的数据点的不同,很可能会生成不同的模型。

    举例来说,假设这里进行了4次 sample 数据点,并在得到的 mini-batch 的数据集上进行算法的训练,得到的模型如下图所示。

    Chapter 5 Machine Learning Basics

    那么你认为这样的结果好吗?肯定是不好的啊,因为算法每次学习到的模型都不一样,这说明算法无法学习到数据的 distribution 规律,那还怎么来进行预测?

    我们期望的结果是:每次不管怎么 sample 数据点,算法学习到的模型都不会变化太大(比如:都是直线,或者都是二次曲线)。这样的话说明算法能很好的学习到数据的 distribution 规律,那么如果来了新的数据(同分布),算法学习到的模型就能够很好的进行 predict(说明模型的 generalization 能力好)。

    而`variance`就是衡量每次在不同 mini-batch 数据上训练生成的不同模型之间的差异性大小的度量值。

    大专栏

上一篇:一言不合就删库跑路?万名贡献者和阿里巴巴开源的二三事


下一篇:book-rev8 Chapter 0 Operating system interfaces