← TensorFlow & Keras learning path
TensorFlow & Keras · Module 4 of 10

Compiling and training

Train models with compile and fit.

📖 Key ideas

  1. model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]).
  2. model.fit(x, y, epochs=10, batch_size=32, validation_split=0.2).
  3. History object stores loss and metrics per epoch.
  4. model.evaluate() tests on held-out data.
  5. model.predict() makes predictions.
💡 Real-life example: compile chooses the training plan; fit runs the training sessions; evaluate is the final exam.
compile()Sets optimiser, loss, metrics
fit()Trains the model
evaluate()Measures performance on data
predict()Generates predictions