Keras ile eğitim

Python ile TensorFlow’a Giriş

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Eğitim ve değerlendirme özeti

  1. Veriyi yükle ve temizle
  2. Modeli tanımla
  3. Modeli eğit ve doğrula
  4. Modeli değerlendir
Python ile TensorFlow’a Giriş

Bir modeli nasıl eğitiriz

# Import tensorflow
import tensorflow as tf

# Define a sequential model
model = tf.keras.Sequential()
# Define the hidden layer
model.add(tf.keras.layers.Dense(16, activation='relu', input_shape=(784,)))
# Define the output layer
model.add(tf.keras.layers.Dense(4, activation='softmax'))
Python ile TensorFlow’a Giriş

Bir modeli nasıl eğitiriz

# Compile model
model.compile('adam', loss='categorical_crossentropy')
# Train model
model.fit(image_features, image_labels)
Python ile TensorFlow’a Giriş

fit() işlemi

  • Zorunlu argümanlar
    • features
    • labels
  • Birçok isteğe bağlı argüman
    • batch_size
    • epochs
    • validation_split
Python ile TensorFlow’a Giriş

Batch size ve epochlar

Diyagram, verisetinin partilere bölünmesini ve bu partilerin birleşiminin bir epoch ettiğini gösteriyor.

Python ile TensorFlow’a Giriş

Doğrulama yapma

Görsel, verisetinin eğitim ve doğrulama örneklerine bölünmesini gösteriyor.

Python ile TensorFlow’a Giriş

Doğrulama yapma

# Train model with validation split
model.fit(features, labels, epochs=10, validation_split=0.20)
Python ile TensorFlow’a Giriş

Doğrulama yapma

Görsel, 10 epoch boyunca eğitim ve doğrulama sonuçlarını gösteriyor.

Python ile TensorFlow’a Giriş

Metriği değiştirme

# Recomile the model with the accuracy metric
model.compile('adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Train model with validation split
model.fit(features, labels, epochs=10, validation_split=0.20)
Python ile TensorFlow’a Giriş

Metriği değiştirme

Görsel, 10 epoch boyunca eğitim ve doğrulama sonuçlarını gösteriyor.

Python ile TensorFlow’a Giriş

evaluation() işlemi

Görsel, verisetinin eğitim, doğrulama ve test örneklerine bölünmesini gösteriyor.

# Evaluate the test set
model.evaluate(test)
Python ile TensorFlow’a Giriş

Hadi pratik yapalım!

Python ile TensorFlow’a Giriş

Preparing Video For Download...