Skip to content

Score a file in Python

Add predictions to a spreadsheet with the model you downloaded, on any computer with Python, the instance included.

You need: the .joblib file from Predict & export (unzip it first if you used Download every model), a CSV or Excel file with the same columns the model learned from, and Python 3.11 or newer.

1. Install the libraries

The Load in Python panel in the Studio starts with the exact versions the model was trained with. Use the same scikit-learn version for identical results:

pip install scikit-learn==<version> pandas joblib

Add openpyxl if you will read Excel files.

On the instance

The Python environment already has all of these. Its scikit-learn normally matches the version the Studio trained with; check it against the first lines of Load in Python if you have upgraded anything.

2. Load the model and predict

import joblib
import pandas as pd
import sklearn

bundle = joblib.load("your_model.joblib")
if sklearn.__version__ != bundle["sklearn_version"]:
    print(f"Note: trained with scikit-learn {bundle['sklearn_version']}, "
          f"you have {sklearn.__version__}. Predictions may differ slightly.")

model = bundle["pipeline"]
FEATURES = bundle["feature_columns"]

new = pd.read_csv("new_data.csv")          # or pd.read_excel("new_data.xlsx")
new[f"{bundle['target']}_prediction"] = model.predict(new[FEATURES])
new.to_csv("scored.csv", index=False)

Selecting FEATURES makes column order irrelevant, ignores extra columns, and fails loudly by name if one is missing.

3. Probabilities, when sorting into groups

For a model that sorts rows into groups, predict_proba gives how likely each group is, in the order of model.classes_:

proba = model.predict_proba(new[FEATURES])
for i, group in enumerate(model.classes_):
    new[f"probability_{group}"] = proba[:, i]

The same code, ready to copy

The Load in Python panel in the Studio shows this code for your model, with an example row from your own data.