#!/usr/bin/env python # coding: utf-8 # # Installation # In[ ]: # run this cell to install pycaret in Google Colab # !pip install pycaret # In[ ]: # If you are using Jupyter notebook, you can pip install pycaret using jupyter notebook or command line # pip install pycaret # In[3]: from pycaret.utils import version version() # # 1. Importing Dataset # In[5]: from pycaret.datasets import get_data data = get_data('juice') # # 2. Setting up Environment # In[10]: from pycaret.classification import * clf1 = setup(data, target = 'Purchase', session_id=786) # # 3. Compare Models # In[11]: compare_models() # # 4. Create Model # In[12]: lr = create_model('lr') # In[13]: dt = create_model('dt') # # 5. Tune Model # In[14]: tuned_dt = tune_model('dt') # In[19]: print(tuned_dt) # In[18]: tuned_nb = tune_model('nb', optimize = 'AUC') # In[20]: print(tuned_nb) # # 6. Ensemble Model # In[21]: bagged_dt = ensemble_model(dt) # In[22]: boosted_dt = ensemble_model(dt, method = 'Boosting') # # 7. Blend Models # In[23]: lr = create_model('lr', verbose=False) lda = create_model('lda', verbose=False) gbc = create_model('gbc', verbose=False) # In[25]: blender = blend_models(estimator_list=[lr,lda,gbc], method = 'soft') # In[26]: blender.estimators_ # # 8. Analyze Model # In[27]: plot_model(blender) # In[41]: plot_model(blender, plot = 'confusion_matrix') # In[42]: plot_model(blender, plot = 'threshold') # In[43]: plot_model(blender, plot = 'pr') # In[44]: plot_model(tuned_dt, plot = 'vc') # In[29]: plot_model(dt, plot = 'boundary') # In[31]: plot_model(tuned_nb, plot = 'boundary') # In[30]: plot_model(blender, plot = 'boundary') # In[33]: evaluate_model(tuned_nb) # # 9. Interpret Model # In[38]: xgboost = create_model('xgboost') # In[39]: interpret_model(xgboost) # In[46]: interpret_model(xgboost, plot = 'correlation') # In[40]: interpret_model(xgboost, plot = 'reason', observation=1) # In[45]: interpret_model(xgboost, plot = 'reason') # # Learning Resources: # # - PyCaret Classification Module : https://www.pycaret.org/classification # - Binary Classification Tutorial (Level Beginner) : https://pycaret.org/clf101/ # - Binary Classification Tutorial (Level Intermediate) : https://pycaret.org/clf102/ # - Kaggle Titanic Predictions (Video Tutorial) : https://www.youtube.com/watch?v=nqMM6rngNCA