Shopper Purchase Prediction with MLflow and scikit-learn
Train, gate, register and serve a purchase prediction model with MLflow: a quality gate, a champion alias, and a REST API that also runs in Docker.
- Python
- uv
- MLflow
- scikit-learn
- pandas
Screenshots
One-off price
- ₹449+ GST, ₹529.82 in total
- $9
- Download it from your library as soon as your payment is confirmed.
- Every later release of this project is included, at no extra cost.
- Latest release
- 1.0.0 · Nov 28, 2026
- Licence
- Source Code Licence
Overview
The complete source code of a machine learning model's whole life in MLflow 3.18, in Python. Train a scikit-learn model that predicts which online shopping sessions end in a purchase, evaluate it against a quality gate, promote it to champion in the Model Registry only when it beats the version in use, and score sessions from the command line, through a REST API or from a Docker container.
Training a model is the easy part. Knowing which version is live, why it got there, and serving exactly that version is what Shopper Purchase Prediction with MLflow and scikit-learn is for, with every step recorded in MLflow.
The whole life of a model
- Train and log. A scikit-learn model logged with its signature, an input example, its exact package versions and its test ROC AUC: 0.9258 in the first run.
- Check it against a quality gate. ROC AUC of at least 0.90 and balanced accuracy of at least 0.75, and, once a champion exists, 0.01 better balanced accuracy than the champion. Every check is an MLflow run.
- Promote it.
promoteregisters each model as a new version and moves thechampionalias only when it passes. A version that fails keeps aquality_gate: failedtag, and the champion stays where it was. - Score with the champion.
predictloads whichever version is the champion and refuses files that don't match the model's signature. - Serve it.
mlflow models serveputs the champion behind a REST API,call-apisends it sessions, and the same model runs in a Docker image built by MLflow. All three gave the same probabilities. - Prove it travels.
validatepredicts the model's input example in a fresh environment built from the model's own requirements.
Safe and traceable
- A safe model format. The model is saved with skops, which loads only the types the project trusts, instead of pickle.
- The code behind each model. Every run records the Git commit of its code.
- A checked download. The data is downloaded once and its SHA-256 fingerprint checked before it's read.
Code you can build on
- A clean Python package. A
srclayout managed by uv, with six commands:train,evaluate,promote,predict,validateandcall-api. - Settings in one place. pydantic-settings reads
.env, and.env.exampledocuments every setting. - Exact versions.
uv.lockpins every package: MLflow 3.18.0, scikit-learn 1.9.1, skops 0.16.0 and Python 3.15. - No data in the archive. The project downloads the public dataset on the first run.
What it doesn't include
- No hosting. It runs on your own computer: a tracking server you start in one command, and a model server or container on the same computer.
- No test project. The results above come from real runs, not from automated tests in the archive.
Run it in seven steps
- Unzip the archive.
- Start an MLflow tracking server.
- Copy
.env.exampleto.env. - Install the packages with
uv sync. - Put the project in Git.
- Train with
uv run train. - Promote the model with
uv run promote.
The README has every command, for macOS and Linux and for PowerShell, plus serving and Docker. How to Set Up and Run the Shopper Purchase Prediction Project (opens in a new tab) shows each step with what it should print. It was tested from a clean copy of the archive on macOS.
Learn how it was built
Parts 6 to 9 of the free tutorial series MLflow Tutorial for Machine Learning in Python (opens in a new tab) explain logging and validating models, evaluation and quality gates, the Model Registry, and serving, using this code.
Free tutorial series
MLflow Tutorial for Machine Learning in Python
Prefer to learn by building it? This free, step-by-step guide on our blog shows how the project is made.
What you get
Everything in the archive, at a glance.
- Version 1.0.0 of the complete source code: a Python package managed by uv
- The train command: a scikit-learn model logged to MLflow with its signature, input example, requirements and test ROC AUC
- The evaluate command and a quality gate on ROC AUC and balanced accuracy, with a comparison against a baseline model
- The promote command, which registers each model and moves the champion alias only when the new version passes
- The predict command, which scores a CSV file of sessions with the champion and checks it against the model's signature
- The validate command, which predicts in a fresh environment built from the model's requirements
- The call-api command for a model served with mlflow models serve or from MLflow's Docker image
- Three example sessions as CSV and as a REST request body
- Settings in .env through pydantic-settings, with a documented .env.example
- A README with the setup for macOS, Linux and PowerShell, serving, Docker, every setting and the dataset's credit
Built with
The exact runtimes and versions it was built and tested against.
- Python3.15.2
- uv0.13.10
- MLflow3.18.0
- scikit-learn1.9.1
- pandas3.1.1
- NumPy2.5.5
- skops0.16.0
- pydantic-settings2.16.3
- Requests2.34.2
- Docker Engine29.9.3
What is in the archive
The file tree you get once you unzip it.
shopper-purchase-prediction-mlflow-scikit-learn/
- src/
- shopper_purchase_prediction/
- __init__.py
- call_api.py
- code_version.py
- config.py
- data.py
- evaluate.py
- model.py
- predict.py
- promote.py
- registry.py
- train.py
- validate.py
- shopper_purchase_prediction/
- examples/
- sessions.csv
- sessions.json
- .env.example
- .gitignore
- .python-version
- pyproject.toml
- uv.lock
- README.md
What it needs from you
The accounts and services it expects to find, so nothing is a surprise.
- uv, which installs Python 3.15 and the packages for you
- Git, so each run records the commit of its code
- An MLflow tracking server: the README starts one on your computer in one command
- An internet connection for the first install, about 580 MB of packages, and the first run, which downloads the data
- Optional: Docker, to run the model in a container
Releases
Every version so far, newest first.
1.0.0Latest
First release of the complete source code.
- Trains a scikit-learn model that predicts which online shopping sessions end in a purchase, and logs it to MLflow 3.18.0.
- Evaluates models against a quality gate, registers them, and promotes a version to champion only when it passes.
- Scores sessions with the champion from the command line, through mlflow models serve and from a Docker image.
- Includes a README that takes you from the archive to a champion serving predictions.
Source Code Licence
What you may do with it
What you may and may not do with the source code you buy.
Read the full licence
- What this licence covers
This licence governs every file included in a product you buy from Dewiride Store: source code, configuration, database scripts, sample data, documentation and any other file in the download. It takes effect when your payment is confirmed and applies to every release of that product that reaches your library. Files that reach your library through an annual updates membership are governed in exactly the same way.
It forms part of the Terms of Sale and Use. Where a product page states different or additional licence terms for that product, those terms prevail for that product. The membership page may likewise state different or additional licence terms for the files a membership carries, and those terms then prevail for those files.
- The licence we grant you
We grant you a perpetual, worldwide, non-exclusive, non-transferable licence to use, reproduce, adapt, translate and modify the files, and to include the result in your own work, on the conditions set out below.
Perpetual means it does not expire. Worldwide means it is not limited to any country. Non-exclusive means we license the same product to other customers. Non-transferable means you cannot pass it on to someone else.
The licence is granted to you — either you personally, or the organisation you identified when buying. Everyone working within that organisation may use the files for that organisation’s projects. Nobody outside it may.
- What you may do
- Use and change the files in your own projects, commercial or otherwise, with no limit on the number of projects.
- Build a product or a service on them and charge your own customers for it.
- Deploy the result for a client, as part of work you are doing for that client.
- Distribute the result in compiled, deployed or otherwise non-source form.
- Keep as many back-up copies as you reasonably need.
- Study, observe and test how the code works, and obtain the information you need to make it work with your own software.
The last two are yours by law under sections 52(1)(aa) to (ac) of the Indian Copyright Act, 1957, and nothing in this licence is intended to take them away.
- What you may not do
- Resell, sublicense, redistribute or publish the files themselves, in whole or in substantial part, in source form.
- Include them in a template, starter kit, course, tutorial repository or component library that you sell or give away, where the code is the thing being supplied.
- Share your account, your download links or your invoices with anyone outside your organisation.
- Publish the files in a public repository, or in any other place where they can be obtained without buying them.
- Remove or obscure the copyright and attribution notices in the source files.
- Use the files to build something whose main purpose is to compete with Dewiride Store as a supplier of the same code.
The distinction that matters is simple: you may sell what you build with the code; you may not sell the code.
- Third-party components
Our products depend on open-source libraries, frameworks and services that we did not write. Those remain under their own licences, which we do not and cannot change. Where a product includes or requires such a component, its licence is named in the product’s documentation, and complying with it is your responsibility.
- Releases
Every release of a product you own is covered by this same licence and appears in your library at no extra cost. A release you have already downloaded remains licensed to you even if we later stop publishing the product. A release that reached your library through an annual updates membership is licensed to you on these same terms, and stays licensed after the period that carried it has ended.
- Ownership
We keep ownership of the files and of the copyright in them. You own whatever you create with them: your changes, your additions and the product you build are yours.
- If this licence ends
This licence ends if you materially breach it and do not put the breach right within thirty days of us asking you to in writing. It also ends if your payment is reversed or refunded, because the purchase it depends on no longer stands. Where a membership period is refunded or reversed, the licence ends for the releases that period carried and for nothing else: anything you bought separately, or that another period carried, is unaffected.
If it ends, you must stop using the files and delete the copies you hold. Work you had already delivered to a client before that point may continue in use, so that ending this licence never breaks something your own customer relies on.
- No warranty beyond the description
The warranties and limits in section 19 and section 20 of the Terms of Sale and Use apply to this licence as well.
- Governing law
This licence is governed by the law of India, and section 24 of the Terms of Sale and Use applies to any dispute about it. If a translation and the English version differ in meaning, the English version governs.
Shopper Purchase Prediction with MLflow and scikit-learn
- ₹449+ GST, ₹529.82 in total
- $9