Skip to content

Latest commit

Β 

History

History
352 lines (262 loc) Β· 12.9 KB

File metadata and controls

352 lines (262 loc) Β· 12.9 KB

Module 2: Classification & Production Pipelines 🎯

From Notebooks to Professional ML Systems

πŸ“ Location: 2_Classification/
🎯 Prerequisite: Module 1: Regression Mastery
➑️ Next Module: Module 3: Neural Networks from Scratch

Welcome to the Classification Module of SAIR – where you transition from experimental notebooks to production-ready ML systems with professional pipelines and deployment architecture.


🎯 Is This Module For You?

βœ… Complete this module if:

  • You've mastered regression and want to tackle classification problems
  • You're ready to build professional ML pipelines
  • You want to learn industry best practices for ML systems
  • You're preparing for ML engineering roles

πŸš€ Review and continue if you're experienced:

  • You've built classification models but want production experience
  • You're familiar with sklearn but want pipeline architecture skills
  • You want to add MLflow and modular design to your toolkit

πŸ› οΈ Tools You'll Master

Python Scikit-learn MLflow Streamlit

These production tools transform your ML code from experiments to enterprise-ready systems.


πŸ“š What You'll Learn

Lecture Focus Time Estimate Mastery Level
Lecture_4.ipynb Classification from Scratch 4-5 hours Essential
Lecture_5.ipynb Production Pipeline System 5-6 hours Professional
Pipeline/ System Modular Architecture 6-8 hours Industry Ready

πŸ—ΊοΈ Your Learning Journey

Phase 1: Algorithm Fundamentals 🎯

Start with: Lecture_4.ipynb

  • Implement logistic regression from first principles
  • Understand classification metrics and evaluation
  • Build intuition for decision boundaries and probability

Phase 2: Pipeline Development πŸš€

Continue with: Lecture_5.ipynb

  • Transform notebooks into modular code
  • Learn configuration management
  • Set up experiment tracking and hyperparameter tuning

Phase 3: Production Architecture πŸ“š

Master with: Pipeline/ system

  • Build end-to-end ML pipeline
  • Implement professional project structure
  • Deploy with Streamlit applications

🎯 Learning Outcomes

After completing this module, you will be able to:

Skill Where You Build It
Implement logistic regression from scratch Lecture_4.ipynb
Interpret classification metrics: precision, recall, F1, ROC-AUC Lecture_4.ipynb
Transform a notebook into a modular ML codebase Lecture_5.ipynb
Design a configuration-driven pipeline Pipeline/
Run grid search and hyperparameter tuning at scale Pipeline/models/
Compare experiments in MLflow and select the best model Pipeline/
Deploy a classifier as a Streamlit web app Pipeline/streamlit_app/

πŸ’‘ Our Learning Philosophy

"From experimental code to production systems."

At SAIR, we believe modular, maintainable code separates hobby projects from professional systems. This module teaches you to architect ML solutions that scale and can be maintained by teams.

This is where you become an ML engineer, not just a model builder.


πŸš€ Quick Start Guide

For Sequential Learners:

# 1. Start with classification fundamentals
jupyter notebook Lecture_4.ipynb

# 2. Learn pipeline transformation
jupyter notebook Lecture_5.ipynb

# 3. Explore the production pipeline
cd Pipeline
python run_pipeline.py

For Pipeline-Focused Learners:

# Dive directly into professional architecture
cd Pipeline
python run_pipeline.py

# Run the Streamlit app
uv run streamlit run streamlit_app/app.py

Run the Complete Example:

# Test the breast cancer pipeline
python breast_cancer_pipline.py

πŸ—οΈ Professional Pipeline Architecture

πŸš€ Spaceship Titanic ML Pipeline Example

The Pipeline/ directory contains a complete, production-ready ML system that transforms Lecture 5 concepts into a professional codebase.

Key Features:

  • βœ… Modular Architecture - Separate data, models, config, utils
  • βœ… Advanced Feature Engineering - Custom transformers for domain-specific features
  • βœ… Multi-Model Training - 7+ algorithms with systematic comparison
  • βœ… Hyperparameter Tuning - Cross-validation and optimization
  • βœ… MLflow Experiment Tracking - Reproducible experiments
  • βœ… Streamlit Deployment - Interactive web application

Pipeline Structure:

Pipeline/
β”œβ”€β”€ config/              # Configuration Management
β”‚   β”œβ”€β”€ config.py        # Centralized settings and paths
β”‚   └── __init__.py
β”œβ”€β”€ data/                # Data Processing
β”‚   β”œβ”€β”€ load_data.py     # Data ingestion and splitting
β”‚   β”œβ”€β”€ preprocessing.py # Cleaning & preparation pipelines
β”‚   β”œβ”€β”€ feature_engineering.py # Custom feature creation
β”‚   └── raw/            # Source datasets
β”œβ”€β”€ models/              # ML Modeling
β”‚   β”œβ”€β”€ base_model.py    # Abstract base classes
β”‚   β”œβ”€β”€ train_model.py   # Training orchestration
β”‚   β”œβ”€β”€ evaluate_model.py # Comprehensive evaluation
β”‚   └── hyperparameter_tuning.py # Systematic optimization
β”œβ”€β”€ utils/               # Shared Utilities
β”‚   └── mlflow_utils.py  # Experiment tracking helpers
β”œβ”€β”€ streamlit_app/       # Deployment
β”‚   └── app.py          # Web interface for predictions
└── run_pipeline.py      # Main execution script

Run the Complete Pipeline:

cd Pipeline

# Execute full pipeline
python run_pipeline.py --mode full

# Or run specific steps
python run_pipeline.py --mode preprocessing    # Data only
python run_pipeline.py --mode training        # Models only  
python run_pipeline.py --mode evaluation      # Evaluation only

View MLflow Experiments:

mlflow ui --backend-store-uri mlruns
# Open http://localhost:5000 in your browser

🎯 Capstone Project: Build Your Pipeline

Your Mission:

Apply the pipeline architecture to a classification problem of your choice, inspired by the Spaceship Titanic example.

Success Criteria:

  • βœ… Implement modular pipeline structure
  • βœ… Advanced feature engineering for your domain
  • βœ… Multi-model comparison and selection
  • βœ… MLflow experiment tracking
  • βœ… Streamlit deployment interface
  • βœ… Professional documentation

Project Ideas (Inspired by Spaceship Titanic):

  • πŸ₯ Medical Diagnosis - Patient outcome prediction
  • πŸ’³ Fraud Detection - Transaction classification
  • πŸ“§ Spam Filter - Email categorization system
  • πŸ›’ Customer Churn - Retention prediction
  • 🎯 Sentiment Analysis - Review classification
  • πŸš€ Custom Dataset - Your own classification problem!

Follow the Pattern:

Study the Pipeline/ structure and adapt it for your project:

  • Replace dataset loading in data/load_data.py
  • Customize feature engineering in data/feature_engineering.py
  • Modify model portfolio in models/base_model.py
  • Update the Streamlit app for your domain

🌟 Student Inspiration: Spaceship Titanic Pipeline

The included Pipeline/ demonstrates exactly what you'll build:

What Makes It Professional:

  • Configuration Management: Centralized settings in config.py
  • Feature Engineering: Custom SpaceshipFeatureEngineer class
  • Model Portfolio: 7+ algorithms with hyperparameter tuning
  • Experiment Tracking: MLflow for reproducibility
  • Modular Design: Each component independently testable

Key Learning Outcomes:

After studying this pipeline, you'll be able to: βœ… Build modular ML pipelines from scratch
βœ… Implement domain-specific feature engineering
βœ… Compare multiple models systematically
βœ… Track experiments with MLflow
βœ… Create reproducible research
βœ… Structure projects for collaboration

Adaptation Guide:

# In your project, replace Spaceship Titanic specifics:
# data/load_data.py β†’ Your dataset loading
# data/feature_engineering.py β†’ Your domain features  
# models/base_model.py β†’ Your model portfolio
# streamlit_app/app.py β†’ Your application interface

πŸ“Š Reading MLflow Results

When you run the pipeline, MLflow logs every experiment. Here's how to interpret the results:

# Open the MLflow dashboard
mlflow ui --backend-store-uri Pipeline/mlruns
# Then open: http://localhost:5000
Metric What It Means Good Range
val_accuracy Accuracy on held-out validation set >85% for most problems
val_f1 Harmonic mean of precision and recall >0.80 for balanced classes
val_roc_auc Area under the ROC curve >0.85 is strong
train_accuracy vs val_accuracy Gap > 10% = overfitting Keep gap under 5%

Model selection rule: pick the model with the best val_f1, not train_accuracy. High training accuracy with low val accuracy = overfitting β€” try more regularization or less complexity.


πŸ”§ Troubleshooting

Problem Likely Cause Fix
mlflow.exceptions.MlflowException Tracking dir not found Run pipeline from the Pipeline/ directory
Streamlit app shows stale predictions Old model pickle loaded Delete models/ and re-run --mode full
KeyError in feature engineering Column renamed in your dataset Update column names in config.py
Hyperparameter tuning takes too long Too many combinations Reduce param_grid in models/base_model.py
Class imbalance warning Unequal class distribution Add class_weight='balanced' to your estimator

🀝 Get Help & Connect

Building pipelines can be challenging - we're here to help!

Telegram

Get architecture reviews, pipeline feedback, and join deep-dive sessions on ML engineering best practices. Share your pipeline adaptations and get inspired by others!


🎯 Ready for Your Next Step?

Starting classification?

β†’ Begin with Lecture_4.ipynb

Ready for pipelines?

β†’ Study the Pipeline/ example thoroughly

Want to test the complete system?

β†’ Run breast_cancer_pipline.py

Ready to build your own?

β†’ Create your project following the pipeline pattern

Ready to advance?

β†’ Continue to Module 3: Neural Networks from Scratch


πŸ“š Reference Materials

Resource Purpose When to Use
Pipeline/run_pipeline.py Complete pipeline example Learning architecture
Pipeline/streamlit_app/app.py Production deployment Building your UI
Pipeline/config/config.py Configuration template Project setup
breast_cancer_pipline.py Integrated example Testing end-to-end flow

"Ψ§Ω„Ψ³ΩŠΨ±" - "Walking on a road"
Professional ML is about systems, not just models. This pipeline example shows you the path from notebooks to production.

Study the pattern, then build your masterpiece! πŸ—οΈ


πŸ”œ Next Step: Module 3: Neural Networks from Scratch


πŸ—‚οΈ Module Structure:

3_Classification/
β”‚
β”œβ”€β”€ πŸ“š README.md                          # This guide
β”œβ”€β”€ 🎯 Lecture_4.ipynb                    # Classification from Scratch
β”œβ”€β”€ πŸš€ Lecture_5.ipynb                    # Production Pipeline Design
β”œβ”€β”€ πŸ”§ breast_cancer_pipline.py           # Integrated Example
└── πŸ—οΈ Pipeline/                         # Professional Architecture
    β”œβ”€β”€ config/                           # Configuration Management
    β”œβ”€β”€ data/                             # Data Processing
    β”œβ”€β”€ models/                           # ML Modeling
    β”œβ”€β”€ utils/                            # Shared Utilities
    β”œβ”€β”€ streamlit_app/                    # Deployment Interface
    β”œβ”€β”€ run_pipeline.py                   # Main Execution
    β”œβ”€β”€ README.md                         # Detailed Documentation
    └── requirements.txt                  # Dependencies