优化器

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...