留一法交叉驗證(LOOCV)

Python 的模型驗證

Kasey Jones

Data Scientist

LOOCV

LOOCV 是將資料切分為 n 次,n 為資料中的觀測數。這是將交叉驗證做得最極端的方式。我們必須執行總共 n 個模型。

Python 的模型驗證

何時使用 LOOCV?

適用於:

  • 訓練資料量有限
  • 你想為新資料取得最準確的誤差估計

注意事項:

  • 計算資源有限
  • 資料量很大
  • 需測試的參數很多
Python 的模型驗證

LOOCV 範例

n = X.shape[0]
mse = make_scorer(mean_squared_error)
cv_results = cross_val_score(estimator, X, y, scoring=mse, cv=n)
print(cv_results)
[5.45, 10.52, 6.23, 1.98, 11.27, 9.21, 4.65, ... ]
print(cv_results.mean())
6.32
Python 的模型驗證

一起來練習吧!

Python 的模型驗證

Preparing Video For Download...