本地验证

用 Python 赢下 Kaggle 竞赛

Yauhen Babakhin

Kaggle Grandmaster

动机

过拟合示例:公共与私有排行榜

用 Python 赢下 Kaggle 竞赛

留出集

留出集示意图

用 Python 赢下 Kaggle 竞赛

留出集

留出集示意图

用 Python 赢下 Kaggle 竞赛

留出集

留出集示意图

用 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 竞赛

Passons à la pratique !

用 Python 赢下 Kaggle 竞赛

Preparing Video For Download...