對於過擬合現象
\[{h_\theta }\left( x \right) = {\theta _0} + {\theta _1}x + {\theta _2}{x^2} + {\theta _3}{x^3} + {\theta _4}{x^4}\]
Once parameters θ0,θ1,θ2,θ3,θ4 were fit to some set of data (training set), the error of the parameters as measured on that data (the training error J(θ)) is likely to be lower than the actual generalization error.
一旦參數θ0,θ1,θ2,θ3,θ4適合某些數據集(訓練集),在該數據上測量的參數誤差(訓練誤差J(θ))可能低於實際值泛化錯誤(在測試集上的錯誤)。
假設又如下模型
\[\begin{array}{l}
{h_\theta }\left( x \right) = {\theta _0} + {\theta _1}x\\
{h_\theta }\left( x \right) = {\theta _0} + {\theta _1}x + {\theta _2}{x^2}\\
.\\
.\\
.\\
{h_\theta }\left( x \right) = {\theta _0} + {\theta _1}x + ... + {\theta _{10}}{x^{10}}
\end{array}\]
該選擇哪一個?
一般情況下我們會用以下步驟選擇模型
- 運用訓練集訓練模型得到參數θ
- 將不同模型得到的假設函數運用於測試集
- 找出在測試集中誤差最小的模型
這樣做的問題在於你的模型選擇依賴於測試集,你是根據模型對於測試集的表現選擇模型的,這樣做對於新的數據表現如何並不能很好的保障。
解決方法是
將數據分為訓練集(Training set)60%、交叉驗證集(Cross validation set)20%、測試集(Test set)20%。
運用交叉驗證集去選取模型,而不是測試集。