Skip to content

Use your model in Google Colab

Google Colab runs Python notebooks in your browser, so you can use a downloaded model with nothing installed on your computer.

Your data leaves your AWS account

Files you upload to Colab are processed by Google. If your data must stay in your account, use JupyterLab on the instance instead.

1. Start a notebook

Open colab.research.google.com and choose New notebook.

2. Install the matching scikit-learn

Colab comes with its own scikit-learn, which may be a different version. In the first cell, install the version shown at the top of the Studio's Load in Python panel:

!pip install -q scikit-learn==<version>

If Colab asks you to restart the session, do so, then continue below.

3. Upload the model and your data

from google.colab import files
uploaded = files.upload()   # choose the .joblib file and your CSV

4. Predict

import joblib
import pandas as pd

bundle = joblib.load("your_model.joblib")
model = bundle["pipeline"]
FEATURES = bundle["feature_columns"]

new = pd.read_csv("new_data.csv")
new[f"{bundle['target']}_prediction"] = model.predict(new[FEATURES])
new.head()

5. Download the result

new.to_csv("scored.csv", index=False)
files.download("scored.csv")

The predictions match the ones the Studio gave for the same rows, as long as the scikit-learn version matches.