反覆迭代但不過度擬合

在 Python 設計機器學習工作流程

Dr. Chris Anagnostopoulos

Honorary Associate Professor

示意圖:機器學習 pipeline 推上線後仍可持續調校。

在 Python 設計機器學習工作流程

同一張示意圖:可從上線環境擷取更多資料,協助進一步調校模型。

在 Python 設計機器學習工作流程

同一張示意圖:領域專家可提供新見解,可能改變模型,例如新的 loss 函式。

在 Python 設計機器學習工作流程

同一張示意圖:上線中的模型標為 champion,開發中的標為 challenger。

在 Python 設計機器學習工作流程

交叉驗證結果

grid_search = GridSearchCV(pipe, params, cv=3, return_train_score=True)
gs = grid_search.fit(X_train, y_train)
results = pd.DataFrame(gs.cv_results_)
results[['mean_train_score', 'std_train_score', 
   'mean_test_score', 'std_test_score']]
   mean_train_score  std_train_score  mean_test_score  std_test_score
0             0.829            0.006            0.735           0.009
1             0.829            0.006            0.725           0.009
2             0.961            0.008            0.716           0.019
3             0.981            0.005            0.749           0.024
...
在 Python 設計機器學習工作流程

交叉驗證結果

   mean_train_score  std_train_score  mean_test_score  std_test_score
0             0.829            0.006            0.735           0.009
1             0.829            0.006            0.725           0.009
2             0.961            0.008            0.716           0.019
3             0.981            0.005            0.749           0.024
4             0.986            0.003            0.728           0.009
5             0.995            0.002            0.751           0.008

觀察:

  • 訓練分數遠高於測試分數。
  • 測試分數的標準差很大。
在 Python 設計機器學習工作流程

資料集分成 training 與 test,且 training 透過交叉驗證再切成多塊。

在 Python 設計機器學習工作流程

資料集分成 training 與 validation,且 training 透過交叉驗證再切成多塊。

在 Python 設計機器學習工作流程

偵測過度擬合

  • CV 訓練分數 >> CV 測試分數
    • 模型擬合階段的過度擬合
    • 降低分類器複雜度
    • 增加訓練資料
    • 提高 CV 次數
  • CV 測試分數 >> 驗證分數
    • 模型調參階段的過度擬合
    • 降低 CV 次數
    • 縮小參數網格

資料集分成 training 與 validation,且 training 透過交叉驗證再切成多塊。

在 Python 設計機器學習工作流程

資料集分成 training 與 validation,且 training 透過交叉驗證再切成多塊。

在 Python 設計機器學習工作流程

資料集分成 training、validation 與 production 資料,且 training 透過交叉驗證再切成多塊。

在 Python 設計機器學習工作流程

把「CV 專家」寫進你的 CV!

在 Python 設計機器學習工作流程

Preparing Video For Download...