Use your model in Python¶
Time: about 5 minutes · You need: a registered model (any classification or regression model works, such as the one from Your first model) and Python 3.11, 3.12 or 3.13. · You'll end with: predictions from your model in your own Python code, with no ParleML server running.
Every registered model can be downloaded as a small scoring package: the trained model, a
requirements.txt that pins the exact libraries it needs, and a ready-to-run score.py.
1. Download the package¶
In the app, open Models, then your model. In the page header, choose Python package. You
get a zip such as customer-churn-baseline-1a2b3c4d-python-package.zip. Unzip it:
customer-churn-baseline-package/
├── README.md
├── requirements.txt
├── score.py
└── model/bundle/ the trained model
Can't find the model?
A model appears under Models once you register it. On the experiment page, open the ⋯ menu in the header and choose Register as model. It does not wait for the explanations. Experiments themselves are not packaged, only registered models.
2. Install what it needs¶
Create an environment next to the package and install its requirements. The libraries come from PyPI.
cd customer-churn-baseline-package
uv venv
uv pip install -r requirements.txt
cd customer-churn-baseline-package
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cd customer-churn-baseline-package
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
requirements.txt pins the range of ParleML's ml4 library that can read this model: patch
releases install, the next feature release does not. A version that cannot read the model refuses
to load it, so you never get silently wrong predictions.
3. Predict in code¶
import pandas as pd
from parleml_ml4.delivery.bundle import load_pipeline
model = load_pipeline("model/bundle")
customers = pd.read_parquet("new_customers.parquet") # same columns as the training data
labels = model.predict(customers) # "1" / "0" at the model's tuned threshold
risk = model.predict_proba(customers) # one column per class
print(risk.head())
The input needs the columns the model was trained on. Extra columns are ignored. The target
column is not needed. For a regression model, predict returns the estimated value.
Prefer Parquet over CSV: it keeps each column's type, which the model's encoders rely on.
Or score a whole file from the command line¶
python score.py new_customers.parquet
This writes new_customers.scored.parquet next to the input, with a prediction column and one
proba_<class> column per class. Add --out <path> to write it somewhere else.
Or call the running server¶
While ParleML is running, any finished classification or regression experiment can score a row over HTTP:
curl -X POST http://localhost:8000/api/experiments/<experiment-id>/predict \
-H "Content-Type: application/json" \
-d '{"row": {"plan_type": "Basic", "tenure_months": 4, "support_tickets_90d": 3}}'
The answer carries the prediction and its probabilities. Once the experiment's explanations are
computed (Compute explanations on its page), it also carries the top drivers and the rules
the case matched; until then explanations_computed is false and those lists are empty.
Columns you leave out are sent as missing. The experiment ID is in the experiment
page's address. The full API is at http://localhost:8000/docs.
Next¶
- Score a new file inside the app, with a diagnosis when the outcome is known.
- Models and release: stages, the model card and every download format.