本地驗證

用 Python 拿下 Kaggle 競賽

Yauhen Babakhin

Kaggle Grandmaster

動機

過擬合範例:Public 與 Private 排行榜

用 Python 拿下 Kaggle 競賽

留出集(Holdout set)

留出集示意圖

用 Python 拿下 Kaggle 競賽

留出集(Holdout set)

留出集示意圖

用 Python 拿下 Kaggle 競賽

留出集(Holdout set)

留出集示意圖

用 Python 拿下 Kaggle 競賽

K 折交叉驗證

 

將訓練資料切成四個摺疊

用 Python 拿下 Kaggle 競賽

K 折交叉驗證

 

K 折交叉驗證示意圖

用 Python 拿下 Kaggle 競賽

K 折交叉驗證

# Import KFold
from sklearn.model_selection import KFold
# Create a KFold object
kf = KFold(n_splits=5, shuffle=True, random_state=123)
# Loop through each cross-validation split
for train_index, test_index in kf.split(train):

# Get training and testing data for the corresponding split cv_train, cv_test = train.iloc[train_index], train.iloc[test_index]
用 Python 拿下 Kaggle 競賽

分層 K 折

  分層 K 折交叉驗證示意圖

用 Python 拿下 Kaggle 競賽

分層 K 折

# Import StratifiedKFold
from sklearn.model_selection import StratifiedKFold

# Create a StratifiedKFold object str_kf = StratifiedKFold(n_splits=5, shuffle=True, random_state=123)
# Loop through each cross-validation split for train_index, test_index in str_kf.split(train, train['target']): cv_train, cv_test = train.iloc[train_index], train.iloc[test_index]
用 Python 拿下 Kaggle 競賽

一起來練習吧!

用 Python 拿下 Kaggle 競賽

Preparing Video For Download...