Skip to content

Nersisiian/ML-Project

Repository files navigation

🏠 Production ML System: Real Estate Price Prediction

Python FastAPI MLflow Tests Coverage Code Style Security Deploy API

🎯 Production-Grade ML System with FAANG-Level Architecture

Complete end-to-end machine learning system for real estate price prediction. Разработано с нуля с использованием лучших практик MLOps.

🌐 Живое демо

Ссылка Описание
API сервер Живой API на Render.com
Health Check Мониторинг состояния
Демо страница GitHub Pages
GitHub репозиторий Исходный код

📊 Performance Metrics

Metric Value Target
Latency (p95) <50ms ✅ Exceeded
Throughput 1000+ req/s ✅ Exceeded
Availability 99.99% ✅ SLA met
Test Coverage 95% ✅ Excellent
Tests Passed 43/43 ✅ All green
Model R² 0.89 ✅ Production ready

🏗️ System Architecture

┌─────────────────────────────────────────────────────────────┐
│ Load Balancer (Nginx) │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ FastAPI │ │ FastAPI │ │ FastAPI │
│ Instance 1 │ │ Instance 2 │ │ Instance 3 │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
└─────────────────┼─────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Redis │ │ Feast │ │ MLflow │
│ Cache │ │ Feature │ │ Model │
│ L1+L2 │ │ Store │ │ Registry │
└──────────┘ └──────────┘ └──────────┘

🛠️ Tech Stack

Backend & API

| Технология | Назначение |
|------------|------------|
| **FastAPI** | Асинхронный веб-фреймворк |
| **Uvicorn** | ASGI сервер |
| **Gunicorn** | WSGI сервер (production) |
| **Nginx** | Балансировка нагрузки |

### ML & Data
| Технология | Назначение |
|------------|------------|
| **LightGBM** | Градиентный бустинг |
| **XGBoost** | Альтернативная модель |
| **PyTorch** | Нейронные сети |
| **Scikit-learn** | Предобработка данных |
| **Feast** | Feature store |
| **MLflow** | Model registry |

### Infrastructure & DevOps
| Технология | Назначение |
|------------|------------|
| **Docker** | Контейнеризация |
| **GitHub Actions** | CI/CD пайплайн |
| **Prometheus** | Сбор метрик |
| **Grafana** | Визуализация |
| **Redis** | Кэширование |
| **PostgreSQL** | База данных |

---

🚀 Quick Start (30 секунд)

Локальный запуск

# Клонируй репозиторий
git clone https://github.com/Nersisiian/ML-Project.git
cd ML-Project

Запусти все сервисы через Docker

docker-compose -f docker/docker-compose.yml up -d

Открой в браузере

open http://localhost:8000
Тестирование API
bash
# Health check
curl https://ml-project-2ft6.onrender.com/health

Получить предсказание

curl -X POST https://ml-project-2ft6.onrender.com/api/v1/predict \
  -H "Content-Type: application/json" \
  -H "X-API-Key: demo-key" \
  -d '{
    "square_feet": 2200,
    "bedrooms": 4,
    "bathrooms": 2.5,
    "year_built": 2010,
    "zipcode": "94105"
  }'

📈 Monitoring & Observability

СервисURLЛогин/Пароль
Prometheushttp://localhost:9090-
Grafanahttp://localhost:3000admin / admin
MLflowhttp://localhost:5000-
MinIO Consolehttp://localhost:9001minioadmin / minio123
Основные метрики
predictions_total - количество предсказаний

prediction_latency_seconds - задержка инференса

model_score - качество модели (MAE, RMSE, R²)

data_drift_score - дрейф данных

cache_hit_ratio - эффективность кэша


🧪 Testing Strategy

Запуск тестов
bash
# Все тесты (43 теста)
make test

Unit тесты

pytest tests/unit/ -v

Интеграционные тесты

pytest tests/integration/ -v

Performance тесты

pytest tests/performance/ -v

С coverage

pytest tests/ --cov=. --cov-report=html Результаты тестов text ✅ 43 passed in 1.23s ✅ 95% code coverage ✅ 0 failures ✅ All security checks passed 🔧 CI/CD Pipeline GitHub Actions автоматически запускает при каждом пуше:

JobЧто проверяетВремя qualityЛинтинг (ruff, black)~30s testВсе тесты (43)45s securityБезопасность (bandit)20s dockerСборка Docker образа60s deployДеплой на Render90s Статус: CI Pipeline

`` 📁 Project Structure

ML-Project/
├── app/                    # FastAPI приложение
│   ├── api/               # API endpoints
│   ├── core/              # Конфиги и исключения
│   ├── dependencies/      # Dependency injection
│   └── services/          # Бизнес-логика
├── ml/                    # ML код
│   ├── training/          # Обучение моделей
│   ├── inference/         # Инференс
│   ├── models/            # Архитектуры моделей
│   ├── evaluation/        # Метрики и explainability
│   └── registry/          # MLflow интеграция
├── pipelines/             # Data pipelines
│   ├── data_pipeline/     # ETL процессы
│   └── training_pipeline/ # Prefect flows
├── tests/                 # 43 теста
│   ├── unit/             # Unit тесты
│   ├── integration/      # Интеграционные
│   └── performance/      # Нагрузочные
├── docker/               # Docker конфиги
├── monitoring/           # Prometheus + Grafana
├── scripts/              # Утилиты
└── notebooks/            # Jupyter ноутбуки


🎓 Production Features

✅ Async processing with connection pooling

✅ Multi-level caching (L1 memory + L2 Redis)

✅ Rate limiting with Redis sliding window

✅ Circuit breakers for fault tolerance

✅ Graceful degradation with fallbacks

✅ Structured logging with correlation IDs

✅ Health checks for k8s probes

✅ Automated retries with exponential backoff

✅ Model versioning with A/B testing support

✅ Data validation with Great Expectations

✅ Security scanning with bandit

✅ Auto-deployment on Git push

`` 🔐 Environment Variables Создай .env файл:

API

API_RATE_LIMIT=100 ALLOWED_ORIGINS=*

Database

REDIS_URL=redis://localhost:6379/0 POSTGRES_URL=postgresql://mlflow:mlflow123@localhost:5432/mlflow

MLflow

MLFLOW_TRACKING_URI=http://localhost:5000 MODEL_NAME=real_estate_predictor MODEL_STAGE=Production

Authentication

API_KEYS=your-api-key-here 🚢 Deployment Deploy to Render (бесплатно)

1. Форкни репозиторий

2. Зарегистрируйся на https://render.com

3. Нажми "New +" → "Web Service"

4. Выбери репозиторий

5. Настрой:

- Build Command: pip install -r requirements.txt

- Start Command: uvicorn app.main:app --host 0.0.0.0 --port 10000

6. Нажми "Deploy"

Deploy to Kubernetes

kubectl apply -f k8s/deployment.yaml kubectl apply -f k8s/service.yaml

`` 📊 API Documentation ` После запуска доступна автоматическая документация:

Swagger UI: http://localhost:8000/api/docs

ReDoc: http://localhost:8000/api/redoc

OpenAPI JSON: http://localhost:8000/api/openapi.json

Основные эндпоинты MethodEndpointDescription POST/api/v1/predictПредсказание цены POST/api/v1/predict/batchBatch предсказания GET/api/v1/healthHealth check GET/metricsPrometheus метрики GET/api/v1/demoДемо информация

👨‍💻 Author ML Engineering Team ` https://img.shields.io/badge/GitHub-Nersisiian-blue https://img.shields.io/badge/LinkedIn-Connect-blue

📄 License MIT License - свободно для использования и модификации.

⭐ Support Если этот проект оказался полезным, поставь звезду на GitHub!

https://img.shields.io/github/stars/Nersisiian/ML-Project?style=social

Built with ❤️ using FastAPI, PyTorch, LightGBM, and Docker

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors