NumPy arrays support elementwise arithmetic. Python's ** operator raises a number to a power; an expression such as error**2 squares it. A for loop repeats indented statements. print displays a result. Use these operations to expose each stage of fitting rather than hiding it behind a model.fit call.
x, target, weight, rate = 2.0, 6.0, 1.0, 0.1
prediction = weight * x
loss = (prediction - target) ** 2 / 2
gradient = (prediction - target) * x
updated = weight - rate * gradient
new_loss = (updated * x - target) ** 2 / 2
print(prediction, loss, gradient, updated, new_loss)
The expected values are approximately 2,8,−8,1.8,2.88. Floating-point arithmetic represents many decimals approximately, so compare with a tolerance rather than exact equality. NumPy's allclose performs that comparison for several values.
Download week01.py and run ./.venv/Scripts/python.exe week01.py --lesson 3. It checks those intermediate values and repeats updates using rates 0.01,0.1,1.0. Before inspecting the output, predict which rate takes a gentle step and which first increases loss. The printed sequences are measured computations for this scalar function, not evidence that one rate works for every neural network.