sklearn.model_selectionのtrain_test_split使用方法、データセットの分割、トレーニングセットとテストセットの分割

1826 ワード

import numpy as np
from sklearn.model_selection import train_test_split


X = np.load("./data/111.npy")
y = np.load("./data/222.npy")


print(X.shape)
print(y.shape)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)          #test_size 20%

print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)
np.save("./data/train_data.npy",X_train)      
np.save("./data/test_data.npy",X_test)        
np.save("./data/train_label.npy",y_train)
np.save("./data/test_label.npy",y_test)
print("save end")