Predict Model


Once a model is successfully deployed either on cloud using deploy_model or locally using save_model, it can be used to predict on unseen data using predict_model function. This functions takes a trained model object and the dataset to predict. It will automatically apply the entire transformation pipeline created during the experiment. For classification, predicted labels are created based on 50% probability, but if you choose to use a different threshold that you may have obtained using optimize_threshold, you can pass the probability_threshold parameter within predict_model. This function can also be used to generate predictions on hold-out / test set.

 

Predictions on hold-out / test set

 

 

Code
from pycaret.datasets import get_data
diabetes = get_data('diabetes')

# Importing module and initializing setup
from pycaret.classification import *
clf1 = setup(data = diabetes, target = 'Class variable')

# create a model
xgboost = create_model('xgboost')

# predict on hold-out
pred_holdout = predict_model(xgboost)

 

Output

Predictions on unseen data

 

Code
# Importing dataset
from pycaret.datasets import get_data
boston = get_data('boston')

# Importing module and initializing setup
from pycaret.regression import *
reg1 = setup(data = boston, target = 'medv')

# create a model
lr = create_model('lr')

# finalize a model
lr_final = finalize_model(lr)

# importing unseen data 
import pandas as pd
data_unseen = pd.read_csv('data_unseen.csv') 

# generate predictions on unseen data
predictions = predict_model(lr_final, data = data_unseen)

 

Output

Predictions on unseen data directly from cloud

 

Code
# Importing dataset
from pycaret.datasets import get_data
boston = get_data('boston')

# Importing module and initializing setup
from pycaret.regression import *
reg1 = setup(data = boston, target = 'medv')

# create a model
lr = create_model('lr')

# finalize a model
lr_final = finalize_model(lr)

# deploy a model
deploy_model(lr_final, model_name = 'lr_aws', platform = 'aws',
             authentication = {'bucket' : 'pycaret-test'})

# importing unseen data 
import pandas as pd
data_unseen = pd.read_csv('data_unseen.csv') 

# generate predictions directly from AWS
predictions = predict_model('lr_aws', data = data_unseen, platform = 'aws', authentication = {'bucket' : 'pycaret-test'})

 

Output

Try this next