ML科普系列(一)訓練集、測試集和驗證集

訓練集驗證集測試集這三個名詞在機器學習領域極其常見,但不少人並非特別清楚,尤爲是後兩個常常被人混用。網絡

在有監督(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.

訓練集

做用:估計模型學習

學習樣本數據集,經過匹配一些參數來創建一個分類器。創建一種分類的方式,主要是用來訓練模型的。測試

驗證集

做用:肯定網絡結構或者控制模型複雜程度的參數優化

對學習出來的模型,調整分類器的參數,如在神經網絡中選擇隱藏單元數。驗證集還用來肯定網絡結構或者控制模型複雜程度的參數。spa

測試集

做用:檢驗最終選擇最優的模型的性能如何code

主要是測試訓練好的模型的分辨能力(識別率等)orm

爲什麼須要劃分

Ripley也談到了這個問題:Why separate test and validation sets? blog

  • 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)。

附上一段僞代碼:

for each epoch
    for each training data instance
        propagate error through the network
        adjust the weights
        calculate the accuracy over training data
    for each validation data instance
        calculate the accuracy over the validation data
    if the threshold validation accuracy is met
        exit training
    else
        continue training
相關文章
相關標籤/搜索