활성화 함수

Python으로 시작하는 TensorFlow

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

활성화 함수란?

  • 일반적인 은닉층의 구성 요소
    • 선형: 행렬 곱셈
    • 비선형: 활성화 함수
Python으로 시작하는 TensorFlow

비선형성이 중요한 이유

이 그림은 청구 금액과 나이로 부도를 예측하는 단순 네트워크를 보여줍니다.

Python으로 시작하는 TensorFlow

비선형성이 중요한 이유

이 그림은 30세 이하 차주에 대해 신용카드 청구 금액과 부도 간의 관계를 보여줍니다.

Python으로 시작하는 TensorFlow

간단한 예시

import numpy as np
import tensorflow as tf

# 예시 차주 특성 정의
young, old = 0.3, 0.6
low_bill, high_bill = 0.1, 0.5
# 모든 특성 조합에 행렬 곱셈 단계 적용
young_high = 1.0*young + 2.0*high_bill
young_low = 1.0*young + 2.0*low_bill
old_high = 1.0*old + 2.0*high_bill
old_low = 1.0*old + 2.0*low_bill
Python으로 시작하는 TensorFlow

간단한 예시

# 젊은 층의 부도 예측 차이
print(young_high - young_low)

# 고령층의 부도 예측 차이
print(old_high - old_low)
0.8 
0.8
Python으로 시작하는 TensorFlow

간단한 예시

# 젊은 층의 부도 예측 차이
print(tf.keras.activations.sigmoid(young_high).numpy() - 
tf.keras.activations.sigmoid(young_low).numpy())

# 고령층의 부도 예측 차이
print(tf.keras.activations.sigmoid(old_high).numpy() - 
tf.keras.activations.sigmoid(old_low).numpy())
0.16337568
0.14204389
Python으로 시작하는 TensorFlow

시그모이드 활성화 함수

  • 시그모이드 활성화 함수
    • 이진 분류
    • 로우 레벨: tf.keras.activations.sigmoid()
    • 하이 레벨: sigmoid

이미지는 -10부터 10 구간에서 시그모이드 활성화 함수를 보여줍니다.

Python으로 시작하는 TensorFlow

ReLU 활성화 함수

  • ReLU 활성화 함수
    • 은닉층
    • 로우 레벨: tf.keras.activations.relu()
    • 하이 레벨: relu

이미지는 -10부터 10 구간에서 ReLU 활성화 함수를 보여줍니다.

Python으로 시작하는 TensorFlow

소프트맥스 활성화 함수

  • 소프트맥스 활성화 함수
    • 출력층(클래스 > 2)
    • 로우 레벨: tf.keras.activations.softmax()
    • 하이 레벨: softmax
Python으로 시작하는 TensorFlow

신경망의 활성화 함수

import tensorflow as tf
# 입력층 정의
inputs = tf.constant(borrower_features, tf.float32)
# Dense 층 1 정의
dense1 = tf.keras.layers.Dense(16, activation='relu')(inputs)
# Dense 층 2 정의
dense2 = tf.keras.layers.Dense(8, activation='sigmoid')(dense1)
# 출력층 정의
outputs = tf.keras.layers.Dense(4, activation='softmax')(dense2)
Python으로 시작하는 TensorFlow

연습해 봅시다!

Python으로 시작하는 TensorFlow

Preparing Video For Download...