關於神經網絡中過擬合的問題

關於神經網絡中過擬合的問題小記。

在訓練的時候你的模型是否會出現訓練時速度很慢?或者預測結果與訓練結果相差過大的現象?那我們可能就需要處理一下過擬合的問題了。

首先看一下overfitting維基百科上的一些信息:
Overfitting occurs when a model is excessively complex, such as having too many parameters relative to the number of observations. A model that has been overfit has poor predictive performance, as it overreacts to minor fluctuations in the training data.

In particular, a model is typically trained by maximizing its performance on some set of training data. However, its efficacy is determined not by its performance on the training data but by its ability to perform well on unseen data

The potential for overfitting depends not only on the number of parameters and data but also the conformability of the model structure with the data shape, and the magnitude of model error compared to the expected level of noise or error in the data.
從以上兩段可以稍微總結一下,當你的模型過於複雜時,比如說輸入參數過多,你的模型就會出現過擬合問題,該模型雖然會在訓練集上表現出較好的預測結果,然而!在預測的時候呢?預測結果就會表現的很差。根據維基的定義以及我平時的一些實驗總結,當你observation 的noise 過多,輸入維度過大,都可能會導致overfitting。

解決辦法就是我們可以啓用交叉驗證(cross-validation),正則化(regularization),Early Stopping,剪枝(pruning),Bayesian priors這幾種方法。

先說cross-validation
cross-validation 的原理就是現在它的一個子集上做訓練,這個子集就是訓練集,再用驗證集測試所訓練出的模型,來評價模型的性能和指標,最後再用測試集來預測。

Early Stopping就是在每次訓練的epoch結束時,將計算出的accuracy 跟上一次的進行比較,如果accuracy 不再變化,那麼停止訓練。

下面主要說下regularization 在NN中的作用:

模型假設三層,輸入,隱藏,輸出。輸入層爲2個神經元,輸出爲2個,batchsize爲10,下圖爲當隱藏層神經元個數分別設置爲3,6,20時,模型的情況:
這裏寫圖片描述
注意看當隱藏神經元爲20時,模型的狀況,每個紅色的點都被完美的歸類,沒錯,這在訓練時結果是很好,但是在測試集的表現呢?這就不一定了,誰能保證自己的訓練結每點噪聲呢?是不是?所以用這個模型去預測未知的,就可能造成預測結果很差,這就是NN的overfitting問題。

所以一般大部分情況,我們在調試模型時很多時候是在跟overfitting做鬥爭。關於regularization 方法。

簡單來說就是在目標函數上加一個λ 使之變成 Error+λf(θ)λ 用來懲罰那些權重很大的向量,稱之爲正則係數吧!λ=0 就意味着沒有采用regularization來預防overfitting。

regularization 有 L1 regularization和L2 regularization。如果你想知道哪一個特徵對最後的結果產生了比較大的影響,可以採用L1 regularization,如果你不那麼在意對特徵的分析,那就用L2 regularization吧。

參考資料:
http://www.kdnuggets.com/2015/04/preventing-overfitting-neural-networks.html/2
https://en.wikipedia.org/wiki/Overfitting#cite_note-1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章