How patilsri585/mlops-project-vehicle-insurance works
1. This repository is an end-to-end MLOps project for vehicle insurance response prediction. It has two primary execution paths: an offline training pipeline that builds and publishes a model, and an online inference path that serves predictions through a FastAPI app.
2. The main runtime entry points are demo.py for running the full training workflow and app.py for serving predictions. The app layer is lightweight; most business logic lives under main/, which is organized as a reusable Python package.
3. The training pipeline is staged and linear: MongoDB ingestion, schema/data validation, data transformation, model training, model evaluation, and model push. Each stage emits a persisted artifact into a timestamped artifact/ folder, so outputs from one run are isolated from the next.
4. Data ingress starts in main/configuration/mongo_db_connection.py and main/data_access/proj1_data.py, which connect to MongoDB Atlas and extract the source dataset. The ingestion component writes raw data to a CSV feature store and splits it into train/test files before downstream processing.
5. Validation and transformation are separate boundaries. data_validation.py checks incoming data against config/schema.yaml, while data_transformation.py performs preprocessing such as encoding, scaling, and class-imbalance handling. The fitted preprocessing pipeline is serialized as preprocessing.pkl, and transformed datasets are stored as .npy arrays.
6. Model training is isolated in model_trainer.py, which consumes the transformed training arrays and creates the classifier artifact model.pkl. model_evaluation.py then compares the trained model against test data and acceptance criteria defined in configuration. This makes model promotion dependent on measured quality, not just successful training.
7. Model publishing is handled by model_pusher.py and the AWS helpers in main/configuration/aws_connection.py plus main/cloud_storage/aws_storage.py. The trained model artifact is uploaded to S3, which acts as the model registry / distribution point for deployment and inference.
8. The inference pipeline in main/pipeline/prediction_pipeline.py mirrors the training preprocessing logic to avoid training-serving skew. It accepts user input from the HTML form in templates/vehicledata.html, applies custom type conversions and feature alignment, loads the preprocessor and model, and returns a binary prediction.
9. Configuration is externalized in config/model.yaml and config/schema.yaml. These files define model settings, feature lists, scaling rules, and validation constraints, so the pipeline behavior is controlled by config rather than hardcoded assumptions.
10. Shared domain objects live in main/entity/. These dataclasses define configuration and artifact shapes, while estimator.py and s3_estimator.py wrap model loading and S3-backed access. This keeps orchestration code from depending directly on low-level storage details.
11. Operational concerns are built into the package: main/logger/ provides rotating file logging, and main/exception/ standardizes error reporting with traceback context. Generated logs are stored under logs/, while notebooks under notebook/ support exploration and offline experimentation rather than production execution.
12. Deployment is container-based and cloud-backed. The dockerfile packages the app, and .github/workflows/aws.yaml implements CI/CD that builds the image, pushes it to AWS ECR, then deploys it to an EC2 self-hosted runner. Environment secrets include AWS credentials and the MongoDB connection string, making cloud services part of the runtime boundary.
Main entry points: training_pipeline.py Training Pipeline · prediction_pipeline.py Prediction Pipeline · data_transformation.py Transformation · model_pusher.py Pusher
Components 19
Runtimes
Main execution entry points for training and inference
Pipelines
Orchestrates offline training and online prediction flows
- Training Pipeline · Coordinates ingestion through model push
main/pipeline/training_pipeline.py - Prediction Pipeline · Prepares input and generates online predictions
main/pipeline/prediction_pipeline.py
Core Components
Staged MLOps processing blocks
- Ingestion · Pulls data from MongoDB and writes feature store splits
main/components/data_ingestion.py - Validation · Validates data against the configured schema
main/components/data_validation.py - Transformation · Encodes, scales, and balances data for training
main/components/data_transformation.py - Trainer · Trains the classifier and produces the model artifact
main/components/model_trainer.py - Evaluation · Compares model performance to acceptance criteria
main/components/model_evaluation.py - Pusher · Uploads the approved model artifact to S3
main/components/model_pusher.py
Shared Package
Reusable domain objects and support utilities
- Entities · Defines config and artifact shapes shared across the app
main/entity/artifact_entity.py - Estimators · Wraps local model loading and S3-backed access
main/entity/estimator.py - Logging & Errors · Standardizes rotating logs and traceback-rich exceptions
main/logger
Configuration
Externalized model and schema settings
- model.yaml · Holds model and preprocessing settings
config/model.yaml - schema.yaml · Defines feature constraints and validation rules
config/schema.yaml
Infrastructure
Cloud, deployment, and persistence boundaries
- MongoDB · Connects to MongoDB Atlas for source data access
main/configuration/mongo_db_connection.py - AWS Setup · Provides AWS credentials and service access
main/configuration/aws_connection.py - S3 Storage · Stores and retrieves model artifacts from S3
main/cloud_storage/aws_storage.py
User Interface
Request input and presentation surfaces
- Vehicle Form · Collects user input for online prediction
templates/vehicledata.html
Connections 22
- demo.py → Training Pipeline: runs · Launches the offline training workflow
- app.py → Prediction Pipeline: serves · Uses the inference flow for request handling
- Training Pipeline → Ingestion: stage 1 · Starts data acquisition and split creation
- Training Pipeline → Validation: stage 2 · Validates raw and split data
- Training Pipeline → Transformation: stage 3 · Builds preprocessing artifacts and arrays
- Training Pipeline → Trainer: stage 4 · Trains the classifier from transformed data
- Training Pipeline → Evaluation: stage 5 · Checks model quality before promotion
- Training Pipeline → Pusher: stage 6 · Publishes the approved model to S3
- Ingestion → MongoDB: reads from · Connects to MongoDB Atlas source data
- Validation → schema.yaml: checks against · Uses schema constraints for validation
- Transformation → model.yaml: uses config · Applies preprocessing rules from model config
- Transformation → Entities: emits · Produces transformation artifact metadata
- Trainer → Entities: emits · Produces training artifact metadata
- Evaluation → model.yaml: thresholds · Reads acceptance criteria from configuration
- Pusher → AWS Setup: uses · Uses AWS service configuration
- Pusher → S3 Storage: uploads to · Pushes the trained model into S3 storage
- S3 Storage → Estimators: backs · Provides S3-backed model access
- Prediction Pipeline → Vehicle Form: receives · Accepts user-submitted vehicle data
- Prediction Pipeline → Transformation: mirrors · Reuses preprocessing behavior to avoid skew
- Prediction Pipeline → Estimators: loads · Loads the persisted model for inference
- Training Pipeline → Logging & Errors: logs · Records progress and failures
- Prediction Pipeline → Logging & Errors: logs · Records inference errors and tracebacks