活性化関数

Introduction to TensorFlow in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

活性化関数とは?

  • 典型的な中間層の構成要素
    • 線形: 行列積
    • 非線形: 活性化関数
Introduction to TensorFlow in Python

非線形性が重要な理由

この画像は、請求額と年齢を使って延滞を予測する簡単なネットワークを示します。

Introduction to TensorFlow in Python

非線形性が重要な理由

この画像は、30歳以下の借り手におけるクレジットカード請求額と延滞の関係を示します。

Introduction to TensorFlow in Python

簡単な例

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
Introduction to TensorFlow in Python

簡単な例

# 若年層での延滞予測の差
print(young_high - young_low)

# 高齢層での延滞予測の差
print(old_high - old_low)
0.8 
0.8
Introduction to TensorFlow in Python

簡単な例

# 若年層での延滞予測の差
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
Introduction to TensorFlow in Python

シグモイド活性化関数

  • シグモイド活性化関数
    • 二値分類
    • 低レベル: tf.keras.activations.sigmoid()
    • 高レベル: sigmoid

この画像は、-10〜10の範囲でのシグモイド活性化関数のプロットを示します。

Introduction to TensorFlow in Python

ReLU活性化関数

  • ReLU活性化関数
    • 中間層
    • 低レベル: tf.keras.activations.relu()
    • 高レベル: relu

この画像は、-10〜10の範囲でのReLU活性化関数のプロットを示します。

Introduction to TensorFlow in Python

ソフトマックス活性化関数

  • ソフトマックス活性化関数
    • 出力層(3クラス以上)
    • 低レベル: tf.keras.activations.softmax()
    • 高レベル: softmax
Introduction to TensorFlow in Python

ニューラルネットの活性化関数

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)
Introduction to TensorFlow in Python

練習してみましょう!

Introduction to TensorFlow in Python

Preparing Video For Download...