Lossfuncties

Introductie tot TensorFlow in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Introductie tot verliesfuncties

  • Fundamentele tensorflow-operatie
    • Gebruikt om een model te trainen
    • Maat voor model-fit
  • Hogere waarde -> slechtere fit
    • Minimaliseer de verliesfunctie
Introductie tot TensorFlow in Python

Veelgebruikte verliesfuncties in TensorFlow

  • TensorFlow heeft operaties voor gangbare verliesfuncties

    • Mean squared error (MSE)
    • Mean absolute error (MAE)
    • Huber-fout
  • Verliesfuncties via tf.keras.losses()

    • tf.keras.losses.mse()
    • tf.keras.losses.mae()
    • tf.keras.losses.Huber()
Introductie tot TensorFlow in Python

Waarom zijn verliesfuncties belangrijk?

Deze afbeelding toont de verliesfuncties MSE, MAE en Huber uitgezet over het interval -2 tot 2.

  • MSE
    • Straft uitschieters sterk
    • Hoge (gradiënt)gevoeligheid nabij minimum
  • MAE
    • Schaal lineair met foutgrootte
    • Lage gevoeligheid nabij minimum
  • Huber
    • Lijkt op MSE nabij minimum
    • Lijkt op MAE verder van minimum
Introductie tot TensorFlow in Python

Een verliesfunctie definiëren

# Import TensorFlow under standard alias
import tensorflow as tf

# Compute the MSE loss
loss = tf.keras.losses.mse(targets, predictions)
Introductie tot TensorFlow in Python

Een verliesfunctie definiëren

# Define a linear regression model
def linear_regression(intercept, slope = slope, features = features):
    return intercept + features*slope
# Define a loss function to compute the MSE
def loss_function(intercept, slope, targets = targets, features = features):
    # Compute the predictions for a linear model
    predictions = linear_regression(intercept, slope)

    # Return the loss
    return tf.keras.losses.mse(targets, predictions)
Introductie tot TensorFlow in Python

De verliesfunctie definiëren

# Compute the loss for test data inputs
loss_function(intercept, slope, test_targets, test_features)
10.77
# Compute the loss for default data inputs
loss_function(intercept, slope)
5.43
Introductie tot TensorFlow in Python

Laten we oefenen!

Introductie tot TensorFlow in Python

Preparing Video For Download...