Practice in Lab: Project: fit, select, refit and serialize a ridge workflow →
Project: fit, select, refit and serialize a ridge workflow
A model workflow owns more than a coefficient vector. Preprocessing statistics, hyperparameter selection, refitting and final evaluation each have a different data boundary. This project trains actual NumPy ridge models and exports the complete transformation needed to reproduce predictions. Validation chooses a penalty; after that decision, train and validation may be combined for a final fit. Test labels are used only to measure the frozen artifact. The fixture is small and local; it does not implement experiment storage, a feature service or a production deployment.
import numpy as np
x = np.array([[0.,7.],[1.,7.],[2.,7.]])
scale = x.std(axis=0)
scale[scale == 0] = 1
z = (x-x.mean(axis=0))/scale
print(z.mean(axis=0).round(8).tolist())Review the design
Review every fitted statistic's provenance. Reproduce predictions after JSON serialization, test constant columns, poison held-out labels and explain how dataset/schema versions would enter a real artifact registry.
Your task
Rows contain unique string id, numeric feature list x and target y. Require three nonempty identity-disjoint finite rectangular partitions and positive finite penalties. For each penalty, fit population means/stds and centered-target ridge only on train; constant-feature scale is one. Select minimum validation MSE, smaller penalty on an exact tie. Refit preprocessing and ridge on train+validation, then evaluate test once. Return alpha, validation_mse, test_mse, predictions, fit_ids and a JSON-compatible artifact with means, scales, coefficients and unpenalized intercept. Solve (Z.T@Z+alpha*I)w=Z.T@(y-mean_y).
The explanation opens here once every check passes.