天天看點

[機器學習筆記] 機器學習中的“過拟合(Overfitting)”和“欠拟合(Underfitting)”

機器學習中的“過拟合(Overfitting)”和“欠拟合(Underfitting)”

在機器學習領域中,當讨論一個機器學習模型學習和泛化的好壞時,通常使用術語是:過拟合(Overfitting)和欠拟合(Underfitting)。過拟合和欠拟合是機器學習算法表現差的兩大原因。

什麼是過拟合和欠拟合?

過拟合(overfitting):是指在模型參數拟合過程中的問題,由于訓練資料包含抽樣誤差,訓練時,複雜的模型将抽樣也考慮在内,将抽樣誤差也進行了很好的拟合。具體表現就是最終模型在訓練集上效果好;在測試集上效果差。模型泛化能力弱。

拟合的模型一般是用來預測未知的結果(不在訓練集内),過拟合雖然在訓練集上效果好,但是在實際使用時(測試集)效果差。同時,在很多問題上,我們無法窮盡所有狀态,不可能将所有情況都包含在訓練集上。是以,必須要解決過拟合問題。

欠拟合(Underfitting):是指模型不能在訓練集上獲得足夠低的誤差。

簡單來說,當學習器把訓練樣本學得“太好了”的時候,很可能已經把訓練樣本自身的一些特點當作了所有潛在的樣本都會具有的性質,這樣就導緻泛化性能下降,這就是“過拟合(Overfitting)”;與之相對的是“欠拟合(Underfitting)”,這是指對訓練樣本的一般性質尚未學好。《機器學習》(周志華,清華大學出版社,P23.)

在神經網絡訓練的過程中,欠拟合主要表現為輸出結果的高偏差,而過拟合主要表現為輸出結果的高方差。

過拟合和欠拟合的簡單判斷标準

訓練集上的表現 測試集上的表現 判定結果
不好 不好 欠拟合(欠配)
不好 過拟合(過配)
适度拟合

過拟合的産生原因和解決方法

常見原因

  • 模組化樣本選取有誤,如樣本數量太少,選樣方法錯誤,樣本标簽錯誤等,導緻選取的樣本資料不足以代表預定的分類規則
  • 樣本噪音幹擾過大,使得機器将部分噪音認為是特征進而擾亂了預設的分類規則;
  • 假設的模型無法合理存在,或者說是假設成立的條件實際并不成立;
  • 參數太多,模型複雜度過高;
  • 對于決策樹模型,如果我們對于其生長沒有合理的限制,其自由生長有可能使節點隻包含單純的事件資料(event)或非事件資料(no event),使其雖然可以完美比對(拟合)訓練資料,但是無法适應其他資料集。
  • 對于神經網絡模型:

1)對樣本資料可能存在分類決策面不唯一,随着學習的進行,,BP算法使權值可能收斂過于複雜的決策面;

2)權值學習疊代次數足夠多(Overtraining),拟合了訓練資料中的噪聲和訓練樣例中沒有代表性的特征。

解決方法

  • 在神經網絡模型中,可使用權值衰減的方法,即每次疊代過程中以某個小因子降低每個權值。
  • 選取合适的停止訓練标準,使對機器的訓練在合适的程度;
  • 保留驗證資料集,對訓練成果進行驗證;
  • 擷取額外資料進行交叉驗證;
  • 正則化,即在進行目标函數或代價函數優化時,在目标函數或代價函數後面加上一個正則項,一般有L1正則與L2正則等。

欠拟合的産生原因和解決方法

常見原因

  • 模型複雜度過低
  • 特征量過少

解決方法

欠拟合的情況比較容易克服, 常見解決方法有:

  • 增加新特征,可以考慮加入進特征組合、高次特征,來增大假設空間;
  • 添加多項式特征,這個在機器學習算法裡面用的很普遍,例如将線性模型通過添加二次項或者三次項使模型泛化能力更強;
  • 減少正則化參數,正則化的目的是用來防止過拟合的,但是模型出現了欠拟合,則需要減少正則化參數;
  • 使用非線性模型,比如核SVM 、決策樹、深度學習等模型;
  • 調整模型的容量(capacity),通俗地,模型的容量是指其拟合各種函數的能力;
  • 容量低的模型可能很難拟合訓練集;使用內建學習方法,如Bagging ,将多個弱學習器Bagging。

名詞解釋:泛化能力

泛化能力(Generalization Ability)是指機器學習算法對新鮮樣本的适應能力。

學習的目的是學到隐含在資料對背後的規律,對具有同一規律的學習集以外的資料,經過訓練的網絡也能給出合适的輸出,該能力稱為泛化能力。通常期望經訓練樣本訓練的網絡具有較強的泛化能力,也就是對新輸入給出合理響應的能力。應當指出并非訓練的次數越多越能得到正确的輸入輸出映射關系。網絡的性能主要用它的泛化能力來衡量。 

機器學習中的偏差和方差的了解

在機器學習中,偏差描述的是根據樣本拟合出的模型輸出結果與真實結果的差距,損失函數就是依據模型偏差的大小進行反向傳播的。降低偏差,就需要複雜化模型,增加模型參數,但容易造成過拟合。方差描述的是樣本上訓練出的模型在測試集上的表現,降低方差,繼續要簡化模型,減少模型的參數,但容易造成欠拟合。根本原因是,我們總是希望用有限的訓練樣本去估計無限的真實資料。假定我們可以獲得所有可能的資料集合,并在這個資料集上将損失函數最小化,則這樣的模型稱之為“真實模型”。但實際應用中,并不能獲得且訓練所有可能的資料,是以真實模型一定存在,但無法獲得

補充一段Overfitting和Underfitting的英文的說明:

Overfitting occurs when a statistical model or machine learning algorithm captures the noise of the data.  Intuitively, overfitting occurs when the model or the algorithm fits the data too well.  Specifically, overfitting occurs if the model or algorithm shows low bias buthigh variance.  Overfitting is often a result of an excessively complicated model, and it can be prevented by fitting multiple models and using validation or cross-validation to compare their predictive accuracies on test data.

Underfitting occurs when a statistical model or machine learning algorithm cannot capture the underlying trend of the data.  Intuitively, underfitting occurs when the model or the algorithm does not fit the data well enough.  Specifically, underfitting occurs if the model or algorithm shows low variance but high bias.  Underfitting is often a result of an excessively simple model.

Both overfitting and underfitting lead to poor predictions on new data sets.

以下内容參考:

refer from http://www.analyticbridge.com/profiles/blogs/underfitting-overfitting-problem-in-m-c-learning

Underfitting : 

If our algorithm works badly with points in our data set, then the algorithm underfitting the data set. It can be check easily throug the cost function measures. Cost function in linear regression is half the mean squared error ex. if mean squared error is c the cost fucntion is 0.5C 2. If in an experiment cost ends up high even after many iterations, then chances are we have an underfitting problem. We can say that learning algorithm is not good for the problem. Underfitting is also known as high bias( strong bias towards its hypothesis). In an another words we can say that hypothesis space the learning algorithm explores is too small to properly represent the data.

How to avoid underfitting :

More data will not generally help. It will, in fact, likely increase the training error. Therefore we should increase more features. Because that expands the hypothesis space. This includes making new features from existing features. Same way more parameteres may also expand the hypothesis space.

Overfitting : 

If our algorithm works well with points in our data set, but not on new points, then the algorithm overfitting the data set. Overfitting check easily through by spliting the data set so that 90% of data in our training set and 10% in a cross-validation set. Train on the training set, then measure the cost on the cross-validation set. If the cross-validation cost is much higher than the training cost, then chances are we have an overfitting problem. In another words we can say that hypothesis space is too large, and perhaps some features are faking the learning algorithm out.

How to avoid overfitting :

To avoid overfitting add the regularization if there are many features. Regularization forces the magnitudes of the parameters to be smaller(shrinking the hypothesis space). For this add a new term to the cost function