v6 Save Pipeline¶
View code on GitHub Get the Video Course
Progress¶
✅ STEP 1: Load Data
✅ STEP 2: Split Train/Test
✅ STEP 3: Create Pipeline
✅ STEP 4: Train Pipeline
✅ STEP 5: Evaluate & Metrics
🟡 STEP 6: Save Pipeline ← NEW IN THIS VERSION
⬜ STEP 7: Save Metrics JSON
What's New¶
| File | Change |
|---|---|
utils/ | Implemented save_ - pickle + metadata JSON |
utils/ | Exports save_ |
p3_ | Added STEP 6: save trained pipeline to disk |
New Function¶
# utils/model_utils.py
def save_pipeline(pipeline, model_name, metrics=None, metadata=None):
"""Save Pipeline pickle + metadata JSON to models/ directory."""
What Gets Saved¶
The latest files are always the most recent - used by the inference API later. Timestamped files provide version history.
Key Concept: Manual Model Saving¶
This is the manual way to save models. Notice what we have to manage ourselves:
- File paths and directories
- Pickle serialization
- Metadata JSON with metrics
- Timestamped backups
Good to know: tools like MLflow (not part of this course) replace all of this with
mlflow.sklearn.log_model(pipeline)- one line instead of 30+.
Not part of this course
MLflow, DVC, Kubernetes, CI/CD and Kubeflow belong to MLOps, the next layer. This course covers the machine learning side, end to end, and stops at the API. See Important Notes, note 3.
How to Run¶
cd v6_save_pipeline_ccfd-project/
# PRE-REQUISITE: Generate data first
python p1_01_generate_initial_dataset.py
# Run training script
python p3_01_train_model_baseline.py
Expected Output (STEP 6):
STEP 6: Saving Pipeline
Model Saved: p3_01_baseline
Location: models/p3_01_baseline/
Model: LogisticRegression
Timestamp: 20260323_143052
Next Version¶
v7 → Implement save_metrics_json() - save detailed metrics to a JSON file for tracking.
Prefer to learn by watching?
The video course builds this whole project with you on screen, step by step.
Back to 04 A Train Baseline Model v5 Evaluate and Metrics Next: v7 Save Metrics JSON