인공지능/데이터 전처리

[데이터 전처리] Training/Test용 데이터 분리 train_test_split()

건휘맨 2024. 4. 12. 17:35
from sklearn.model_selection import train_test_split

 

train_test_split() : 데이터셋을 학습용과 테스트용으로 나눈다.

>>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=32)

>>> X_train
array([[1.        , 0.        , 0.        , 0.73913043, 0.68571429],
       [0.        , 1.        , 0.        , 0.13043478, 0.17142857],
       [1.        , 0.        , 0.        , 0.34782609, 0.28571429],
       [1.        , 0.        , 0.        , 0.91304348, 0.88571429],
       [0.        , 0.        , 1.        , 0.47826087, 0.37142857],
       [1.        , 0.        , 0.        , 0.43478261, 0.54285714]])
       
>>> y_train
array([0, 0, 1, 1, 0, 1])

>>> X_test
array([[0., 1., 0., 1., 1.],
       [0., 0., 1., 0., 0.]])
       
>>> y_test
array([0, 1])