最佳化器

Python 的 TensorFlow 入門

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

如何找到最小值

圖片為大峽谷。

1 來源:U.S. National Park Service
Python 的 TensorFlow 入門

如何找到最小值

圖片為大峽谷。

1 來源:U.S. National Park Service
Python 的 TensorFlow 入門

如何找到最小值

圖片為大峽谷。

1 來源:U.S. National Park Service
Python 的 TensorFlow 入門

此圖展示 SGD、RMSprop 與 Adam 最佳化器在簡單問題中的學習路徑。

Python 的 TensorFlow 入門

梯度下降最佳化器

  • 隨機梯度下降(SGD)最佳化器

    • tf.keras.optimizers.SGD()
    • learning_rate
  • 簡單、易理解

Python 的 TensorFlow 入門

RMSprop 最佳化器

  • 均方根(RMS)傳播最佳化器

    • 對每個特徵套用不同學習率
    • tf.keras.optimizers.RMSprop()
    • learning_rate
    • momentum
    • decay
  • 允許動量累積與衰減

Python 的 TensorFlow 入門

Adam 最佳化器

  • 自適應動量(Adam)最佳化器

    • tf.keras.optimizers.Adam()
    • learning_rate
    • beta1
  • 預設參數表現良好

Python 的 TensorFlow 入門

完整範例

import tensorflow as tf

# Define the model function
def model(bias, weights, features = borrower_features):
    product = tf.matmul(features, weights)
    return tf.keras.activations.sigmoid(product+bias)
# Compute the predicted values and loss
def loss_function(bias, weights, targets = default, features = borrower_features):
    predictions = model(bias, weights)
    return tf.keras.losses.binary_crossentropy(targets, predictions)
# Minimize the loss function with RMS propagation
opt = tf.keras.optimizers.RMSprop(learning_rate=0.01, momentum=0.9)
opt.minimize(lambda: loss_function(bias, weights), var_list=[bias, weights])
Python 的 TensorFlow 入門

一起來練習吧!

Python 的 TensorFlow 入門

Preparing Video For Download...