"""
  ## <h1 style=' border:0; color:#FFA500 '><center>✨[TPS Oct - 21] -> 22 models comparision📈📊</center></h1>
"""
"""
# <h1 style=' border:0; color:#FFA500 '><left>Installing Lazy Predict 😴</left></h1> 
"""
from IPython.display import clear_output
!pip3 install -U lazypredict

clear_output()
"""
# <h1 style=' border:0; color:#FFA500 '><left>Import Libraries 📚</left></h1> 
"""
!pip3 install -U pandas==1.2.3 #Upgrading pandas
import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt 
import lazypredict
from lazypredict import Supervised
from lazypredict.Supervised import LazyClassifier


plt.style.use('fivethirtyeight')
plt.rcParams["figure.figsize"] = (20,5)
clear_output()
"""
# <h1 style=' border:0; color:#FFA500 '><left>Loading Data 🚚</left></h1> 
"""
# Load the training data
train = pd.read_csv("../input/tabular-playground-series-oct-2021/train.csv", index_col=0)
test = pd.read_csv("../input/tabular-playground-series-oct-2021/test.csv", index_col=0)

# Preview the data
train.head()
X = train.drop(['target'], axis=1)
y = train['target']
#Spliting into training and validation set
from sklearn.model_selection import train_test_split
X_train, X_valid, y_train, y_valid = train_test_split(X,y,test_size = 0.20,random_state = 1)
del X,y,train,test
"""
# <h1 style=' border:0; color:#FFA500 '><left>Model Selection 📚</left></h1> 
"""
num_models = 22 #Total number of model is 29 for classification model but removed some of them due to error :(
reg_idx = [i for i in range(num_models)]
noregs_idx = [4,9,9,9,13,20,20] # Removing 7 models from 29 models. Some of these models are time consuming whereas other require lot of ram and some getting error
regs_name =[]
regs = []
for i in range(29):
    regs_name.append(lazypredict.Supervised.CLASSIFIERS[i][0])
    regs.append(lazypredict.Supervised.CLASSIFIERS[i][1])

for i in noregs_idx:
    del regs_name[i]
    del regs[i]
print("ALL 22 AVAILABLE CLASSIFICATION MODELS:")
for i in range(NUM_):
    print(i+1 , regs_name[i])
"""
# <h1 style=' border:0; color:#FFA500 '><left>Training on 22 different models 🏋️</left></h1> 
"""
results = pd.DataFrame()
for i in range(22):
    print(i,regs_name[i])
    reg = LazyClassifier(verbose=0, 
                    ignore_warnings=False,
                    custom_metric=None,
                    classifiers = [regs[i]])
    models, predictions = reg.fit(X_train, X_valid, y_train, y_valid)
    models.index = [regs_name[i]]
    results = results.append(models)
    print(results)
clear_output()
"""
# <h1 style=' border:0; color:#FFA500 '><left>✔️ Results</left></h1> 
"""
results = results.sort_values(by = "ROC AUC",ascending=False)
print(results)
"""
# <h1 style=' border:0; color:#FFA500 '><left>🥇 Top 5 Performing Models</left></h1> 
"""
results.head()
"""
# <h1 style=' border:0; color:#FFA500 '><left> Comparison Plots 📈 </left></h1> 
"""
plt.plot(reg_idx , results["ROC AUC"],label = "ROC AUC" ,marker='o')
plt.xlabel("Model ID")
plt.ylabel("ROC AUC")
plt.title("MAE Comparison of 22 Different Models")
plt.legend()
plt.show()
plt.plot(reg_idx , results["Time Taken"],label = "Time Taken" ,marker='*' , color = 'r')
plt.xlabel("Model ID")
plt.ylabel("Time Taken")
plt.title("TIME TAKEN for 22 Different Models")
plt.legend()
plt.show()
"""
# <h1 style=' border:0; color:#FFA500 '><center> If you find this notebook usefull support me with giving ⬆️!</left></h1> 
"""
"""
Inspired from https://www.kaggle.com/odins0n/30dml-comparison-of-36-different-models
"""