Practice in Lab: Project: train logistic regression and restore the best validation checkpoint →
Project: train logistic regression and restore the best validation checkpoint
Training correctness includes the state selected for deployment. A reference to a mutable weight array is not a saved checkpoint, and a final training iterate is not necessarily the best validation model. This project trains a real NumPy logistic classifier, fits preprocessing on training observations and restores a copied validation checkpoint before evaluating test. The fixtures include a deliberately contradictory validation population so the best step occurs early. This is a deterministic full-batch optimizer, without minibatch scheduling, distributed training or a production checkpoint store.
import numpy as np
weights = np.array([1.,2.])
checkpoint = weights.copy()
weights += 3
print(checkpoint.tolist(), weights.tolist())Review the design
Review gradient normalization, regularization, fitted transformations and checkpoint ownership. Explain validation selection bias and preserve an independent final test population.
Your task
Require nonempty identity-disjoint rectangular finite feature partitions with binary integer y, positive finite learning_rate, integer steps>=1 and finite l2>=0. Standardize from train population means/stds only; constant scales become one. Start weights/bias at zero. Each full-batch gradient step uses mean sigmoid error, L2 on weights only, then measures unregularized validation log loss. Keep the earliest strict best checkpoint by copying weights. Restore it for final test evaluation. Return weights,bias,means,scales,best_step,validation_loss,test_loss,predictions and validation history. Use stable logaddexp for sigmoid and loss.
The explanation opens here once every check passes.