왜 이 코드를 실행하나요? 데이터가 깨지지 않고 잘 들어왔는지 눈으로 확인하고, 이 데이터를 공부용(Train)과 시험용(Test)으로 엄격하게 분리하여 모델을 평가할 준비를 합니다.
y = np.array(all_labels)
# 라벨 리스트를 계산용 배열로 변환해요.
import matplotlib.pyplot as plt
plt.imshow(all_images[0])
# 첫 번째 사진이 무엇인지 도화지에 그려봐요.
plt.show()
# 그림을 화면에 출력해요.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, shuffle=True, random_state=0)
# 데이터를 8:2 비율로 훈련/테스트용으로 나눠요.
X_train.shape, X_test.shape, y_train.shape, y_test.shape
# 나눠진 4개 뭉치의 크기를 각각 찍어서 확인해요.
실제 출력
X_train: (190, 96, 96, 3), X_test: (48, 96, 96, 3)
y_train: (190,), y_test: (48,)
출력 해설: 공부용(Train)과 시험용(Test)이 8:2 비율로 정확히 분할되었습니다.