训练集&验证机&测试集

当前机器学习主要分为监督学习和无监督学习,监督学习在训练的过程中,需要大量有标注的数据,而其中就涉及到了训练集、验证集、测试集的概念

划分

拿到数据集后,首先需要对数据集进行划分,通常采取8:1:1的比例,当然比例可以是根据实际需要调整的;同时通常采取均匀随机抽样的方法,使得三个集合的分布都是相同的,这一点是很必要的

如果是做比赛,官方只提供了一个标注的数据集(作为训练集)以及一个没有标注的测试集,那么我们做模型的时候,通常会人工从训练集中划分一个验证集出来。这时候我们通常不再划分一个测试集,可能的原因有两个:1、比赛方基本都很抠,训练集的样本本来就少;2、我们也没法保证要提交的测试集是否跟训练集完全同分布,因此再划分一个跟训练集同分布的测试集就没多大意义了。

为什么有了验证集还需要测试集

有了模型后,训练集就是用来训练参数,即用于梯度下降,而每次epoch后更新参数,包括普通参数超参数
普通参数比如各个节点的权重等,是经过训练而得到的,就是可以被梯度下降所更新的,也就是训练集所更新的;超参数,比如网络的层数和节点的个数、迭代次数、学习速率等等,是不在梯度下降更新的范围内的,所以可以通过验证集的结果来调整这些参数,那么实际上,验证集也算作是参与了超参数的训练。
所以,我们还是需要一个完全没有经过任何训练的集合,也就是测试集,用于真正评估最后的准确率。

虽然,我们也能发现,我们也可能通过最后的测试集结果再调整结构、参数等等,那么不就再次陷入了上述的情景,但是事实上:一是,我们不可能无限制的划分加入新的集合,二是,我认为,如果是调整完结构后,应该需要重新进行训练、验证、测试,评估自然也需要重新开始,也就能够逐渐消除影响。

其实在验证集之外还有测试集的目的,就在于使其最后评价出来的最优模型是无偏的(unbias)的,这个我觉得wiki写的很好:

  • The model is initially fit on a training dataset,[3] which is a set of examples used to fit the parameters (e.g. weights of connections between neurons in artificial neural networks) of the model.
  • Successively, the fitted model is used to predict the responses for the observations in a second dataset called the validation dataset.[3] The validation dataset provides an unbiased evaluation of a model fit on the training dataset while tuning the model’s hyperparameters)[5] (e.g. the number of hidden units (layers and layer widths) in a neural network[4]).
  • Finally, the test dataset is a dataset used to provide an unbiased evaluation of a final model fit on the training dataset.[5] If the data in the test dataset has never been used in training (for example in cross-validation)), the test dataset is also called a holdout dataset. The term “validation set” is sometimes used instead of “test set” in some literature (e.g., if the original dataset was partitioned into only two subsets, the test set might be referred to as the validation set).[5]

训练epoch、iteraation、batch

iteration:数据进行一次前向-后向的训练(更新一次参数
batchsize:每次iteration训练的样本数量
epoch:将所有样本通过训练一次
例如:
假如有1280000张图片,batchsize=256,则1个epoch需要1280000/256=5000次iteration,假如它的max-iteration=450000,则共有450000/5000=90个epoch

0%