Skip to content

Instantly share code, notes, and snippets.

@pycaret
Last active September 2, 2022 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pycaret/e21f838a26923856db896df10cc3c7e6 to your computer and use it in GitHub Desktop.
Save pycaret/e21f838a26923856db896df10cc3c7e6 to your computer and use it in GitHub Desktop.
# 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
bagged_dt = ensemble_model(dt, method = 'Bagging')
# train a adaboost classifier on dt with 100 estimators
boosted_dt = ensemble_model(dt, method = 'Boosting', n_estimators = 100)
# train a votingclassifier on all models in library
blender = blend_models()
# train a voting classifier on specific models
dt = create_model('dt')
rf = create_model('rf')
adaboost = create_model('ada')
blender_specific = blend_models(estimator_list = [dt,rf,adaboost], method = 'soft')
# train a voting classifier dynamically
blender_top5 = blend_models(compare_models(n_select = 5))
# train a stacking classifier
stacker = stack_models(estimator_list = [dt,rf], meta_model = adaboost)
# stack multiple models dynamically
top7 = compare_models(n_select = 7)
stacker = stack_models(estimator_list = top7[1:], meta_model = top7[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment