Skip to content

Instantly share code, notes, and snippets.

# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train a decision tree model
dt = create_model('dt')
# train a bagging classifier on dt
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train a decision tree model
dt = create_model('dt')
# tune hyperparameters of decision tree
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train adaboost model
adaboost = create_model('ada')
# AUC plot
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# train logistic regression model
lr = create_model('lr') #lr is the id of the model
# check the model library to see all models
# import classification module
from pycaret.classification import *
# init setup
clf1 = setup(data, target = 'name-of-target')
# return best model
best = compare_models()
# return best model based on Recall
predict_model(xgboost, probability_threshold=0.2)
# Importing dataset
from pycaret.datasets import get_data
credit = get_data('credit')
# Importing module and initializing setup
from pycaret.classification import *
clf1 = setup(data = credit, target = 'default')
# create a model
xgboost = create_model('xgboost')
tuned_lda = tune_model(model='lda', supervised_target='status', estimator='xgboost')
#tune with default n_iter i.e. 10
tuned_dt1 = tune_model('dt')
#tune with n_iter = 50
tuned_dt2 = tune_model('dt', n_iter = 50)
# import regression module
from pycaret.regression import *
# init setup
reg1 = setup(data, target = 'charges', silent=True,
categorical_features=['sex', 'smoker', 'region', 'children'],
numeric_features=['age', 'bmi'])