1. 程式人生 > >機器學習工具之交叉驗證資料集自動劃分train_test_split

機器學習工具之交叉驗證資料集自動劃分train_test_split

機器學習工具之交叉驗證資料集自動劃分

1. 使用方式:

from sklearn.model_selection import train_test_split

x_train,x_test,y_train,y_test=train_test_split

(train_data,train_lable,test_size=0.3,random_state=o,stratify=train_lable)

注意:stratify一般用於非平衡資料按train_lable的比例分層,多用於分類

2 . 引數介紹

train_data:樣本特徵集

train_target:樣本的標籤集

test_size:樣本佔比,測試集佔資料集的比重,如果是整數的話就是樣本的數量

random_state:是隨機數的種子。在同一份資料集上,相同的種子產生相同的結果,不同的種子產生不同的劃分結果

X_train,y_train:構成了訓練集

X_test,y_test:構成了測試集