1. 程式人生 > >python 把資料分成訓練集和測試集

python 把資料分成訓練集和測試集

from sklearn.model_selection import train_test_split
import pandas as pd

f1=pd.read_excel('aaa.xlsx')

f1.columns
#Index(['X', 'Y'], dtype='object')

X_train,X_test,y_train,y_test = train_test_split(X,Y,test_size=0.3)

X_train: 訓練集X
y_train: 訓練集Y
X_test:測試集X
y_test:測試集Y
train_test_split:切割樣本
test_size=0.3:選取樣本30%作為測試集的數量