How to Set Up and Run the Shopper Purchase Prediction Project with MLflow and scikit-learn
You've downloaded the Shopper Purchase Prediction source code, and you want to see it working. This post takes you from the zip file to a model that MLflow has registered, checked against a quality gate and made the champion, scoring shopping sessions through a REST API, one step at a time, with what each step should print.
You don't need to have read the tutorial series first. By the end, you'll have:
- an MLflow tracking server running on your own computer, with its UI at
http://127.0.0.1:8080; - the project installed and in Git, so every run records the version of the code that produced it;
- a trained model, logged with its signature and an input example;
- version 1 of
shopper-purchase-predictionin the Model Registry, past the quality gate and markedchampion; - the champion scoring sessions from the command line, through a REST API, and, if you have Docker, from a container.
Everything on this page is real output, from a fresh copy of the archive on macOS, in zsh. The PowerShell lines were run in PowerShell 7.6.
Get the Source Code
The archive holds everything this post installs and runs. After you buy it, you'll find it in your library on the store, as one zip file.
What You Need
- uv. uv installs Python and every package the project needs. If your computer doesn't have Python 3.15, uv downloads it for you.
- Git. Every run records the Git commit of the code that produced it.
- A terminal. On macOS or Linux, that's zsh or bash. On Windows, it's PowerShell.
- An internet connection for the install, about 580 MB of packages, and for the first training run, which downloads the data, about 1 MB.
- Docker, only for Step 11, which runs the model in a container.
Check the first two in your terminal:
uv --version
git --version
uv 0.13.10 (e3e7c1eac 2026-11-24 aarch64-apple-darwin)
git version 2.56.1
Your numbers can be higher than these.
What it costs: MLflow, scikit-learn, uv and Python are free and open source, and everything runs on your own computer. The dataset is free to use under its CC BY 4.0 licence. For Step 11, Docker Desktop is free under Docker's licence terms for "Small businesses (fewer than 250 employees AND less than $10 million in annual revenue)", personal use, education and non-commercial open source projects; it "requires a paid subscription" for professional use in larger organizations and for government entities.
Step 1: Unzip the Archive
Open a terminal in the folder where you saved the zip file.
- macOS / Linux
- Windows (PowerShell)
unzip shopper-purchase-prediction-mlflow-scikit-learn-1.0.0.zip
cd shopper-purchase-prediction-mlflow-scikit-learn
Expand-Archive -Path shopper-purchase-prediction-mlflow-scikit-learn-1.0.0.zip -DestinationPath .
Set-Location shopper-purchase-prediction-mlflow-scikit-learn
This is what you've got:
├── README.md These same steps, every command and every setting
├── pyproject.toml The project, its packages and its six commands
├── uv.lock The exact version of every package
├── .python-version Python 3.15
├── .env.example The settings, with their defaults
├── .gitignore
├── examples/
│ ├── sessions.csv Three sessions to score
│ └── sessions.json The same sessions, as the body of a REST request
└── src/
└── shopper_purchase_prediction/
├── train.py The train command
├── model.py The model, and the types its file may load
├── evaluate.py The evaluate command and the quality gate
├── promote.py The promote command
├── registry.py Finds the version the champion alias points to
├── predict.py The predict command
├── validate.py The validate command
├── call_api.py The call-api command
├── data.py Downloads the data once, checks it and splits it
├── config.py The settings
├── code_version.py The Git commit each run records
└── __init__.py
Step 2: Start an MLflow Tracking Server
The project doesn't keep its runs and models itself. It sends them to an MLflow tracking server: a small web application that stores them in a database and shows them in your browser. The server lives in a folder of its own, next to the project. If you already run one for another project of the series, keep it running and go to Step 3.
Go up to the folder that holds the project, and create the server's folder there:
cd ..
uv init --bare --python 3.15 mlflow-server
Initialized project `mlflow-server` at `/Users/you/source/mlflow-server`
--bare creates only a pyproject.toml file, because this folder only runs a server. --python 3.15 records that it needs Python 3.15 or newer. Now install MLflow in it:
cd mlflow-server
uv add mlflow
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3
Creating virtual environment at: .venv
Resolved 92 packages in 21ms
Installed 88 packages in 811ms
...
+ mlflow==3.18.0
+ mlflow-skinny==3.18.0
...
Then start the server:
uv run mlflow server --port 8080
Backend store URI not provided. Using sqlite:///mlflow.db
Registry store URI not provided. Using backend store URI.
2026/11/28 16:07:51 INFO mlflow.store.db.utils: Creating initial MLflow database tables...
2026/11/28 16:07:51 INFO mlflow.store.db.utils: Updating database tables
[MLflow] Security middleware enabled with default settings (localhost-only). To allow connections from other hosts, use --host 0.0.0.0 and configure --allowed-hosts and --cors-allowed-origins.
2026/11/28 16:07:52 INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
...
2026/11/28 16:07:54 INFO: Application startup complete.

sqlite:///mlflow.db: the runs go into a database file inmlflow-server, and the files each run saves, including the models, intomlflow-server/mlartifacts.Registry store URI not providedmeans the Model Registry, which Step 8 uses, keeps its versions in the same database. How to See Where MLflow Stores Runs and Artifacts shows both.--port 8080: MLflow's usual port, 5000, belongs to AirPlay Receiver on a Mac, so the project uses 8080 on every system. How to Change the MLflow Server Port covers other ports.- Four
StarletteDeprecationWarningmessages, which the excerpt leaves out, come from MLflow's own code, one per worker. They're harmless: Fixed: "StarletteDeprecationWarning: starlette.middleware.wsgi is deprecated" When You Start the MLflow Server explains them.
Leave this terminal open: the server runs as long as it does. How to Start an MLflow Tracking Server on Your Computer explains every option of mlflow server.
Step 3: Create Your Settings File
Open a second terminal in the shopper-purchase-prediction-mlflow-scikit-learn folder, and copy the example settings to .env, the file the project reads them from:
- macOS / Linux
- Windows (PowerShell)
cp .env.example .env
Copy-Item .env.example .env
Nothing is printed. This is the file you've just made:
# The MLflow tracking server this project sends its runs and models to.
MLFLOW_TRACKING_URI=http://127.0.0.1:8080
# The MLflow experiment that groups this project's runs and models.
MLFLOW_EXPERIMENT_NAME=shopper-purchase-prediction
# The folder that keeps the downloaded dataset, relative to the project folder.
SHOPPER_DATA_DIR=data
# The registered model in the MLflow Model Registry that holds this project's model versions.
SHOPPER_REGISTERED_MODEL_NAME=shopper-purchase-prediction
# The model server that `uv run call-api` sends sessions to: mlflow models serve, or the Docker container.
SHOPPER_SERVING_URL=http://127.0.0.1:5001
The defaults match the server from Step 2 and the model server from Step 10, so there's nothing to change. Git ignores .env, so your own settings never end up in a commit.
Step 4: Install the Packages
uv sync
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
Creating virtual environment at: .venv
Resolved 95 packages in 5ms
Built shopper-purchase-prediction @ file:///Users/you/source/shopper-purchase-prediction-mlflow-scikit-learn
Prepared 1 package in 6ms
Installed 92 packages in 912ms
+ aiohappyeyeballs==2.7.1
...
+ zipp==4.1.2

uv sync creates the project's own environment in .venv and installs exactly the versions uv.lock lists, so you get the same packages the project was tested with. It also installs the project itself, which is what makes its six commands work with uv run.
Step 5: Put the Project in Git
Every run records the Git commit the code is at, so that months later you can still tell which code produced a model. That needs a Git repository:
git init -b main
Initialized empty Git repository in /Users/you/source/shopper-purchase-prediction-mlflow-scikit-learn/.git/
git add .
git commit -m "Shopper purchase prediction 1.0.0"
[main (root-commit) f2cb6ae] Shopper purchase prediction 1.0.0
20 files changed, 2755 insertions(+)
create mode 100644 .env.example
create mode 100644 .gitignore
...
create mode 100644 src/shopper_purchase_prediction/validate.py
create mode 100644 uv.lock

.env and .venv aren't in the list: .gitignore keeps them out, and the data folder the first run creates is ignored too. If Git asks who you are, How to Create a Git Repository and Make Your First Commit shows how to set your name and email. Your commit's hash, f2cb6ae here, will be different.
Step 6: Train Your First Model
uv run train --run-name first-model --class-weight balanced
2026/11/28 15:45:40 INFO mlflow.tracking.fluent: Experiment with name 'shopper-purchase-prediction' does not exist. Creating a new experiment.
2026/11/28 15:45:40 INFO shopper_purchase_prediction: Loading the online shoppers data
2026/11/28 15:45:40 INFO shopper_purchase_prediction.data: Downloading the online shoppers data from https://archive.ics.uci.edu/static/public/468/online+shoppers+purchasing+intention+dataset.zip
2026/11/28 15:46:43 INFO shopper_purchase_prediction: Training on 9864 sessions
2026/11/28 15:46:45 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/shopper-purchase-prediction-mlflow-scikit-learn
2026/11/28 15:46:51 INFO mlflow.utils.uv_utils: Detected uv project: found uv.lock and pyproject.toml in /Users/you/source/shopper-purchase-prediction-mlflow-scikit-learn
2026/11/28 15:46:51 INFO mlflow.utils.environment: Detected uv project at /Users/you/source/shopper-purchase-prediction-mlflow-scikit-learn. Attempting to export requirements via 'uv export'.
2026/11/28 15:46:51 INFO mlflow.utils.uv_utils: Exported 92 dependencies via uv
2026/11/28 15:46:51 INFO mlflow.utils.environment: Successfully exported 92 requirements from uv project. Skipping package capture based inference.
2026/11/28 15:46:51 INFO shopper_purchase_prediction: Run first-model logged the model models:/m-20741d86688449b3ada3daf43cb73ba7, test ROC AUC 0.9258
🏃 View run first-model at: http://127.0.0.1:8080/#/experiments/3/runs/9f0c476b6872450bb1dc5f8ab9e5200a
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/3

Line by line:
Creating a new experiment: the first run creates theshopper-purchase-predictionexperiment. I ran all three projects of the series against one server, so it's experiment 3 here; on your server, the number may differ.Downloading the online shoppers data: the project downloads the dataset once into itsdatafolder, checks its SHA-256 fingerprint, and reads that copy from then on.Training on 9864 sessions: 80% of the 12,330 sessions. The other 2,466 are kept back for testing.Exported 92 dependencies via uv: MLflow saves the exact package versions next to the model, so the model can be loaded in a fresh environment later. Step 10 does exactly that.logged the model models:/m-…: the model's own ID. Copy yours: Step 8 needs it.--class-weight balancedmakes the sessions that ended in a purchase, 1,908 of the 12,330 or about 15%, count as much, together, as all the others.
Step 7: Find the Model in MLflow
Open http://127.0.0.1:8080 in your browser. On your first visit, MLflow opens in GenAI mode, with the MLflow Assistant panel on the right. Recent Experiments lists every experiment on the server: here the two other projects of the series as well, because they share it.

GenAI mode is for apps built on language models. This project trains a classic model, so:
- Click Model training at the top of the sidebar.
- Close the MLflow Assistant panel with the X in its top-right corner.

MLflow remembers both choices in your browser. Click shopper-purchase-prediction. By the end of Step 8, its runs page has two runs:

first-model is the training run from Step 6. Open Models in the experiment's sidebar to see the model it logged:

The model is its own object in MLflow, with the ID from Step 6. I took this screenshot after Step 8: Registered models and Dataset come from promoting the model and checking it on the shopper-test sessions.
Step 8: Promote It to Champion
promote registers the model as a new version of shopper-purchase-prediction, checks it against the quality gate, and makes it the champion only when it passes. Use your own model ID from Step 6:
uv run promote --model-uri models:/m-20741d86688449b3ada3daf43cb73ba7
Successfully registered model 'shopper-purchase-prediction'.
2026/11/28 15:47:00 INFO mlflow.store.model_registry.abstract_store: Waiting up to 300 seconds for model version to finish creation. Model name: shopper-purchase-prediction, version 1
Created version '1' of model 'shopper-purchase-prediction'.
2026/11/28 15:47:00 INFO shopper_purchase_prediction: Loading the online shoppers data
2026/11/28 15:47:00 INFO shopper_purchase_prediction: Evaluating models:/m-20741d86688449b3ada3daf43cb73ba7 on 2466 test sessions
2026/11/28 15:47:06 INFO mlflow.tracking.fluent: Active model is set to the logged model with ID: m-20741d86688449b3ada3daf43cb73ba7
2026/11/28 15:47:06 INFO mlflow.tracking.fluent: Use `mlflow.set_active_model` to set the active model to a different one if needed.
2026/11/28 15:47:06 INFO mlflow.models.evaluation.evaluators.classifier: The evaluation dataset is inferred as binary dataset, positive label is 1, negative label is 0.
2026/11/28 15:47:06 INFO mlflow.models.evaluation.default_evaluator: Testing metrics on first row...
model
roc_auc 0.9258
balanced_accuracy 0.8289
recall_score 0.7696
precision_score 0.5579
f1_score 0.6469
accuracy_score 0.8698
log_loss 0.2865
2026/11/28 15:47:08 INFO mlflow.models.evaluation.validation: Validating candidate model metrics against baseline
2026/11/28 15:47:08 INFO mlflow.models.evaluation.validation: Model validation passed!
2026/11/28 15:47:08 INFO shopper_purchase_prediction: models:/m-20741d86688449b3ada3daf43cb73ba7 passed the quality gate
🏃 View run rare-quail-206 at: http://127.0.0.1:8080/#/experiments/3/runs/1ba326a0409a431692ce39f093f4d4ad
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/3
2026/11/28 15:47:08 INFO shopper_purchase_prediction: Version 1 of shopper-purchase-prediction is the new champion

The quality gate asks for a ROC AUC of at least 0.90 and a balanced accuracy of at least 0.75: this model scored 0.9258 and 0.8289. There was no champion yet, so that was all it had to beat. Next time, promote also requires a balanced accuracy at least 0.01 above the current champion's, and leaves the champion where it is when the new version doesn't make it. Validating candidate model metrics against baseline is MLflow's own wording, printed even when there's no baseline to compare with.
Click Model registry in MLflow's sidebar, then shopper-purchase-prediction:

Click Version 1:

@championmarks the version in use. The project'spredictcommand, the model server in Step 10 and the Docker image in Step 11 all ask MLflow for whichever version has this alias.quality_gate: passedrecords the verdict on the version itself, andquality_gate_run_idpoints to the run that holds the scores behind it.- Schema shows the model's signature: 17 columns in, one result out.
That run is the second one on the experiment's runs page, rare-quail-206 here, named by MLflow:

Step 9: Score Sessions with the Champion
examples/sessions.csv holds three shopping sessions. predict scores them with the champion:
uv run predict --input examples/sessions.csv
2026/11/28 15:47:10 INFO shopper_purchase_prediction: Scoring with version 1 of shopper-purchase-prediction, the champion
session purchase_probability
1 0.8931
2 0.0009
3 0.0033

The first session is very likely to end in a purchase, the other two almost certainly not. --output scored.csv writes every session with its probability to a file instead. To score your own sessions, give predict a CSV file with the same 17 columns as examples/sessions.csv.
Step 10: Serve the Champion as a REST API
mlflow models serve puts the champion behind a REST API, so any program can send it sessions over HTTP. The mlflow command doesn't read .env by itself, so --env-file .env gives it the tracking server's address. Run it in a third terminal, in the project folder:
uv run mlflow --env-file .env models serve -m "models:/shopper-purchase-prediction@champion" -p 5001 --env-manager uv
Loaded environment variables from: .env
2026/11/28 15:47:26 INFO mlflow.models.flavor_backend_registry: Selected backend for flavor 'python_function'
2026/11/28 15:47:26 INFO mlflow.utils.virtualenv: Creating a new environment in /Users/you/.mlflow/envs/mlflow-7735733f20ba64ed6cf58b815ae0ed61cb4368db with python version 3.15.2 using uv
...
INFO: Started server process [79631]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:5001 (Press CTRL+C to quit)

-m "models:/shopper-purchase-prediction@champion": serve the version the alias points to. MLflow looks the alias up once, when the server starts.--env-manager uv: build a fresh environment from the model's own requirements, in.mlflow/envsin your home folder, so the server doesn't depend on the project's.venv. The first start takes a minute or two; it took about 100 seconds here.-p 5001: the portSHOPPER_SERVING_URLin.envpoints to.
When it says Application startup complete, go back to the second terminal and send it the same three sessions:
uv run call-api --input examples/sessions.csv
session purchase_probability
1 0.8931
2 0.0009
3 0.0033

The same probabilities as predict: the REST API runs the same model. Press Ctrl+C in the third terminal to stop the model server when you're done. Part 9 of the series explains the server's endpoints and the formats it accepts.
Step 11: Run It in Docker
Skip this step if you don't use Docker. How to Check the Docker Version and That Docker Is Running with docker version shows how to check that Docker is ready. With the model server from Step 10 stopped, build an image of the champion:
uv run mlflow --env-file .env models build-docker -m "models:/shopper-purchase-prediction@champion" -n shopper-purchase-prediction --env-manager local
Loaded environment variables from: .env
2026/11/28 15:49:34 INFO mlflow.models.flavor_backend_registry: Selected backend for flavor 'python_function'
2026/11/28 15:49:34 INFO mlflow.pyfunc.backend: Building docker image with name shopper-purchase-prediction
[+] Building 233.6s (14/14) FINISHED
...
=> [5/9] RUN pip install mlflow==3.18.0
...
=> => naming to docker.io/library/shopper-purchase-prediction
The build took about 4 minutes here, most of it installing MLflow into the image, and the image takes 1.25 GB. Then run it, on the same port the model server used:
docker run -d --name shopper-api --platform linux/amd64 -e MLFLOW_MODELS_WORKERS=2 -p 127.0.0.1:5001:8080 shopper-purchase-prediction
05a0fcb2ab2aa4180248a10b7e1dc3528fae4686b8b86e62b5f743d3181572ad
That long number is the new container's ID. Give it a few seconds to start, and send it the sessions:
uv run call-api --input examples/sessions.csv
session purchase_probability
1 0.8931
2 0.0009
3 0.0033

The container gives the same answers. --platform linux/amd64 runs the image on the platform MLflow's Dockerfile builds for, which Docker emulates on Apple silicon. -p 127.0.0.1:5001:8080 makes the container reachable from your computer only. Part 9 explains each option. To stop and remove the container, then the image:
docker stop shopper-api
docker rm shopper-api
docker image rm shopper-purchase-prediction
shopper-api
shopper-api
Untagged: shopper-purchase-prediction:latest
Deleted: sha256:a65e638b30de0a8bd9c42ac108260300a6728171d34548412cd4b70215a57d2f
How to Stop and Remove a Docker Container explains the first two.
Stop It, and Start It Again Later
To stop the tracking server, press Ctrl+C in its terminal:
^C2026/11/28 16:07:56 INFO: Shutting down
Traceback (most recent call last):
...
KeyboardInterrupt
...
2026/11/28 16:07:56 INFO: Stopping parent process [92053]
The KeyboardInterrupt traceback comes from the server's background job runner, and the server still stops cleanly. Fixed: "Exception ignored on threading shutdown" KeyboardInterrupt When You Stop the MLflow Server explains it, and shows how to turn the job runner off when you don't need it.
Your runs, models and registry stay in mlflow-server/mlflow.db and mlflow-server/mlartifacts. Next time, start the server from its folder, then work from the project's folder in a second terminal:
uv run mlflow server --port 8080
uv run predict --input examples/sessions.csv
To try a new model, train it, then promote it with its own ID. It becomes the champion only if it beats the current one.
Find Your Way Around the Code
| To change | Look in |
|---|---|
| The model | model.py: the text columns are one-hot encoded, then a HistGradientBoostingClassifier predicts |
| What a training run logs | train.py: the signature, the input example and the linked test score |
| The quality gate's thresholds | quality_gate() in evaluate.py |
| What promotion does | promote.py |
| The alias that marks the version in use | CHAMPION in registry.py |
| Where the runs, models and versions go | MLFLOW_TRACKING_URI, MLFLOW_EXPERIMENT_NAME and SHOPPER_REGISTERED_MODEL_NAME in .env |
The model server call-api talks to | SHOPPER_SERVING_URL in .env |
Before You Go to Production
What you've just run is a tracking server and a model server for one person, on one computer. Part 10 of the series goes through the whole checklist. In short:
- Commit before you train. A model records the last commit, not changes you haven't committed.
- Back the server up. It holds your models and the registry. How to Back Up an MLflow Tracking Server copies the database and the artifacts safely while the server runs.
- Upgrade MLflow with a backup first. How to Upgrade an MLflow Tracking Database with mlflow db upgrade shows why.
- Open the servers to other computers only on purpose. Both accept local connections only. How to Let an MLflow Server Accept Another Host Name with --allowed-hosts is the first step for the tracking server.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Skipping Step 5 | Each run says Found no Git commit for the project, so the run won't record one, and records no commit | Put the folder in Git and commit, then train |
| Copying the model ID from this page | promote looks for a model that isn't on your server | Use the ID your own train printed |
Running mlflow models serve without --env-file .env | The command uses a new local database, and can't find the champion | Add --env-file .env, as in Step 10 |
Running predict before promote | No version of shopper-purchase-prediction has the champion alias yet | Promote a model first, or pass --model-uri |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
MlflowException: API request to … failed with exception … Max retries exceeded | The tracking server isn't running, or runs on another port | Fixed: "MlflowException: API request to … failed with exception … Max retries exceeded" Connection Refused in MLflow |
| "Access to localhost was denied" in the browser | Something else, such as AirPlay Receiver, answers on that port | Fixed: "Access to localhost was denied" HTTP ERROR 403 When You Open the MLflow UI on a Mac |
Can't reach the model server at http://127.0.0.1:5001. Is it running? from call-api | The model server or the container isn't running | Start it, and wait for Application startup complete |
Exception ignored on threading shutdown or another KeyboardInterrupt traceback when you stop the tracking server | Ctrl+C interrupts the server's background job runner | Nothing to fix: Fixed: "Exception ignored on threading shutdown" KeyboardInterrupt When You Stop the MLflow Server |
FAQ
Do I need to read the tutorial series first?
No. This post is all you need to run the project. The series explains how each piece works, from Part 6 to Part 9 for this project.
What does validate do?
uv run validate --model-uri <model> builds a fresh environment from the model's own requirements and predicts its input example there, to prove the model doesn't depend on the project's .venv. Part 6 shows it.
Can I evaluate a model without promoting it?
Yes: uv run evaluate --model-uri <model> checks the gate without touching the registry, and --baseline-uri <model> compares it with another model. Part 7 explains the gate.
Does it run on Windows?
The steps are the same in PowerShell: only unzipping the archive and copying the settings file differ, and both have a PowerShell tab above. I ran those two in PowerShell 7.6 on macOS, not on Windows.
Conclusion
From the zip file to a champion took seven steps: unzip, start a tracking server, create .env, run uv sync, commit, train and promote. Version 1 passed the quality gate with a ROC AUC of 0.9258 and a balanced accuracy of 0.8289, and scored the same three sessions identically from the command line, through mlflow models serve and from a Docker container.
Additional Resources
README.mdin the archive: every command, option and setting.- MLflow Tutorial for Machine Learning in Python: the free series that builds this project.
- MLflow Model Registry: versions and aliases, in MLflow's own guide.
- Online Shoppers Purchasing Intention dataset: the data and its notes.
