<jupyter_start><jupyter_text>Introduction to PyCaret - An open source low-code ML library This notebook consists 2 parts - Classification part using Titanic DataSet - Regression part using House Price Regression DataSet ![](https://pycaret.org/wp-content/uploads/2020/03/Divi93_43.png)You can reach pycaret website and documentation from https://pycaret.orgPyCaret is an open source, low-code machine learning library in Python that allows you to go from preparing your data to deploying your model within seconds in your choice of notebook environment.PyCaret being a low-code library makes you more productive. With less time spent coding, you and your team can now focus on business problems.PyCaret is simple and easy to use machine learning library that will help you to perform end-to-end ML experiments with less lines of code. PyCaret is a business ready solution. It allows you to do prototyping quickly and efficiently from your choice of notebook environment.  let's install pycaret !<jupyter_code>!pip install pycaret<jupyter_output>Collecting pycaret
  Downloading pycaret-1.0.0-py3-none-any.whl (188 kB)
[K     |████████████████████████████████| 188 kB 4.9 MB/s 
[?25hCollecting shap==0.32.1
  Downloading shap-0.32.1.tar.gz (259 kB)
[K     |████████████████████████████████| 259 kB 58.1 MB/s 
[?25hRequirement already satisfied: pandas in /opt/conda/lib/python3.6/site-packages (from pycaret) (0.25.3)
Requirement already satisfied: nltk in /opt/conda/lib/python3.6/site-packages (from pycaret) (3.2.4)
Requirement already satisfied: ipywidgets in /opt/conda/lib/python3.6/site-packages (from pycaret) (7.5.1)
Requirement already satisfied: pyLDAvis in /opt/conda/lib/python3.6/site-packages (from pycaret) (2.1.2)
Requirement already satisfied: joblib in /opt/conda/lib/python3.6/site-packages (from pycaret) (0.14.1)
Requirement already satisfied: umap-learn in /opt/conda/lib/python3.6/site-packages (from pycaret) (0.3.10)
Requirement already satisfied: spacy in /opt/conda/lib/python3.6/site-packages (from py[...]<jupyter_text>Part 1 Classification![](https://www.sciencealert.com/images/articles/processed/titanic-1_1024.jpg)  We start by loading the libraries<jupyter_code>import numpy as np 
import pandas as pd<jupyter_output><empty_output><jupyter_text>Read our files<jupyter_code>train = pd.read_csv('../input/titanic/train.csv')
test  = pd.read_csv('../input/titanic/test.csv')
sub   = pd.read_csv('../input/titanic/gender_submission.csv')<jupyter_output><empty_output><jupyter_text>Import whole classification<jupyter_code>from pycaret.classification import *<jupyter_output><empty_output><jupyter_text>let's see what we're dealing with<jupyter_code>train.head()
train.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
PassengerId    891 non-null int64
Survived       891 non-null int64
Pclass         891 non-null int64
Name           891 non-null object
Sex            891 non-null object
Age            714 non-null float64
SibSp          891 non-null int64
Parch          891 non-null int64
Ticket         891 non-null object
Fare           891 non-null float64
Cabin          204 non-null object
Embarked       889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.7+ KB<jupyter_text>Set up our dataset (preprocessing)<jupyter_code>clf1 = setup(data = train, 
             target = 'Survived',
             numeric_imputation = 'mean',
             categorical_features = ['Sex','Embarked'], 
             ignore_features = ['Name','Ticket','Cabin'],
             silent = True)

#quite intuitive isn't it ?<jupyter_output>Setup Succesfully Completed!<jupyter_text>Compare the models<jupyter_code>compare_models()<jupyter_output><empty_output><jupyter_text>let's create a Light GBM Model<jupyter_code>lgbm  = create_model('lightgbm')<jupyter_output><empty_output><jupyter_text>Let's tune it!<jupyter_code>tuned_lightgbm = tune_model('lightgbm')<jupyter_output><empty_output><jupyter_text>Learning Curve<jupyter_code>plot_model(estimator = tuned_lightgbm, plot = 'learning')<jupyter_output><empty_output><jupyter_text>AUC Curve<jupyter_code>plot_model(estimator = tuned_lightgbm, plot = 'auc')<jupyter_output><empty_output><jupyter_text>Confusion Matrix<jupyter_code>plot_model(estimator = tuned_lightgbm, plot = 'confusion_matrix')<jupyter_output><empty_output><jupyter_text>Feature Importance<jupyter_code>plot_model(estimator = tuned_lightgbm, plot = 'feature')<jupyter_output><empty_output><jupyter_text>whole thing!<jupyter_code>evaluate_model(tuned_lightgbm)<jupyter_output><empty_output><jupyter_text>Interpretation<jupyter_code>interpret_model(tuned_lightgbm)<jupyter_output><empty_output><jupyter_text>Predictions<jupyter_code>predict_model(tuned_lightgbm, data=test)
predictions = predict_model(tuned_lightgbm, data=test)
predictions.head()
sub['Survived'] = round(predictions['Score']).astype(int)
sub.to_csv('submission.csv',index=False)
sub.head()<jupyter_output><empty_output><jupyter_text>Extra: Blending made easy!<jupyter_code>logr  = create_model('lr');      
xgb   = create_model('xgboost');            

#blending 3 models
blend = blend_models(estimator_list=[tuned_lightgbm,logr,xgb])<jupyter_output><empty_output><jupyter_text>Part2 - Regression ![](https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSYeyNpaoAW-3rFX9-ORmiJ-uLAAswYBRhszs2QzllV7MCfFPvk&usqp=CAU)  Import Whole Regression<jupyter_code>from pycaret.regression import *<jupyter_output><empty_output><jupyter_text>let's see the data<jupyter_code>train = pd.read_csv('../input/house-prices-advanced-regression-techniques/train.csv')
test  = pd.read_csv('../input/house-prices-advanced-regression-techniques/test.csv')
sample= pd.read_csv('../input/house-prices-advanced-regression-techniques/sample_submission.csv')
train.head()
train.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 1460 entries, 0 to 1459
Data columns (total 81 columns):
Id               1460 non-null int64
MSSubClass       1460 non-null int64
MSZoning         1460 non-null object
LotFrontage      1201 non-null float64
LotArea          1460 non-null int64
Street           1460 non-null object
Alley            91 non-null object
LotShape         1460 non-null object
LandContour      1460 non-null object
Utilities        1460 non-null object
LotConfig        1460 non-null object
LandSlope        1460 non-null object
Neighborhood     1460 non-null object
Condition1       1460 non-null object
Condition2       1460 non-null object
BldgType         1460 non-null object
HouseStyle       1460 non-null object
OverallQual      1460 non-null int64
OverallCond      1460 non-null int64
YearBuilt        1460 non-null int64
YearRemodAdd     1460 non-null int64
RoofStyle        1460 non-null object
RoofMatl         1460 non-null object
Exterior1st      1460 non-n[...]<jupyter_text>Set up our dataset (preprocessing)<jupyter_code>reg = setup(data = train, 
             target = 'SalePrice',
             numeric_imputation = 'mean',
             categorical_features = ['MSZoning','Exterior1st','Exterior2nd','KitchenQual','Functional','SaleType',
                                     'Street','LotShape','LandContour','LotConfig','LandSlope','Neighborhood',   
                                     'Condition1','Condition2','BldgType','HouseStyle','RoofStyle','RoofMatl',    
                                     'MasVnrType','ExterQual','ExterCond','Foundation','BsmtQual','BsmtCond',   
                                     'BsmtExposure','BsmtFinType1','BsmtFinType2','Heating','HeatingQC','CentralAir',   
                                     'Electrical','GarageType','GarageFinish','GarageQual','GarageCond','PavedDrive',
                                     'SaleCondition']  , 
             ignore_features = ['Alley','PoolQC','MiscFeature','Fence','FireplaceQu','Utilities'],
             normalize = True,
             silent = True)<jupyter_output>Setup Succesfully Completed!<jupyter_text>let's compare different regression models!<jupyter_code>compare_models()<jupyter_output><empty_output><jupyter_text>let's do CatBoost<jupyter_code>cb = create_model('catboost')<jupyter_output><empty_output><jupyter_text>gotta tune it<jupyter_code>tuned_cb = tune_model('catboost')<jupyter_output><empty_output><jupyter_text>SHAP Values (impact on model output)<jupyter_code>interpret_model(tuned_cb)
predictions = predict_model(tuned_cb, data = test)
sample['SalePrice'] = predictions['Label']
sample.to_csv('submission_house_price.csv',index=False)
sample.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11452416830879796, 'fraction_numerical': 0.0340790541323751, 'mean_word_length': 4.502551020408164, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 94, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '4839', 'license': 'MIT', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2868, 'n_words': 568, 'path': 'dataset_0/notebook/pycaret-introduction-classification-regression.ipynb', 'repo_name': 'xuyeliu/JNotebook2csv', 'size': '8627'}