Skip to main content

1. What is MLOps?

MLOps (Machine Learning Operations) is the practice of applying software engineering and DevOps principles to the complete machine-learning lifecycle. A typical ML project involves:
MLOps automates and manages this entire workflow.

Why MLOps is needed

A model working inside a Jupyter Notebook is not enough for a production application. An ML system needs to handle:
  • Data ingestion
  • Data preprocessing
  • Model training
  • Model evaluation
  • Experiment tracking
  • Model versioning
  • Model deployment
  • API serving
  • Monitoring
  • Retraining
  • Automation

2. Traditional ML vs MLOps

Without MLOps

Problems:
  • Difficult to reproduce experiments
  • Model versions can be confusing
  • Manual deployment
  • Difficult to monitor
  • Difficult to retrain
  • Difficult to track data/model changes

With MLOps


3. End-to-End MLOps Pipeline

The main pipeline can be divided into four stages:

1. Ingest

Collect and prepare data.

2. Train

Train and evaluate the ML model.

3. Serve

Expose the trained model through an API.

4. Monitor

Monitor the deployed application.

4. Project Structure

A simple MLOps project can be organized as:
For the learning example, the pipeline will use the Diabetes dataset from scikit-learn.

5. Technologies Used


6. Step 1 – Data Ingestion

Data ingestion means obtaining data and making it available to the ML pipeline. For this example, use the Diabetes dataset.

Cell 1 – Imports


Cell 2 – Load Dataset

Example output:

Cell 3 – Save Data

The resulting structure:

7. Step 2 – Data Preparation

Separate the features and target.
Here:

8. Step 3 – Train/Test Split

The dataset is divided into training and testing data.

Why split the dataset?

The training set is used to learn patterns. The testing set is used to evaluate how well the model performs on unseen data.

9. Step 4 – Model Training

Use Linear Regression.

10. Step 5 – Model Evaluation

Generate predictions:
Calculate metrics:

Important metrics

MSE
RMSE
Measures how much of the target variation is explained by the model.

11. Step 6 – Experiment Tracking with MLflow

MLflow records information about ML experiments. It can track:
For example:

12. MLflow Configuration

Install MLflow:
Then configure it.

Cell 4 – MLflow


13. Step 7 – Log the Training Run


14. Step 8 – Register the Model

The trained model can be registered in MLflow.
MLflow will create something like:
If another model is registered later:

15. Viewing MLflow UI

Start MLflow from the project directory:
On Git Bash, this can also be written as:
Open:
The UI allows inspection of:

16. Step 9 – Model Serving

After registering the model, expose it through FastAPI. Create:

17. Start FastAPI

From the project root:
API:
Swagger documentation:

18. Test the Prediction API

The Diabetes dataset contains 10 features, so the request should contain 10 values. Example:
Example response:

19. Step 10 – Monitoring

Once the model is deployed, the application should be monitored. Important metrics include:
Prometheus collects metrics. Grafana visualizes them.

20. Prometheus Metrics

Install:
Example:
Create a counter:
Increment it:
Expose /metrics:
Prometheus can then scrape:

21. Prometheus Configuration

Create:

22. Run Prometheus with Docker

From Git Bash:
Open:
Check:
You should see:

23. Query API Metrics

In Prometheus, go to:
Run:
After requesting:
the counter increases. For example:

24. Grafana

Grafana provides dashboards for visualizing Prometheus metrics. Architecture:
Typical dashboard panels:
Prometheus:
Grafana commonly runs at:

25. Step 11 – Docker

Docker packages the application and its dependencies. Instead of:
being manually installed on every machine, Docker creates a reproducible environment. Example:
Build:
Run:

26. Step 12 – Automation

An MLOps pipeline should eventually be automated. For example:
This removes many manual steps.

27. Complete MLOps Architecture

The complete learning architecture is:

28. Automation with Scripts

Instead of putting everything into one notebook, production pipelines usually separate responsibilities.

train.py

serve.py

monitor.py


29. Example train.py

A simple standalone training script:
Run:

30. MLOps Pipeline Execution

The complete execution becomes:

Step 1 — Install dependencies

Step 2 — Train

Step 3 — Start MLflow

Step 4 — Start FastAPI

Step 5 — Start Prometheus

Step 6 — Start Grafana


31. Important MLOps Concepts

These are important topics to understand beyond the basic pipeline:

Experiment Tracking

Track:
Tool:

Model Registry

Store and manage:

Model Versioning

Example:

Model Serving

Expose models through:

Containerization

Package the application using:

Monitoring

Track:
Tools:

CI/CD

Automate:
Tool:

Data Drift

A change in the distribution of input data over time.

Model Drift

When model performance decreases because the relationship between inputs and target changes.

Retraining

When drift or new data requires the model to be trained again:

32. Final MLOps Lifecycle

Key takeaway

The main idea of MLOps is:
For this project, the practical flow is: