Project 11: Tiny Model Trainer
ML Engineer
Builds on these lessons
Current Task
Objective
.fit() trains a compiled model on data for a given number of epochs, returning a History object with the loss at each epoch.
Task: train a tiny model for 5 epochs and print how many loss values were recorded.
index.py
import tensorflow as tf
from tensorflow.keras import layers, Sequential
import numpy as np
model = Sequential([layers.Dense(1, input_shape=(1,))])
model.compile(optimizer='sgd', loss='mse')
x = np.array([1.0, 2.0, 3.0])
y = np.array([2.0, 4.0, 6.0])
history = model.fit(x, y, epochs=5, verbose=0)
print(len(history.history['loss']))
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview