Neural Networks with Keras

Machine LearningDeep LearningFree Lesson

Advertisement

Introduction

Build neural networks with Keras high-level API.

Sequential Model

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

model = keras.Sequential([
    layers.Dense(64, activation="relu", input_shape=(784,)),
    layers.Dense(32, activation="relu"),
    layers.Dense(10, activation="softmax")
])

Model Compilation

model.compile(
    optimizer="adam",
    loss="sparse_categorical_crossentropy",
    metrics=["accuracy"]
)

Training

model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.2)

# Evaluate
loss, accuracy = model.evaluate(X_test, y_test)

# Predict
predictions = model.predict(X_test)

Practice Problems

  1. Build multi-layer network
  2. Use different optimizers
  3. Add dropout for regularization
  4. Monitor training with callbacks
  5. Save and load models

Advertisement

Need Expert Python Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement