훈련과 검증 데이터셋의 정규화도 마쳤으니 모델 훈련을 진행해 봅시다. 다음 코드는 앞서 사용했던 코드와 동일하며, 단지 데이터셋의 정규화 유무만 다릅니다.

    코드 9-31 데이터셋 로딩 및 모델 훈련

    model = tf.keras.Sequential([
        tf.keras.layers.Dense(64, activation='relu',
                              input_shape=(x_train.shape[1],)),
        tf.keras.layers.Dense(64, activation='relu'),
        tf.keras.layers.Dense(8, activation='softmax')
    ])
    
    model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])
    history2 = model.fit(
        x_train, y_train,
        epochs=26, batch_size=60,
        validation_data=(x_test, y_test))
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.