訓練集、驗證集和測試集這三個名詞在機器學習領域極其常見,但很多人并不是特别清楚,尤其是後兩個經常被人混用。
在有監督(supervise)的機器學習中,資料集常被分成2~3個,即:訓練集(train set),驗證集(validation set),測試集(test set)。

Ripley, B.D(1996)在他的經典專著Pattern Recognition and Neural Networks中給出了這三個詞的定義。
Training set: A set of examples used for learning, which is to fit the parameters [i.e., weights] of the classifier.
Validation set: A set of examples used to tune the parameters [i.e., architecture, not weights] of a classifier, for example to choose the number of hidden units in a neural network.
Test set: A set of examples used only to assess the performance [generalization] of a fully specified classifier.
作用:估計模型
學習樣本資料集,通過比對一些參數來建立一個分類器。建立一種分類的方式,主要是用來訓練模型的。
作用:确定網絡結構或者控制模型複雜程度的參數
對學習出來的模型,調整分類器的參數,如在神經網絡中選擇隐藏單元數。驗證集還用來确定網絡結構或者控制模型複雜程度的參數。
作用:檢驗最終選擇最優的模型的性能如何
主要是測試訓練好的模型的分辨能力(識别率等)
Ripley也談到了這個問題:Why separate test and validation sets?
1. The error rate estimate of the final model on validation data will be biased (smaller than the true error rate) since the validation set is used to select the final model.
2. After assessing the final model with the test set, YOU MUST NOT tune the model any further.
簡而言之,為了防止過度拟合。如果我們把所有資料都用來訓練模型的話,建立的模型自然是最契合這些資料的,測試表現也好。但換了其它資料集測試這個模型效果可能就沒那麼好了。就好像你給班上同學做校服,大家穿着都合适你就覺得按這樣做就對了,那給别的班同學穿呢?不合适的機率會高吧。總而言之訓練集和測試集相同的話,模型評估結果可能比實際要好。
顯然,training set是用來訓練模型或确定模型參數的,如ANN中權值等; validation set是用來做模型選擇(model selection),即做模型的最終優化及确定的,如ANN的結構;而 test set則純粹是為了測試已經訓練好的模型的推廣能力。當然,test set這并不能保證模型的正确性,他隻是說相似的資料用此模型會得出相似的結果。但實際應用中,一般隻将資料集分成兩類,即training set 和test set,大多數文章并不涉及validation set。
一個典型的劃分是訓練集占總樣本的50%,而其它各占25%,三部分都是從樣本中随機抽取。
樣本少的時候,上面的劃分就不合适了。常用的是留少部分做測試集。然後對其餘N個樣本采用K折交叉驗證法。就是将樣本打亂,然後均勻分成K份,輪流選擇其中K-1份訓練,剩餘的一份做驗證,計算預測誤差平方和,最後把K次的預測誤差平方和再做平均作為選擇最優模型結構的依據。特别的K取N,就是留一法(leave one out)。
附上一段僞代碼: