모델과 손실 함수 정의하기
이 연습 문제에서는 신경망을 학습시켜 신용카드 보유자가 연체(default)할지 예측해 볼 거예요. 네트워크를 학습하는 데 사용할 특성과 타깃은 Python 셸의 borrower_features와 default로 제공돼요. 가중치와 편향은 이전 연습 문제에서 정의했어요.
predictions 레이어는 $\sigma(layer1*w2+b2)\(로 정의되어 있으며, 여기서 \)\sigma$는 시그모이드 활성화 함수이고, layer1은 첫 번째 은닉 밀집 레이어의 노드 텐서, w2는 가중치 텐서, b2는 편향 텐서예요.
학습 가능한 변수는 w1, b1, w2, b2예요. 추가로, 다음 연산이 미리 임포트되어 있어요: keras.activations.relu()와 keras.layers.Dropout().
이 연습은 강의의 일부입니다
Python으로 시작하는 TensorFlow
연습 안내
- 첫 번째 레이어에 정류 선형 유닛(ReLU) 활성화 함수를 적용하세요.
layer1에 25% 드롭아웃을 적용하세요.- 교차 엔트로피 손실 함수에 타깃
targets와 예측값predictions를 전달하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define the model
def model(w1, b1, w2, b2, features = borrower_features):
# Apply relu activation functions to layer 1
layer1 = keras.activations.____(matmul(features, w1) + b1)
# Apply dropout rate of 0.25
dropout = keras.layers.Dropout(____)(____)
return keras.activations.sigmoid(matmul(dropout, w2) + b2)
# Define the loss function
def loss_function(w1, b1, w2, b2, features = borrower_features, targets = default):
predictions = model(w1, b1, w2, b2)
# Pass targets and predictions to the cross entropy loss
return keras.losses.binary_crossentropy(____, ____)