比單獨使用train_test_split來划分數據更嚴謹
stratify是為了保持split前類的分布。比如有100個數據,80個屬於A類,20個屬於B類。如果train_test_split(... test_size=0.25, stratify = y_all), 那么split之后數據如下:
training: 75個數據,其中60個屬於A類,15個屬於B類。
testing: 25個數據,其中20個屬於A類,5個屬於B類。
用了stratify參數,training集和testing集的類的比例是 A:B= 4:1,等同於split前的比例(80:20)。通常在這種類分布不平衡的情況下會用到stratify。
這個參數sklearn的文檔4中講的不是太清楚
幫助文檔
http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html