Funcții de pierdere

Introducere în TensorFlow în Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Introducere în funcțiile de pierdere

  • Operație fundamentală în tensorflow
    • Utilizată pentru antrenarea modelului
    • Măsoară calitatea ajustării modelului
  • Valoare mai mare -> ajustare mai slabă
    • Minimizați funcția de pierdere
Introducere în TensorFlow în Python

Funcții de pierdere comune în TensorFlow

  • TensorFlow include operații pentru funcții de pierdere comune

    • Eroarea pătratică medie (MSE)
    • Eroarea absolută medie (MAE)
    • Eroarea Huber
  • Funcțiile de pierdere sunt accesibile din tf.keras.losses()

    • tf.keras.losses.mse()
    • tf.keras.losses.mae()
    • tf.keras.losses.Huber()
Introducere în TensorFlow în Python

De ce sunt importante funcțiile de pierdere?

Imaginea prezintă funcțiile de pierdere MSE, MAE și Huber reprezentate grafic pe intervalul -2 până la 2.

  • MSE
    • Penalizează puternic valorile extreme
    • Sensibilitate ridicată (gradient) lângă minim
  • MAE
    • Crește liniar cu mărimea erorii
    • Sensibilitate scăzută lângă minim
  • Huber
    • Similar cu MSE lângă minim
    • Similar cu MAE departe de minim
Introducere în TensorFlow în Python

Definirea unei funcții de pierdere

# Import TensorFlow under standard alias
import tensorflow as tf

# Compute the MSE loss
loss = tf.keras.losses.mse(targets, predictions)
Introducere în TensorFlow în Python

Definirea unei funcții de pierdere

# 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)
Introducere în TensorFlow în Python

Definirea funcției de pierdere

# 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
Introducere în TensorFlow în Python

Să exersăm!

Introducere în TensorFlow în Python

Preparing Video For Download...