#!/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[1]: from pycaret.utils import version version() # # 1. Importing Dataset # In[2]: from pycaret.datasets import get_data data = get_data('diamond') # # 2. Iteration 1: (without preprocessing) # In[3]: from pycaret.regression import * reg1 = setup(data, target = 'Price', session_id=786) # ## 2.1. Compare Models # In[4]: compare_models(blacklist = ['tr', 'catboost']) # ## 2.2 Create Model # In[5]: lr = create_model('lr') # # 2.3 Plot Model # In[6]: plot_model(lr) # In[7]: plot_model(lr, plot = 'error') # In[8]: plot_model(lr, plot = 'feature') # # 3. Iteration 2: (with preprocessing) # In[9]: # profile = True data = get_data('diamond', profile = True) # In[10]: reg2 = setup(data, target = 'Price', session_id=786, transform_target = True, bin_numeric_features=['Carat Weight'], remove_multicollinearity=True, feature_interaction=True) # ## 3.1 Create Model # In[11]: lr2 = create_model('lr') # ## 3.2. Plot Model # In[34]: plot_model(lr2) # In[21]: plot_model(lr2, plot = 'error') # In[22]: plot_model(lr2, plot = 'feature') # # 4. Finalize Model # In[23]: holdout_pred = predict_model(lr2) # In[24]: final_lr = finalize_model(lr2) # In[25]: print(final_lr) # # 5. Save Model # In[26]: save_model(final_lr, 'lr_smith_demo') # In[27]: lr_loaded = load_model('lr_smith_demo') # In[28]: print(lr_loaded) # In[29]: predictions = predict_model(lr_loaded, data=data) predictions.head() # # 6. Deploy Model # In[31]: deploy_model(final_lr, model_name = 'lr_smith_demo', platform = 'aws', authentication = {'bucket' : 'pycaret-test'}) # In[33]: predictions2 = predict_model('lr_smith_demo', data=data) predictions2.head() # # Learning Resources: # # - PyCaret Regression Module : https://www.pycaret.org/regression # - Regression Tutorial (Level Beginner) : https://pycaret.org/reg101/ # - Regression Tutorial (Level Intermediate) : https://pycaret.org/reg102/