{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Install Packages","metadata":{}},{"cell_type":"code","source":"pip install pycaret-ts-alpha","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-07-11T05:59:36.523588Z","iopub.execute_input":"2022-07-11T05:59:36.526004Z","iopub.status.idle":"2022-07-11T05:59:48.726677Z","shell.execute_reply.started":"2022-07-11T05:59:36.525938Z","shell.execute_reply":"2022-07-11T05:59:48.725251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pycaret.classification import *\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sbn\nfrom sklearn.preprocessing import PowerTransformer, LabelEncoder\nimport warnings\nfrom sklearn.impute import KNNImputer\nfrom collections import Counter\nfrom tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.728962Z","iopub.execute_input":"2022-07-11T05:59:48.729384Z","iopub.status.idle":"2022-07-11T05:59:48.738371Z","shell.execute_reply.started":"2022-07-11T05:59:48.729344Z","shell.execute_reply":"2022-07-11T05:59:48.737342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Files","metadata":{}},{"cell_type":"code","source":"#Load file\ntrain = pd.read_csv(\"../input/titanic/train.csv\")\ntest = pd.read_csv(\"../input/titanic/test.csv\")\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.739847Z","iopub.execute_input":"2022-07-11T05:59:48.740174Z","iopub.status.idle":"2022-07-11T05:59:48.789811Z","shell.execute_reply.started":"2022-07-11T05:59:48.740145Z","shell.execute_reply":"2022-07-11T05:59:48.788791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Shape\ntrain.shape, test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.792371Z","iopub.execute_input":"2022-07-11T05:59:48.793110Z","iopub.status.idle":"2022-07-11T05:59:48.799583Z","shell.execute_reply.started":"2022-07-11T05:59:48.793066Z","shell.execute_reply":"2022-07-11T05:59:48.798529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Structure of data\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.800929Z","iopub.execute_input":"2022-07-11T05:59:48.801278Z","iopub.status.idle":"2022-07-11T05:59:48.823249Z","shell.execute_reply.started":"2022-07-11T05:59:48.801247Z","shell.execute_reply":"2022-07-11T05:59:48.822269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA Analysis","metadata":{}},{"cell_type":"code","source":"#Statistics\ntrain.describe().style.background_gradient()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.824558Z","iopub.execute_input":"2022-07-11T05:59:48.824907Z","iopub.status.idle":"2022-07-11T05:59:48.871897Z","shell.execute_reply.started":"2022-07-11T05:59:48.824874Z","shell.execute_reply":"2022-07-11T05:59:48.870955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking unique age values in train set\ntrain.Cabin.unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.873108Z","iopub.execute_input":"2022-07-11T05:59:48.873455Z","iopub.status.idle":"2022-07-11T05:59:48.880256Z","shell.execute_reply.started":"2022-07-11T05:59:48.873425Z","shell.execute_reply":"2022-07-11T05:59:48.879552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking unique age values in train set\ntest.Cabin.unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.881179Z","iopub.execute_input":"2022-07-11T05:59:48.882162Z","iopub.status.idle":"2022-07-11T05:59:48.894766Z","shell.execute_reply.started":"2022-07-11T05:59:48.882083Z","shell.execute_reply":"2022-07-11T05:59:48.894102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Distribution of Age\nplt.figure(figsize=(10,3))\nsbn.histplot(data=train, x='Age', kde=True, bins=30)\nsbn.histplot(data=test, x='Age', kde=True, color='green', bins=30)\nplt.title(\"Distribution of Age\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:48.895824Z","iopub.execute_input":"2022-07-11T05:59:48.896275Z","iopub.status.idle":"2022-07-11T05:59:49.305066Z","shell.execute_reply.started":"2022-07-11T05:59:48.896236Z","shell.execute_reply":"2022-07-11T05:59:49.303904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Distribution of Fare\nplt.figure(figsize=(10,3))\nsbn.histplot(data=train, x='Fare', kde=True, bins=30)\nsbn.histplot(data=test, x='Fare', kde=True, color='green', bins=30)\nplt.title(\"Distribution of Fare\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:49.309491Z","iopub.execute_input":"2022-07-11T05:59:49.309930Z","iopub.status.idle":"2022-07-11T05:59:49.674577Z","shell.execute_reply.started":"2022-07-11T05:59:49.309896Z","shell.execute_reply":"2022-07-11T05:59:49.673627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Analysis of people survived based on Age\nplt.figure(figsize=(10,3))\nsbn.histplot(data=train, x='Age', kde=True, hue='Survived')\nplt.title(\"Analysis of people survived based on Age\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:49.675928Z","iopub.execute_input":"2022-07-11T05:59:49.676324Z","iopub.status.idle":"2022-07-11T05:59:50.062016Z","shell.execute_reply.started":"2022-07-11T05:59:49.676290Z","shell.execute_reply":"2022-07-11T05:59:50.061017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of them over age 10 were dead.","metadata":{}},{"cell_type":"code","source":"#Analysis of people survived based on Fare\nplt.figure(figsize=(10,3))\nsbn.histplot(data=train, x='Fare', kde=True, hue='Survived', bins=30)\nplt.title(\"Analysis of people survived based on Fare\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:50.063167Z","iopub.execute_input":"2022-07-11T05:59:50.063486Z","iopub.status.idle":"2022-07-11T05:59:50.478607Z","shell.execute_reply.started":"2022-07-11T05:59:50.063459Z","shell.execute_reply":"2022-07-11T05:59:50.477241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of those who gave less than 50 bugs were dead.","metadata":{}},{"cell_type":"markdown","source":"We need to normalize the Fair column","metadata":{}},{"cell_type":"code","source":"#Distribution of Age over PClass\nplt.figure(figsize=(10,3))\nsbn.boxplot(data=train, x='Pclass', y='Age')\nplt.title(\"Distribution of Age over PClass\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:50.480553Z","iopub.execute_input":"2022-07-11T05:59:50.480987Z","iopub.status.idle":"2022-07-11T05:59:50.720248Z","shell.execute_reply.started":"2022-07-11T05:59:50.480947Z","shell.execute_reply":"2022-07-11T05:59:50.719561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Distribution of Age over Sex\nplt.figure(figsize=(10,3))\nsbn.boxplot(data=train, x='Sex', y='Age')\nplt.title(\"Distribution of Age over Sex\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:50.721272Z","iopub.execute_input":"2022-07-11T05:59:50.721757Z","iopub.status.idle":"2022-07-11T05:59:50.927167Z","shell.execute_reply.started":"2022-07-11T05:59:50.721723Z","shell.execute_reply":"2022-07-11T05:59:50.926396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Survived in Counts\nprint(train.Survived.value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:50.928245Z","iopub.execute_input":"2022-07-11T05:59:50.928744Z","iopub.status.idle":"2022-07-11T05:59:50.935307Z","shell.execute_reply.started":"2022-07-11T05:59:50.928709Z","shell.execute_reply":"2022-07-11T05:59:50.934367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Survived in %\nplt.figure(figsize=(13,4))\nplt.pie(x=train.Survived.value_counts(), labels=train.Survived.unique(), autopct='%.2f%%')\nplt.title(\"Survived in %\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:50.936739Z","iopub.execute_input":"2022-07-11T05:59:50.937752Z","iopub.status.idle":"2022-07-11T05:59:51.056872Z","shell.execute_reply.started":"2022-07-11T05:59:50.937707Z","shell.execute_reply":"2022-07-11T05:59:51.055774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Analysis Survival based on PClass\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='Pclass', hue='Survived')\nplt.title(\"Analysis: Survival based on PClass\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:51.058568Z","iopub.execute_input":"2022-07-11T05:59:51.059435Z","iopub.status.idle":"2022-07-11T05:59:51.246133Z","shell.execute_reply.started":"2022-07-11T05:59:51.059388Z","shell.execute_reply":"2022-07-11T05:59:51.244973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In Pclass 3 most of them were dead","metadata":{}},{"cell_type":"code","source":"#Analysis Survival based on Sex\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='Sex', hue='Survived')\nplt.title(\"Analysis: Survival based on Sex\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:51.247654Z","iopub.execute_input":"2022-07-11T05:59:51.248898Z","iopub.status.idle":"2022-07-11T05:59:51.412671Z","shell.execute_reply.started":"2022-07-11T05:59:51.248848Z","shell.execute_reply":"2022-07-11T05:59:51.411637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"More males are lost than females.","metadata":{}},{"cell_type":"code","source":"#Analysis Survival based on Parch\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='Parch', hue='Survived')\nplt.title(\"Analysis: Survival based on Parch\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:51.414075Z","iopub.execute_input":"2022-07-11T05:59:51.414722Z","iopub.status.idle":"2022-07-11T05:59:51.629952Z","shell.execute_reply.started":"2022-07-11T05:59:51.414676Z","shell.execute_reply":"2022-07-11T05:59:51.628810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of them were dead in all Parches","metadata":{}},{"cell_type":"code","source":"#Analysis Survival based on Embarked\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='Embarked', hue='Survived')\nplt.title(\"Analysis: Survival based on Embarked\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:51.631456Z","iopub.execute_input":"2022-07-11T05:59:51.631891Z","iopub.status.idle":"2022-07-11T05:59:51.809106Z","shell.execute_reply.started":"2022-07-11T05:59:51.631848Z","shell.execute_reply":"2022-07-11T05:59:51.807914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In Embarked S, Q most of them were dead","metadata":{}},{"cell_type":"code","source":"#Analysis Survival based on Cabin\ncombine_data = [train, test]\nfor data in combine_data:\n    Cabin=[]\n    for val in data['Cabin'].values:\n        if str(val)=='nan':\n            Cabin.append(np.nan)\n        else:\n            Cabin.append(val[0])\n    data['Cabin']=Cabin\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='Cabin', hue='Survived')\nplt.title(\"Analysis: Survival based on Cabin\")\nplt.show()  ","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:51.810728Z","iopub.execute_input":"2022-07-11T05:59:51.811287Z","iopub.status.idle":"2022-07-11T05:59:52.061495Z","shell.execute_reply.started":"2022-07-11T05:59:51.811241Z","shell.execute_reply":"2022-07-11T05:59:52.060418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Analysis Survival based on SibSp\nplt.figure(figsize=(10,3))\nsbn.countplot(data=train, x='SibSp', hue='Survived')\nplt.title(\"Analysis: Survival based on SibSp\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:52.065053Z","iopub.execute_input":"2022-07-11T05:59:52.065889Z","iopub.status.idle":"2022-07-11T05:59:52.644836Z","shell.execute_reply.started":"2022-07-11T05:59:52.065848Z","shell.execute_reply":"2022-07-11T05:59:52.642620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of them were dead in all SibSp","metadata":{}},{"cell_type":"code","source":"#Checking Outliers \nplt.figure(figsize=(10,3))\nsbn.boxplot(data=train, x='Fare')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:52.646268Z","iopub.execute_input":"2022-07-11T05:59:52.646682Z","iopub.status.idle":"2022-07-11T05:59:52.833392Z","shell.execute_reply.started":"2022-07-11T05:59:52.646649Z","shell.execute_reply":"2022-07-11T05:59:52.832071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,3))\nsbn.boxplot(data=train, x='Age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:52.834581Z","iopub.execute_input":"2022-07-11T05:59:52.834900Z","iopub.status.idle":"2022-07-11T05:59:53.027012Z","shell.execute_reply.started":"2022-07-11T05:59:52.834872Z","shell.execute_reply":"2022-07-11T05:59:53.026073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Relationship between Age and Fare\nplt.figure(figsize=(10,3))\nsbn.lmplot(data=train, x='Age', y='Fare', hue='Survived')\nplt.title(\"Relationship between Age and Fare\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:53.028240Z","iopub.execute_input":"2022-07-11T05:59:53.028650Z","iopub.status.idle":"2022-07-11T05:59:53.759046Z","shell.execute_reply.started":"2022-07-11T05:59:53.028616Z","shell.execute_reply":"2022-07-11T05:59:53.758105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking Missing Values in train data\ntrain.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:53.760465Z","iopub.execute_input":"2022-07-11T05:59:53.761253Z","iopub.status.idle":"2022-07-11T05:59:53.772429Z","shell.execute_reply.started":"2022-07-11T05:59:53.761187Z","shell.execute_reply":"2022-07-11T05:59:53.771101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking Missing Values in test data\ntest.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:53.773693Z","iopub.execute_input":"2022-07-11T05:59:53.774365Z","iopub.status.idle":"2022-07-11T05:59:53.790006Z","shell.execute_reply.started":"2022-07-11T05:59:53.774320Z","shell.execute_reply":"2022-07-11T05:59:53.788989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking Correlation Analysis\nplt.figure(figsize=(10,3))\nsbn.heatmap(train.corr(), annot=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:53.795597Z","iopub.execute_input":"2022-07-11T05:59:53.795959Z","iopub.status.idle":"2022-07-11T05:59:54.330437Z","shell.execute_reply.started":"2022-07-11T05:59:53.795929Z","shell.execute_reply":"2022-07-11T05:59:54.329739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking inconsistency in Categorical data\ndata_combine=[train, test]\nfor data in data_combine:\n    data['Pclass']=data['Pclass'].map({1:'Upper', 2:'Middle', 3:'Lower'})\ncolumns=['Sex', 'Embarked', 'Cabin', 'Pclass']\nvalues = ['train data', 'test data']\nfor value, data in zip(values, data_combine):\n    print('__________________', value, '__________________')\n    for col in columns:\n        print(col, \" : \", data[col].unique())","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.331512Z","iopub.execute_input":"2022-07-11T05:59:54.332358Z","iopub.status.idle":"2022-07-11T05:59:54.344171Z","shell.execute_reply.started":"2022-07-11T05:59:54.332326Z","shell.execute_reply":"2022-07-11T05:59:54.343252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preparation","metadata":{}},{"cell_type":"code","source":"#Drop unwanted columns\ncolumns=['PassengerId', 'Name', 'Ticket']\ntest_data=test.copy(deep=True)\ndata_combine=[train, test]\nfor data in data_combine:\n    data.drop(columns, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.345440Z","iopub.execute_input":"2022-07-11T05:59:54.345761Z","iopub.status.idle":"2022-07-11T05:59:54.357142Z","shell.execute_reply.started":"2022-07-11T05:59:54.345732Z","shell.execute_reply":"2022-07-11T05:59:54.356152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Binning Age and Fare Columns\nbins=[-1, 10, 20, 30, 40, 50, 60, 70, 81]\nlabels=[0, 1, 2, 3, 4, 5, 6, 7]\ntrain['Age']=pd.cut(train['Age'], bins=bins, labels=labels)\ntest['Age']=pd.cut(test['Age'], bins=bins, labels=labels)\nbins=[-1, 50, 100, 150, 200, 250, 300, 350, 400,450,500,550]\nlabels=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10]\ntrain['Fare']=pd.cut(train['Fare'], bins=bins, labels=labels)\ntest['Fare']=pd.cut(test['Fare'], bins=bins, labels=labels)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.358377Z","iopub.execute_input":"2022-07-11T05:59:54.358766Z","iopub.status.idle":"2022-07-11T05:59:54.374512Z","shell.execute_reply.started":"2022-07-11T05:59:54.358727Z","shell.execute_reply":"2022-07-11T05:59:54.373624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Handling Missing Values\ncombine_data = [train, test]\nfor data in combine_data:\n    data['Sex']=data['Sex'].map({'female':0, 'male':1})\nfor data in combine_data:\n    data['Embarked']=data['Embarked'].map({'C':0, 'Q':1, 'S':2})\nfor data in combine_data:\n    data['Cabin']=data['Cabin'].map({'B':1, 'E':4, 'A':0, 'C':2, 'D':3, 'F':5, 'G':6})\nfor data in combine_data:\n    data['Pclass']=data['Pclass'].map({'Upper':2, 'Middle':1, 'Lower':0})    ","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.375938Z","iopub.execute_input":"2022-07-11T05:59:54.376291Z","iopub.status.idle":"2022-07-11T05:59:54.392328Z","shell.execute_reply.started":"2022-07-11T05:59:54.376260Z","shell.execute_reply":"2022-07-11T05:59:54.391296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imputer = KNNImputer(n_neighbors=5).fit(train.drop('Survived', axis=1))\ntrain_impute = pd.DataFrame(imputer.transform(train.drop('Survived', axis=1)))\ntrain_impute.columns= train.drop('Survived', axis=1).columns\ntest_impute = pd.DataFrame(imputer.transform(test))\ntrain_impute['Survived']=train[['Survived']]\ntest_impute.columns= train.drop('Survived', axis=1).columns\ncolumns = ['Pclass', 'SibSp', 'Parch', 'Embarked', 'Sex', 'Age', 'Fare', 'Cabin']\nfor col in columns:\n    train_impute[col]=train_impute[col].astype('int')\n    test_impute[col]=test_impute[col].astype('int')\ntrain_impute.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.393578Z","iopub.execute_input":"2022-07-11T05:59:54.393912Z","iopub.status.idle":"2022-07-11T05:59:54.532945Z","shell.execute_reply.started":"2022-07-11T05:59:54.393882Z","shell.execute_reply":"2022-07-11T05:59:54.531811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Feature and Target\nFeature=train_impute.drop(['Survived'], axis=1)\ntarget=train_impute['Survived']","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.538718Z","iopub.execute_input":"2022-07-11T05:59:54.539626Z","iopub.status.idle":"2022-07-11T05:59:54.552750Z","shell.execute_reply.started":"2022-07-11T05:59:54.539568Z","shell.execute_reply":"2022-07-11T05:59:54.551654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column=['Embarked', 'Age', 'Fare', 'Cabin']\nFeature = pd.get_dummies(Feature, columns=column)\ntest_impute = pd.get_dummies(test_impute, columns=column)\ntest_impute=test_impute.loc[:, Feature.columns]","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.558288Z","iopub.execute_input":"2022-07-11T05:59:54.561308Z","iopub.status.idle":"2022-07-11T05:59:54.587739Z","shell.execute_reply.started":"2022-07-11T05:59:54.561244Z","shell.execute_reply":"2022-07-11T05:59:54.586604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Feature.shape, test_impute.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.593519Z","iopub.execute_input":"2022-07-11T05:59:54.597236Z","iopub.status.idle":"2022-07-11T05:59:54.605597Z","shell.execute_reply.started":"2022-07-11T05:59:54.597155Z","shell.execute_reply":"2022-07-11T05:59:54.604559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking Noise in the data\nfrom sklearn.cluster import DBSCAN\ndbscan = DBSCAN(eps=100, min_samples=50).fit(Feature)\nset(dbscan.labels_)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.606932Z","iopub.execute_input":"2022-07-11T05:59:54.607491Z","iopub.status.idle":"2022-07-11T05:59:54.651350Z","shell.execute_reply.started":"2022-07-11T05:59:54.607453Z","shell.execute_reply":"2022-07-11T05:59:54.650351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.concat([Feature, target], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T05:59:54.652944Z","iopub.execute_input":"2022-07-11T05:59:54.653742Z","iopub.status.idle":"2022-07-11T05:59:54.661496Z","shell.execute_reply.started":"2022-07-11T05:59:54.653693Z","shell.execute_reply":"2022-07-11T05:59:54.660459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Building and Evaluation","metadata":{}},{"cell_type":"code","source":"s = setup(data=train,\n          session_id=1010,\n          target='Survived',\n          train_size=0.99,\n          fold_strategy='stratifiedkfold',\n          fold=10,\n          fold_shuffle=True,\n          silent=True,\n          imputation_type=None,\n          normalize=True,\n          normalize_method='minmax',\n          )","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:13:09.521925Z","iopub.execute_input":"2022-07-11T06:13:09.522958Z","iopub.status.idle":"2022-07-11T06:13:09.839427Z","shell.execute_reply.started":"2022-07-11T06:13:09.522909Z","shell.execute_reply":"2022-07-11T06:13:09.838660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top=compare_models(n_select=5)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:20:32.081807Z","iopub.execute_input":"2022-07-11T06:20:32.083013Z","iopub.status.idle":"2022-07-11T06:20:56.267350Z","shell.execute_reply.started":"2022-07-11T06:20:32.082962Z","shell.execute_reply":"2022-07-11T06:20:56.266352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tuning Model","metadata":{}},{"cell_type":"code","source":"tuned_top = [tune_model(i, fold=10, choose_better=True) for i in top]","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:21:24.225161Z","iopub.execute_input":"2022-07-11T06:21:24.225847Z","iopub.status.idle":"2022-07-11T06:22:46.734985Z","shell.execute_reply.started":"2022-07-11T06:21:24.225801Z","shell.execute_reply":"2022-07-11T06:22:46.734241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ensembling Models","metadata":{}},{"cell_type":"code","source":"blend = blend_models(tuned_top, fold=10)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:22:56.593373Z","iopub.execute_input":"2022-07-11T06:22:56.593826Z","iopub.status.idle":"2022-07-11T06:23:06.194531Z","shell.execute_reply.started":"2022-07-11T06:22:56.593779Z","shell.execute_reply":"2022-07-11T06:23:06.193406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Confusion Matrix\nplot_model(blend, plot='confusion_matrix')","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:23:14.859413Z","iopub.execute_input":"2022-07-11T06:23:14.859881Z","iopub.status.idle":"2022-07-11T06:23:15.666236Z","shell.execute_reply.started":"2022-07-11T06:23:14.859842Z","shell.execute_reply":"2022-07-11T06:23:15.665009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Classification Report\nplot_model(blend, plot='class_report')","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:23:19.904867Z","iopub.execute_input":"2022-07-11T06:23:19.905548Z","iopub.status.idle":"2022-07-11T06:23:20.865431Z","shell.execute_reply.started":"2022-07-11T06:23:19.905510Z","shell.execute_reply":"2022-07-11T06:23:20.864246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#ROC AUC Curve\nplot_model(blend, plot='auc')","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:23:28.852762Z","iopub.execute_input":"2022-07-11T06:23:28.853177Z","iopub.status.idle":"2022-07-11T06:23:29.722058Z","shell.execute_reply.started":"2022-07-11T06:23:28.853143Z","shell.execute_reply":"2022-07-11T06:23:29.720837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submissions to Kaggle","metadata":{}},{"cell_type":"code","source":"#Submit the Prediction to Kaggle\ntest_data['Survived']=blend.predict(test_impute)\ntest_data.loc[:,['PassengerId','Survived']].to_csv('Submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-11T06:23:34.818665Z","iopub.execute_input":"2022-07-11T06:23:34.819099Z","iopub.status.idle":"2022-07-11T06:23:34.947639Z","shell.execute_reply.started":"2022-07-11T06:23:34.819063Z","shell.execute_reply":"2022-07-11T06:23:34.946579Z"},"trusted":true},"execution_count":null,"outputs":[]}]}