Skip to main content

A production-ready machine learning framework

Project description

MLOps-Boilerplate

A production-ready machine learning framework for building, training, deploying, and monitoring ML models at scale.

Python Version License Code style: black

๐Ÿš€ Features

  • Modular Architecture: Clean separation of concerns with data layer, ML components, and applications
  • Multiple Data Sources: Built-in connectors for PostgreSQL, MongoDB, AWS S3, Azure Blob Storage
  • ML Models: Support for Random Forest, XGBoost, and easy extensibility for custom models
  • Data Processing: Complete preprocessing pipeline with feature engineering and scaling
  • Cross-Validation: K-Fold and Stratified K-Fold validation with comprehensive metrics
  • Experiment Tracking: Integration with MLflow for experiment management
  • Configuration Management: Pydantic-based configuration with validation
  • Testing: Comprehensive test suite with pytest
  • Monitoring: Model performance tracking and data drift detection
  • API Server: FastAPI-based REST API for model serving
  • Production Ready: Docker support, CI/CD pipelines, and best practices

๐Ÿ“‹ Table of Contents

๐Ÿ”ง Installation

Install from PyPI (Recommended)

pip install mlops-boilerplate

Create a New Project

After installation, create a new ML project using the template:

# Create a new project
ml-create-project my-ml-project

# Navigate to your project
cd my-ml-project

# Set up virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your configuration

Install from Source (For Development)

# Clone the repository
git clone https://github.com/kython220282/MLOps-Boilerplate.git
cd MLOps-Boilerplate

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate

# Install in development mode
pip install -e .

Install with Docker

docker build -t mlops-boilerplate .
docker run -p 8000:8000 mlops-boilerplate

๐Ÿƒ Quick Start

1. Setup Environment

# Copy environment template
cp .env.example .env

# Edit .env with your configuration

2. Train a Model

# Using CLI
ml-train --config config/training_config.json

# Or with Python
python -m ml_service.applications.training --config config/training_config.json

3. Run Inference

ml-inference --model-path models/model.joblib \\
             --input-path data/test.csv \\
             --output-path predictions.csv

4. Start API Server

ml-serve --model-path models/model.joblib --port 8000

๐Ÿ“ Project Structure

machine_learning_service/
โ”œโ”€โ”€ ml_service/                 # Main package
โ”‚   โ”œโ”€โ”€ applications/          # Application entry points
โ”‚   โ”‚   โ”œโ”€โ”€ training.py       # Training CLI application
โ”‚   โ”‚   โ””โ”€โ”€ inference.py      # Inference CLI application
โ”‚   โ”œโ”€โ”€ data_layer/           # Data connectors
โ”‚   โ”‚   โ”œโ”€โ”€ data_connector.py # Database connectors
โ”‚   โ”‚   โ””โ”€โ”€ object_connector.py # Cloud storage connectors
โ”‚   โ”œโ”€โ”€ machine_learning/     # ML components
โ”‚   โ”‚   โ”œโ”€โ”€ data_processor.py # Data preprocessing
โ”‚   โ”‚   โ”œโ”€โ”€ model.py          # Model definitions
โ”‚   โ”‚   โ”œโ”€โ”€ training_pipeline.py # Training orchestration
โ”‚   โ”‚   โ””โ”€โ”€ cross_validator.py # Model validation
โ”‚   โ””โ”€โ”€ config.py             # Configuration management
โ”œโ”€โ”€ config/                    # Configuration files
โ”‚   โ”œโ”€โ”€ training_config.json
โ”‚   โ””โ”€โ”€ training_config.yaml
โ”œโ”€โ”€ tests/                     # Test suite
โ”œโ”€โ”€ docs/                      # Documentation
โ”œโ”€โ”€ requirements.txt          # Dependencies
โ”œโ”€โ”€ setup.py                  # Package setup
โ”œโ”€โ”€ pyproject.toml           # Project configuration
โ”œโ”€โ”€ .env.example             # Environment template
โ””โ”€โ”€ README.md                # This file

๐Ÿ’ก Usage Examples

Training with Different Data Sources

From CSV File:

from ml_service.machine_learning.training_pipeline import TrainingPipeline

config = {
    "data_source": {"type": "file", "path": "data/train.csv"},
    "target_column": "target",
    "model": {"type": "random_forest", "n_estimators": 100},
    "task_type": "classification"
}

pipeline = TrainingPipeline(config)
metrics = pipeline.run_pipeline()

From Database:

config = {
    "data_source": {
        "type": "database",
        "connector_type": "postgresql",
        "connection_config": {
            "host": "localhost",
            "database": "ml_db"
        },
        "query": "SELECT * FROM training_data"
    },
    "target_column": "target"
}

Custom Model Development

from ml_service.machine_learning.model import BaseModel

class CustomModel(BaseModel):
    def build_model(self):
        # Your model architecture
        pass
    
    def train(self, X_train, y_train):
        # Training logic
        pass
    
    def predict(self, X):
        # Prediction logic
        pass

Data Processing Pipeline

from ml_service.machine_learning.data_processor import DataProcessor

processor = DataProcessor()
df = processor.load_data("data/train.csv")
X_train, X_test, y_train, y_test = processor.preprocess_pipeline(
    df, target_column="target"
)

โš™๏ธ Configuration

Training Configuration

Create a JSON or YAML configuration file:

{
  "data_source": {
    "type": "file",
    "path": "data/train.csv"
  },
  "target_column": "target",
  "model": {
    "type": "random_forest",
    "n_estimators": 100,
    "max_depth": 10
  },
  "data_processing": {
    "missing_value_strategy": "mean",
    "scaling_method": "standard"
  },
  "cross_validation": {
    "type": "kfold",
    "n_splits": 5
  }
}

Environment Variables

Set in .env file:

# Database
DB_TYPE=postgresql
DB_HOST=localhost
DB_PORT=5432

# MLflow
MLFLOW_TRACKING_URI=http://localhost:5000

# API
API_HOST=0.0.0.0
API_PORT=8000

๐Ÿงช Testing

Run the test suite:

# Run all tests
pytest

# Run with coverage
pytest --cov=ml_service --cov-report=html

# Run specific test file
pytest tests/test_model.py

# Run with markers
pytest -m unit
pytest -m integration

๐Ÿ“š API Documentation

Start the API server and visit http://localhost:8000/docs for interactive Swagger documentation.

Example API Endpoints

Health Check:

curl http://localhost:8000/health

Make Prediction:

curl -X POST http://localhost:8000/predict \\
  -H "Content-Type: application/json" \\
  -d '{"features": [1.5, 2.3, 3.1, 4.2, 5.0]}'

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Install dev dependencies
pip install -r requirements.txt
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run code formatting
black ml_service tests
isort ml_service tests

# Run linting
flake8 ml_service tests
mypy ml_service

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • scikit-learn for ML algorithms
  • MLflow for experiment tracking
  • FastAPI for API framework
  • Pydantic for configuration management

๏ฟฝโ€๐Ÿ’ป Credits

Created by: Karan
GitHub: @kython220282
Repository: MLOps-Boilerplate

๐ŸŒŸ If You Use This Framework

If you use this framework in your projects, please consider:

  • โญ Star this repository on GitHub
  • ๐Ÿ“ Add credits in your project documentation:
    Built with [MLOps-Boilerplate](https://github.com/kython220282/MLOps-Boilerplate) by Karan
    
  • ๐Ÿ”— Link back to this repository
  • ๐Ÿ’ฌ Share your project - Open an issue to showcase what you've built!

Your support helps maintain and improve this framework for everyone. Thank you! ๐Ÿ™

๐Ÿ“ž Support

For questions and support:


Happy Model Building! ๐ŸŽ‰

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ml_service_framework-0.1.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ml_service_framework-0.1.0-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file ml_service_framework-0.1.0.tar.gz.

File metadata

  • Download URL: ml_service_framework-0.1.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for ml_service_framework-0.1.0.tar.gz
Algorithm Hash digest
SHA256 341d8f998764aa3847e8dc7866cda8ff81ddbc11a678bd4d4f8d281b44347b70
MD5 0e5e416a1ab318a3a517338271865bc2
BLAKE2b-256 18dbeb3e852fb329cc4d4ea06fb815932c90eef811f879fea9c623bacccd31fb

See more details on using hashes here.

File details

Details for the file ml_service_framework-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ml_service_framework-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fa0570877201abe34941c82ce7d5f4e0762021ff9b25b1505c07ff3bcfac666
MD5 af7ebcf5544e8d3989d93afba95431d4
BLAKE2b-256 b24735815c228e306c322f3184d8c7a826730caf1f46865ad32740bd268cca2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page