즐거운프로그래밍

[딥러닝] 사용자 데이터로 CNN 학습하기- 4. 훈련, 검증, 시험 데이터 분리하기

수수께끼 고양이 2023. 11. 6. 10:39
728x90
반응형

 

4. 훈련, 검증, 시험 데이터 분리하기.

훈련 데이터 80%, 검증 데이터 10%, 시험 데이터 10%로 임의로 분리합니다.

훈련 데이터는 인공신경망 학습에 사용

검증 데이터는 학습 도중에 검증용으로 사용

시험 데이터는 학습이 끝난 후에 사용합니다.

 

_04_cnn_training_3.py

from _04_cnn_training_1 import *

from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split

tensors=tensors.astype('float32')/255
targets=to_categorical(targets, 4)

x_train, x_test, y_train, y_test=train_test_split(
    tensors,
    targets,
    test_size=0.2,
    random_state=1)

n=int(len(x_test)/2)
x_valid, y_vaild=x_test[:n], y_test[:n]
x_test, y_test=x_test[n:], y_test[n:]

print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)
print(x_valid.shape, y_vaild.shape)

 

 

 

 

 

 

 

728x90
반응형