#!/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[4]: from pycaret.datasets import get_data data = get_data('juice') # # 2. Setting up Environment # In[5]: get_ipython().run_line_magic('pinfo2', 'setup') # In[6]: from pycaret.classification import * clf1 = setup(data, target = 'Purchase', session_id=786) # # 3. Compare Models # In[7]: compare_models() # # 4. Create Model # In[8]: lr = create_model('lr') # In[9]: dt = create_model('dt') # # 5. Tune Model # In[10]: tuned_dt = tune_model('dt') # In[12]: tuned_nb = tune_model('nb', optimize = 'AUC') # In[13]: print(tuned_nb) # # 6. Ensemble Model # In[14]: bagged_dt = ensemble_model(dt) # In[15]: boosted_dt = ensemble_model(dt, method = 'Boosting') # # 7. Blend Models # In[16]: lr = create_model('lr', verbose=False) lda = create_model('lda', verbose=False) gbc = create_model('gbc', verbose=False) # In[17]: blender = blend_models(estimator_list=[lr,lda,gbc], method = 'soft') # In[18]: blender.estimators_ # # 8. Analyze Model # In[19]: plot_model(blender) # In[20]: plot_model(blender, plot = 'confusion_matrix') # In[21]: plot_model(blender, plot = 'threshold') # In[22]: plot_model(blender, plot = 'pr') # In[23]: plot_model(tuned_dt, plot = 'vc') # In[24]: plot_model(dt, plot = 'boundary') # In[25]: plot_model(tuned_nb, plot = 'boundary') # In[26]: plot_model(blender, plot = 'boundary') # In[27]: evaluate_model(tuned_nb) # # 9. Interpret Model # In[28]: xgboost = create_model('xgboost') # In[29]: interpret_model(xgboost) # In[ ]: interpret_model(xgboost, plot = 'correlation') # In[30]: interpret_model(xgboost, plot = 'reason', observation=1) # In[31]: 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