Skip to content

Retrain with the training code

Training code on the Predict & export page is the complete Python script behind the model you chose, with every setting and random seed the Studio used. Run it on the same file and you get the same score. Run it on a newer file with the same columns and you get a fresh model, built the same way.

1. Save the script

Open Training code, copy it with the copy button, and save it as train.py. The first lines name the scikit-learn and pandas versions it was written for.

2. Put your data next to it

The script reads the file you trained on, by its original name, for example:

df = pd.read_csv('house_prices.csv')

Put that file in the same folder, or change the name to your newer file. The columns must match.

Excel workbooks with several sheets

The script reads the first sheet. If the Studio used a later sheet, add sheet_name="<the sheet's name>" to the pd.read_excel(...) line.

3. Run it

pip install scikit-learn==<version> pandas==<version> joblib   # add openpyxl for Excel
python train.py

It prints the model's accuracy, or R² when predicting a number, next to what a simple guess scores, measured on the same rows the Studio used. Both numbers match the Metrics tab. It then refits on every row and saves the result as model.joblib.

Not the same file as the Studio's download

The script saves the model on its own, without the extra details the Studio's download carries. Load it with model = joblib.load("model.joblib") and call model.predict(...) on the same columns.

Running it on the instance

The Python environment already has the right libraries. Copy the script and your data to the instance, for example through JupyterLab's file browser, and run it there.