Zum Hauptinhalt springen

Shopper Purchase Prediction with MLflow and scikit-learn

Trainieren, prüfen, registrieren und servieren Sie ein Modell für Kaufvorhersagen mit MLflow: ein Qualitäts-Gate, ein champion-Alias und eine REST-API, die auch in Docker läuft.

  • Python
  • uv
  • MLflow
  • scikit-learn
  • pandas

Bildschirmfotos

Bildschirmfoto 1 von 7: Titelbild: Shopper Purchase Prediction, Python-Quellcode für MLflow, mit seinem Stack und einem Terminal, in dem Version 1 das Qualitäts-Gate besteht und zum champion wird.

Titelbild: Shopper Purchase Prediction, Python-Quellcode für MLflow, mit seinem Stack und einem Terminal, in dem Version 1 das Qualitäts-Gate besteht und zum champion wird.

Einmaliger Preis

  • 449 ₹zzgl. GST, insgesamt 529,82 ₹
  • 9 $
  • Laden Sie es aus Ihrer Bibliothek herunter, sobald Ihre Zahlung bestätigt ist.
  • Alle künftigen Releases dieses Projekts sind ohne Aufpreis enthalten.
Neuestes Release
1.0.0 · 28.11.2026

Überblick

Der vollständige Python-Quellcode für das ganze Leben eines Modells in MLflow 3.18. Trainieren Sie ein scikit-learn-Modell, das vorhersagt, welche Sitzungen eines Onlineshops mit einem Kauf enden, prüfen Sie es gegen ein Qualitäts-Gate, machen Sie es in der Model Registry nur zum champion, wenn es die aktive Version übertrifft, und bewerten Sie Sitzungen per Kommandozeile, REST-API oder Docker.

Ein Modell zu trainieren ist der einfache Teil. Zu wissen, welche Version aktiv ist, warum sie es wurde, und genau diese Version auszuliefern, dafür ist Shopper Purchase Prediction with MLflow and scikit-learn da, mit jedem Schritt in MLflow festgehalten.

Das ganze Leben eines Modells

  • Trainieren und protokollieren. Ein scikit-learn-Modell, protokolliert mit Signatur, einem Eingabebeispiel, den exakten Paketversionen und seinem Test-ROC-AUC: 0,9258 beim ersten Lauf.
  • Gegen ein Qualitäts-Gate prüfen. Ein ROC-AUC von mindestens 0,90 und eine Balanced Accuracy von mindestens 0,75 und, sobald es einen champion gibt, eine um 0,01 höhere Balanced Accuracy als er. Jede Prüfung ist ein MLflow-Lauf.
  • Befördern. promote registriert jedes Modell als neue Version und verschiebt den Alias champion nur, wenn sie besteht. Eine durchgefallene Version behält das Tag quality_gate: failed, und der champion bleibt, wo er war.
  • Mit dem champion bewerten. predict lädt die Version, die gerade champion ist, und lehnt Dateien ab, die nicht zur Signatur des Modells passen.
  • Ausliefern. mlflow models serve stellt den champion hinter eine REST-API, call-api schickt ihm Sitzungen, und dasselbe Modell läuft in einem von MLflow gebauten Docker-Image. Alle drei lieferten dieselben Wahrscheinlichkeiten.
  • Beweisen, dass es überall läuft. validate sagt das Eingabebeispiel des Modells in einer frischen Umgebung voraus, die aus den eigenen Anforderungen des Modells gebaut wird.

Sicher und nachvollziehbar

  • Ein sicheres Modellformat. Das Modell wird statt mit pickle mit skops gespeichert, das nur die Typen lädt, denen das Projekt vertraut.
  • Der Code hinter jedem Modell. Jeder Lauf hält den Git-Commit seines Codes fest.
  • Ein geprüfter Download. Die Daten werden einmal heruntergeladen, und ihr SHA-256-Fingerabdruck wird vor dem Lesen geprüft.

Code, auf dem Sie aufbauen können

  • Ein sauberes Python-Paket. Eine src-Struktur, verwaltet mit uv, mit sechs Befehlen: train, evaluate, promote, predict, validate und call-api.
  • Einstellungen an einem Ort. pydantic-settings liest .env, und .env.example dokumentiert jede Einstellung.
  • Exakte Versionen. uv.lock legt jedes Paket fest: MLflow 3.18.0, scikit-learn 1.9.1, skops 0.16.0 und Python 3.15.
  • Keine Daten im Archiv. Das Projekt lädt den öffentlichen Datensatz beim ersten Lauf herunter.

Was nicht enthalten ist

  • Kein Hosting. Es läuft auf Ihrem eigenen Rechner: ein Tracking-Server, den Sie mit einem Befehl starten, und ein Modellserver oder Container auf demselben Rechner.
  • Kein Testprojekt. Die Ergebnisse oben stammen aus echten Läufen, nicht aus automatisierten Tests im Archiv.

In sieben Schritten zum Laufen bringen

  1. Entpacken Sie das Archiv.
  2. Starten Sie einen MLflow-Tracking-Server.
  3. Kopieren Sie .env.example nach .env.
  4. Installieren Sie die Pakete mit uv sync.
  5. Legen Sie das Projekt in Git an.
  6. Trainieren Sie mit uv run train.
  7. Befördern Sie das Modell mit uv run promote.

Die README enthält jeden Befehl, für macOS und Linux und für PowerShell, dazu den Modellserver und Docker. How to Set Up and Run the Shopper Purchase Prediction Project (öffnet in einem neuen Tab) (auf Englisch) zeigt jeden Schritt mit seiner Ausgabe. Getestet wurde mit einer frischen Kopie des Archivs unter macOS.

So wurde es gebaut

Die Teile 6 bis 9 der kostenlosen Tutorial-Reihe MLflow Tutorial for Machine Learning in Python (öffnet in einem neuen Tab) (auf Englisch) erklären anhand dieses Codes das Protokollieren und Prüfen von Modellen, Evaluierung und Qualitäts-Gates, die Model Registry und das Ausliefern von Modellen.

Kostenlose Tutorial-Reihe

MLflow Tutorial for Machine Learning in Python

Sie lernen lieber beim Nachbauen? Diese kostenlose Schritt-für-Schritt-Anleitung in unserem Blog zeigt, wie das Projekt entsteht.

Reihe lesen (öffnet in einem neuen Tab)

Das bekommen Sie

Alles im Archiv, auf einen Blick.

  • Version 1.0.0 des vollständigen Quellcodes: ein mit uv verwaltetes Python-Paket
  • Der Befehl train: ein scikit-learn-Modell, in MLflow protokolliert mit Signatur, Eingabebeispiel, Anforderungen und Test-ROC-AUC
  • Der Befehl evaluate und ein Qualitäts-Gate für ROC-AUC und Balanced Accuracy, mit Vergleich gegen ein Referenzmodell
  • Der Befehl promote, der jedes Modell registriert und den champion-Alias nur verschiebt, wenn die neue Version besteht
  • Der Befehl predict, der eine CSV-Datei mit Sitzungen mit dem champion bewertet und gegen die Signatur des Modells prüft
  • Der Befehl validate, der in einer frischen Umgebung aus den Anforderungen des Modells vorhersagt
  • Der Befehl call-api für ein Modell, das mit mlflow models serve oder aus dem Docker-Image von MLflow ausgeliefert wird
  • Drei Beispielsitzungen als CSV und als Body einer REST-Anfrage
  • Einstellungen in .env über pydantic-settings, mit einer dokumentierten .env.example
  • Eine README mit der Einrichtung für macOS, Linux und PowerShell, dem Modellserver, Docker, jeder Einstellung und der Quellenangabe des Datensatzes

Gebaut mit

Die genauen Laufzeitumgebungen und Versionen, mit denen gebaut und getestet wurde.

  • 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

Was im Archiv liegt

Der Dateibaum, den Sie nach dem Entpacken vor sich haben.

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
  • examples/
    • sessions.csv
    • sessions.json
  • .env.example
  • .gitignore
  • .python-version
  • pyproject.toml
  • uv.lock
  • README.md

Was es von Ihnen braucht

Die Konten und Dienste, die es voraussetzt, damit Sie später nichts überrascht.

  • uv, das Python 3.15 und die Pakete für Sie installiert
  • Git, damit jeder Lauf den Commit seines Codes festhält
  • Einen MLflow-Tracking-Server: Die README startet einen auf Ihrem Rechner mit einem Befehl
  • Eine Internetverbindung für die erste Installation, rund 580 MB Pakete, und den ersten Lauf, der die Daten herunterlädt
  • Optional: Docker, um das Modell in einem Container auszuführen

Versionen

Alle bisherigen Versionen, die neueste zuerst.

  1. 1.0.0Neueste

    Erstes Release des vollständigen Quellcodes.

    • Trainiert ein scikit-learn-Modell, das vorhersagt, welche Sitzungen eines Onlineshops mit einem Kauf enden, und protokolliert es in MLflow 3.18.0.
    • Prüft Modelle gegen ein Qualitäts-Gate, registriert sie und befördert eine Version nur dann zum champion, wenn sie besteht.
    • Bewertet Sitzungen mit dem champion per Kommandozeile, über mlflow models serve und aus einem Docker-Image.
    • Enthält eine README, die Sie vom Archiv bis zu einem champion führt, der Vorhersagen ausliefert.

Source Code Licence

Was Sie damit tun dürfen

What you may and may not do with the source code you buy.

Vollständige Lizenz lesen
  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.