MLOps API A production-ready MLOps API for serving machine learning predictions with automated data pipelines and experiment tracking.
π Overview This project provides a REST API to serve ML model predictions, automating the full pipeline from raw data ingestion to model inference. Experiment tracking and model versioning are handled via MLflow, making it easy to compare runs and deploy the best-performing model.
β¨ Features
β‘ FastAPI β high-performance REST endpoints for real-time predictions π Automated Data Pipeline β handles preprocessing and feature engineering automatically π§ͺ MLflow Tracking β logs experiments, parameters, metrics, and model versions π€ Scikit-learn Models β trained, versioned, and served via API π Prediction Endpoint β send raw input, get back predictions instantly
π οΈ Tech Stack ToolPurposeFastAPIREST API frameworkScikit-learnML model training & inferenceMLflowExperiment tracking & model registryUvicornASGI serverPandas / NumPyData pipeline & preprocessing
π Project Structure mlops-api/ β βββ app/ β βββ main.py # FastAPI app & routes β βββ model.py # Model loading & prediction logic β βββ pipeline.py # Data preprocessing pipeline β βββ mlflow/ β βββ experiments/ # MLflow tracked runs β βββ models/ β βββ model.pkl # Trained scikit-learn model β βββ requirements.txt βββ README.md
βοΈ Getting Started
- Clone the repository bashgit clone https://github.com/yuvrajrajput/mlops-api.git cd mlops-api
- Install dependencies bashpip install -r requirements.txt
- Start the API bashuvicorn app.main:app --reload
- Launch MLflow UI bashmlflow ui Open http://localhost:5000 to view experiments.
π‘ API Usage Predict Endpoint POST /predict json// Request { "feature_1": 5.1, "feature_2": 3.5, "feature_3": 1.4 }
// Response { "prediction": 1, "confidence": 0.94 } Health Check GET /health json{ "status": "ok" }
π MLflow Experiment Tracking All training runs are tracked with:
Model parameters (e.g. n_estimators, max_depth) Metrics (accuracy, F1, AUC) Artifacts (trained model, confusion matrix)
To register the best model: bashmlflow models serve -m "models:/BestModel/Production" --port 1234