네트워크에 레이어 추가하기
더 넓은 네트워크로 실험하는 방법을 보셨죠. 이번 연습에서는 더 깊은 네트워크(은닉층을 더 많이 가지는 모델)를 시도해 보겠습니다.
시작점으로 기준 모델 model_1이 제공됩니다. 이 모델에는 10개 유닛을 가진 은닉층이 1개 있습니다. 해당 모델 구조 요약이 출력되어 있어요. 이제 각 레이어에 10개 유닛을 유지하면서, 은닉층을 3개로 늘린 비슷한 네트워크를 만들어 보겠습니다.
두 모델을 학습하는 데 다시 잠시 시간이 걸리므로, 코드를 실행한 뒤 결과가 표시될 때까지 몇 초 정도 기다려 주세요.
이 연습은 강의의 일부입니다
Python으로 시작하는 Deep Learning
연습 안내
model_1과 비슷하지만, 10개 유닛의 은닉층을 1개가 아닌 3개 갖는model_2를 정의하세요.- 첫 번째 은닉층에서
input_shape로 입력 형태를 지정하세요. - 3개의 은닉층에는
'relu'활성화 함수를, 2개 유닛을 갖는 출력층에는'softmax'를 사용하세요.
- 첫 번째 은닉층에서
- 이전과 마찬가지로
model_2를 컴파일하세요:optimizer는'adam', 손실 함수는'categorical_crossentropy',metrics=['accuracy']를 사용합니다. - 두 모델을 학습하고 어떤 모델이 더 좋은 성능을 내는지 시각화하려면 'Submit Answer'를 누르세요!
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# The input shape to use in the first hidden layer
input_shape = (n_cols,)
# Create the new model: model_2
model_2 = ____
# Add the first, second, and third hidden layers
____
____
____
# Add the output layer
____
# Compile model_2
____
# Fit model 1
model_1_training = model_1.fit(predictors, target, epochs=15, validation_split=0.4, verbose=False)
# Fit model 2
model_2_training = model_2.fit(predictors, target, epochs=15, validation_split=0.4, verbose=False)
# Create the plot
plt.plot(model_1_training.history['val_loss'], 'r', model_2_training.history['val_loss'], 'b')
plt.xlabel('Epochs')
plt.ylabel('Validation score')
plt.show()