SageMaker model training and evaluation
From training to prediction
Machine learning (ML) learns a rule from examples instead of specifying every decision by hand. Training fits parameters; inference applies the fitted model to new features. For a fictional parcel service, predict whether a shipment will be late from information known before dispatch. The label is the actual outcome, not a feature. SageMaker AI provides managed model development and execution; the broader Amazon SageMaker platform includes Unified Studio for data and AI workflows. A local Python model is enough to learn the lifecycle before paying for managed resources.
Data splits and leakage
A feature is an input available at prediction time. Split historical shipments into training, validation and untouched test sets, preferably by time and shipment identity so future information cannot enter past examples. Fit preprocessing on training only. Select the threshold using validation and report final test performance once. In SageMaker AI, processing jobs can prepare features, notebooks can explore them, and training jobs run a chosen algorithm or custom container to produce model artifacts. Track data version, code, hyperparameters and metrics with experiments such as managed MLflow. Never put customer addresses in a practice dataset.
Evaluate a small classifier
A toy CPU model learns a distance threshold from labeled training rows by minimizing classification errors. On independent test rows, count true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). For TP=3, FP=1, TN=3, FN=1, accuracy is 6/8, precision is 3/4 and recall is 3/4. Precision measures how many flagged parcels were late; recall measures how many late parcels were flagged. A majority-class baseline matters: 95% accuracy is unimpressive if only 5% of parcels are late and the model never detects one. Undefined ratios must be reported rather than silently replaced with perfect scores.
[ [ 30, 1, "A" ], [ 40, 1, "A" ], [ 35, 1, "B" ], [ 20, 1, "B" ], [ 10, 0, "A" ], [ 20, 0, "A" ], [ 25, 0, "B" ], [ 50, 0, "B" ]]Practice and limits
Run the local lab in lab-fixtures/ml-release-review. Compare error counts for two candidate thresholds using training only, then evaluate the selected threshold on test data. Report group-specific recall with sample counts for two synthetic routes; a tiny dataset cannot establish fairness. A threshold is deliberately simpler than production ML. Use ByteMind Python and ML tracks for functions, datasets, model fitting and metrics. Managed training is useful for repeatable jobs and specialized hardware; a foundation-model API is a different approach for language tasks when you do not need to train your own classifier.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SageMaker model training and evaluation — knowledge check
Reason about ML evaluation, inference and controlled release.
Which input leaks future information?
Which data should tune a model threshold after fitting?
With TP=3 and FP=1, what is precision?
What does a training job produce?
Why compare subgroup metrics and sample counts?