{"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":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport scipy.stats as stats\nimport os\nfrom sklearn.model_selection import cross_val_score\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.preprocessing import FunctionTransformer\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import MinMaxScaler, OneHotEncoder\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import PowerTransformer\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.preprocessing import RobustScaler\nfrom sklearn.preprocessing import MaxAbsScaler\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.svm import SVC","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.390198Z","iopub.execute_input":"2022-08-03T01:51:00.390784Z","iopub.status.idle":"2022-08-03T01:51:00.401407Z","shell.execute_reply.started":"2022-08-03T01:51:00.390740Z","shell.execute_reply":"2022-08-03T01:51:00.399863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_data(filname):\n    path = '../input/spaceship-titanic/'\n    full_path = os.path.join(path, filname)\n    return pd.read_csv(full_path)\n\n\ndf = load_data('train.csv')\ndf_test = load_data('test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.507598Z","iopub.execute_input":"2022-08-03T01:51:00.508489Z","iopub.status.idle":"2022-08-03T01:51:00.579314Z","shell.execute_reply.started":"2022-08-03T01:51:00.508442Z","shell.execute_reply":"2022-08-03T01:51:00.577400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.581702Z","iopub.execute_input":"2022-08-03T01:51:00.583216Z","iopub.status.idle":"2022-08-03T01:51:00.609178Z","shell.execute_reply.started":"2022-08-03T01:51:00.583154Z","shell.execute_reply":"2022-08-03T01:51:00.607451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.662439Z","iopub.execute_input":"2022-08-03T01:51:00.662857Z","iopub.status.idle":"2022-08-03T01:51:00.685918Z","shell.execute_reply.started":"2022-08-03T01:51:00.662823Z","shell.execute_reply":"2022-08-03T01:51:00.684880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nX = df.drop('Transported', axis=1)\ny = df['Transported']\nX_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3, random_state=42)\nX_train.shape, X_test.shape, y_train.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.749055Z","iopub.execute_input":"2022-08-03T01:51:00.750202Z","iopub.status.idle":"2022-08-03T01:51:00.773775Z","shell.execute_reply.started":"2022-08-03T01:51:00.750119Z","shell.execute_reply":"2022-08-03T01:51:00.771646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train['Name'].nunique())\nprint(X_train['PassengerId'].nunique())","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:00.856912Z","iopub.execute_input":"2022-08-03T01:51:00.857508Z","iopub.status.idle":"2022-08-03T01:51:00.878070Z","shell.execute_reply.started":"2022-08-03T01:51:00.857464Z","shell.execute_reply":"2022-08-03T01:51:00.875160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop(['PassengerId','Name'], axis=1, inplace= True)\nX_test.drop(['PassengerId','Name'], axis=1, inplace= True)\ndf_test.drop(['Name'], axis = 1, inplace =True)\n\npassenger_id_test = df_test.pop('PassengerId')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.022666Z","iopub.execute_input":"2022-08-03T01:51:01.023143Z","iopub.status.idle":"2022-08-03T01:51:01.039515Z","shell.execute_reply.started":"2022-08-03T01:51:01.023087Z","shell.execute_reply":"2022-08-03T01:51:01.038105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Total MISSING VALUES IN TRAIN DATA: {X_train.isna().sum().sum()}')\nprint(f'Total MISSING VALUES IN TEST DATA: {X_test.isna().sum().sum()}')\nprint(f'Total MISSING VALUES IN TEST DATA: {df_test.isna().sum().sum()}')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.217310Z","iopub.execute_input":"2022-08-03T01:51:01.218995Z","iopub.status.idle":"2022-08-03T01:51:01.238957Z","shell.execute_reply.started":"2022-08-03T01:51:01.218929Z","shell.execute_reply":"2022-08-03T01:51:01.237049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Missing Values for each column\nX_train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.262198Z","iopub.execute_input":"2022-08-03T01:51:01.263723Z","iopub.status.idle":"2022-08-03T01:51:01.279983Z","shell.execute_reply.started":"2022-08-03T01:51:01.263649Z","shell.execute_reply":"2022-08-03T01:51:01.278803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.404987Z","iopub.execute_input":"2022-08-03T01:51:01.406438Z","iopub.status.idle":"2022-08-03T01:51:01.417990Z","shell.execute_reply.started":"2022-08-03T01:51:01.406388Z","shell.execute_reply":"2022-08-03T01:51:01.416870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.539021Z","iopub.execute_input":"2022-08-03T01:51:01.539551Z","iopub.status.idle":"2022-08-03T01:51:01.553918Z","shell.execute_reply.started":"2022-08-03T01:51:01.539514Z","shell.execute_reply":"2022-08-03T01:51:01.552811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percent_missing = X_train.isnull().sum() * 100 / len(df)\n\n# Approximately 2% of data is missing for the specified columns\npercent_missing","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.614688Z","iopub.execute_input":"2022-08-03T01:51:01.615213Z","iopub.status.idle":"2022-08-03T01:51:01.631781Z","shell.execute_reply.started":"2022-08-03T01:51:01.615170Z","shell.execute_reply":"2022-08-03T01:51:01.630058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,6))\nsns.heatmap(X_train.isnull(),cmap = 'viridis', yticklabels=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:01.721491Z","iopub.execute_input":"2022-08-03T01:51:01.722551Z","iopub.status.idle":"2022-08-03T01:51:02.140731Z","shell.execute_reply.started":"2022-08-03T01:51:01.722508Z","shell.execute_reply":"2022-08-03T01:51:02.139224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_data = X_train.select_dtypes(include=[np.number])\nnum_data_df_test = df_test.select_dtypes(include=[np.number])\nnum_data_test = X_test.select_dtypes(include=[np.number])\n\ncat_data = X_train.select_dtypes(exclude=[np.number])\ncat_data_test = X_test.select_dtypes(exclude=[np.number])\ncat_data_df_test = df_test.select_dtypes(exclude=[np.number])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:02.143743Z","iopub.execute_input":"2022-08-03T01:51:02.144621Z","iopub.status.idle":"2022-08-03T01:51:02.167101Z","shell.execute_reply.started":"2022-08-03T01:51:02.144572Z","shell.execute_reply":"2022-08-03T01:51:02.165595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_data.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:02.168913Z","iopub.execute_input":"2022-08-03T01:51:02.170002Z","iopub.status.idle":"2022-08-03T01:51:02.183488Z","shell.execute_reply.started":"2022-08-03T01:51:02.169956Z","shell.execute_reply":"2022-08-03T01:51:02.182195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = num_data.shape[1]\nfig, axes = plt.subplots(n, 1, figsize=(18/1.54, 18/1.54))\n\nfor ax, col in zip(axes, num_data):  # For each column...\n    sns.boxplot(col, data=num_data, ax=ax)   # Plot histogaerm\n    ax.axvline(num_data[col].mean(), c='k')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:02.186882Z","iopub.execute_input":"2022-08-03T01:51:02.187955Z","iopub.status.idle":"2022-08-03T01:51:02.905889Z","shell.execute_reply.started":"2022-08-03T01:51:02.187899Z","shell.execute_reply":"2022-08-03T01:51:02.904412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = num_data.shape[1]\nfig, axes = plt.subplots(n, 1, figsize=(18/1.54, 18/1.54))\n\nfor ax, col in zip(axes, num_data):  # For each column...\n    sns.distplot(num_data[col], ax=ax)   # Plot histogaerm\n    ax.axvline(num_data[col].mean(), c='k')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:02.908371Z","iopub.execute_input":"2022-08-03T01:51:02.909297Z","iopub.status.idle":"2022-08-03T01:51:04.450886Z","shell.execute_reply.started":"2022-08-03T01:51:02.909229Z","shell.execute_reply":"2022-08-03T01:51:04.449343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Target in Train Data:-\\n',y_train.value_counts()) #balanced dataset\nprint()\nprint('Target in Test Data:-\\n',y_test.value_counts()) ","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.453208Z","iopub.execute_input":"2022-08-03T01:51:04.453725Z","iopub.status.idle":"2022-08-03T01:51:04.465799Z","shell.execute_reply.started":"2022-08-03T01:51:04.453677Z","shell.execute_reply":"2022-08-03T01:51:04.464105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imp_mode = SimpleImputer(strategy='most_frequent')\nimp_median = SimpleImputer(strategy='median')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.469671Z","iopub.execute_input":"2022-08-03T01:51:04.470482Z","iopub.status.idle":"2022-08-03T01:51:04.481081Z","shell.execute_reply.started":"2022-08-03T01:51:04.470437Z","shell.execute_reply":"2022-08-03T01:51:04.479089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_num = ColumnTransformer([\n    ('median',imp_median,list(num_data.columns[:1])),\n    ('mode',imp_mode, list(num_data.columns[1:]))\n    \n], remainder='drop')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.483450Z","iopub.execute_input":"2022-08-03T01:51:04.484433Z","iopub.status.idle":"2022-08-03T01:51:04.493615Z","shell.execute_reply.started":"2022-08-03T01:51:04.484384Z","shell.execute_reply":"2022-08-03T01:51:04.492119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_num.fit(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.495930Z","iopub.execute_input":"2022-08-03T01:51:04.496416Z","iopub.status.idle":"2022-08-03T01:51:04.533575Z","shell.execute_reply.started":"2022-08-03T01:51:04.496377Z","shell.execute_reply":"2022-08-03T01:51:04.532575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_num.transformers_","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.534993Z","iopub.execute_input":"2022-08-03T01:51:04.535710Z","iopub.status.idle":"2022-08-03T01:51:04.544659Z","shell.execute_reply.started":"2022-08-03T01:51:04.535672Z","shell.execute_reply":"2022-08-03T01:51:04.543602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"impute_num_train = missing_num.transform(X_train)\nimpute_num_test = missing_num.transform(X_test)\nimpute_num_df_test = missing_num.transform(df_test)\n\nX_impute_num_train = pd.DataFrame(impute_num_train, columns=num_data.columns)\nX_impute_num_test = pd.DataFrame(impute_num_test, columns=num_data.columns)\nX_impute_num_df_test = pd.DataFrame(impute_num_df_test, columns=num_data.columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.546279Z","iopub.execute_input":"2022-08-03T01:51:04.546722Z","iopub.status.idle":"2022-08-03T01:51:04.582449Z","shell.execute_reply.started":"2022-08-03T01:51:04.546682Z","shell.execute_reply":"2022-08-03T01:51:04.580940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_num_train.isnull().sum(),X_impute_num_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.584246Z","iopub.execute_input":"2022-08-03T01:51:04.584668Z","iopub.status.idle":"2022-08-03T01:51:04.599869Z","shell.execute_reply.started":"2022-08-03T01:51:04.584632Z","shell.execute_reply":"2022-08-03T01:51:04.598552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting the distplots without any transformation\n# Box-Cox not applicable to this dataset because it contains data in negative value\nfor col in X_impute_num_train.columns:\n    plt.figure(figsize=(14,4))\n    plt.subplot(121)\n    sns.distplot(X_train[col])\n    plt.title(col)\n\n    plt.subplot(122)\n    stats.probplot(X_impute_num_train[col], dist=\"norm\", plot=plt)\n    plt.title(col)\n\n    plt.show()\n    ","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:04.601375Z","iopub.execute_input":"2022-08-03T01:51:04.601881Z","iopub.status.idle":"2022-08-03T01:51:08.453118Z","shell.execute_reply.started":"2022-08-03T01:51:04.601842Z","shell.execute_reply":"2022-08-03T01:51:08.451728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Apply Yeo-Johnson transform\n# It tries to normalize numerical dataset\n\n'''pt1 = PowerTransformer()\n\nX_impute_num_train_transormed = pt1.fit_transform(X_impute_num_train)\nX_impute_num_test_transormed = pt1.transform(X_impute_num_test)\n\n\n\npd.DataFrame({'cols':X_impute_num_train.columns,'Yeo_Johnson_lambdas':pt1.lambdas_})'''","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.455016Z","iopub.execute_input":"2022-08-03T01:51:08.455508Z","iopub.status.idle":"2022-08-03T01:51:08.465306Z","shell.execute_reply.started":"2022-08-03T01:51:08.455467Z","shell.execute_reply":"2022-08-03T01:51:08.463708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trf = FunctionTransformer(func=np.log1p)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.471986Z","iopub.execute_input":"2022-08-03T01:51:08.472897Z","iopub.status.idle":"2022-08-03T01:51:08.479797Z","shell.execute_reply.started":"2022-08-03T01:51:08.472847Z","shell.execute_reply":"2022-08-03T01:51:08.478229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trf2 = Pipeline([('log',FunctionTransformer(np.log1p))])\n\nX_impute_num_train_transormed = trf2.fit_transform(X_impute_num_train)\nX_impute_num_test_transormed = trf2.transform(X_impute_num_test)\nX_impute_num_df_test_transormed = trf2.transform(X_impute_num_df_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.481724Z","iopub.execute_input":"2022-08-03T01:51:08.482164Z","iopub.status.idle":"2022-08-03T01:51:08.498284Z","shell.execute_reply.started":"2022-08-03T01:51:08.482098Z","shell.execute_reply":"2022-08-03T01:51:08.496705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_num_train_transormed = pd.DataFrame(X_impute_num_train_transormed,columns=X_impute_num_train.columns)\nX_impute_num_test_transormed = pd.DataFrame(X_impute_num_test_transormed,columns=X_impute_num_test.columns)\nX_impute_num_df_test_transormed = pd.DataFrame(X_impute_num_df_test_transormed,columns=X_impute_num_df_test.columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.500393Z","iopub.execute_input":"2022-08-03T01:51:08.501258Z","iopub.status.idle":"2022-08-03T01:51:08.511847Z","shell.execute_reply.started":"2022-08-03T01:51:08.501203Z","shell.execute_reply":"2022-08-03T01:51:08.510741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_num_train_transormed.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.513969Z","iopub.execute_input":"2022-08-03T01:51:08.514897Z","iopub.status.idle":"2022-08-03T01:51:08.537447Z","shell.execute_reply.started":"2022-08-03T01:51:08.514842Z","shell.execute_reply":"2022-08-03T01:51:08.536023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Before and after comparision for Yeo-Johnson\n\nfor col in X_impute_num_train_transormed.columns:\n    plt.figure(figsize=(14,4))\n    plt.subplot(121)\n    sns.distplot(X_impute_num_train[col])\n    plt.title(col)\n\n    plt.subplot(122)\n    sns.distplot(X_impute_num_train_transormed[col])\n    plt.title(col)\n\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:08.539760Z","iopub.execute_input":"2022-08-03T01:51:08.540645Z","iopub.status.idle":"2022-08-03T01:51:11.906381Z","shell.execute_reply.started":"2022-08-03T01:51:08.540592Z","shell.execute_reply":"2022-08-03T01:51:11.904851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:11.909640Z","iopub.execute_input":"2022-08-03T01:51:11.910247Z","iopub.status.idle":"2022-08-03T01:51:11.926236Z","shell.execute_reply.started":"2022-08-03T01:51:11.910190Z","shell.execute_reply":"2022-08-03T01:51:11.924752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in cat_data.columns:\n    print(i,':',cat_data[i].nunique())","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:11.928707Z","iopub.execute_input":"2022-08-03T01:51:11.930046Z","iopub.status.idle":"2022-08-03T01:51:11.946250Z","shell.execute_reply.started":"2022-08-03T01:51:11.929983Z","shell.execute_reply":"2022-08-03T01:51:11.944245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:11.948393Z","iopub.execute_input":"2022-08-03T01:51:11.950179Z","iopub.status.idle":"2022-08-03T01:51:11.975093Z","shell.execute_reply.started":"2022-08-03T01:51:11.950094Z","shell.execute_reply":"2022-08-03T01:51:11.974063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_deck'] = cat_data['Cabin'].apply(lambda x: str(x).split('/')[0] if type(x) == str else x)\ncat_data_test['Cabin_deck'] = cat_data_test['Cabin'].apply(lambda x: str(x).split('/')[0] if type(x) == str else x)\ncat_data_df_test['Cabin_deck'] = cat_data_df_test['Cabin'].apply(lambda x: str(x).split('/')[0] if type(x) == str else x)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:11.977281Z","iopub.execute_input":"2022-08-03T01:51:11.978314Z","iopub.status.idle":"2022-08-03T01:51:12.006068Z","shell.execute_reply.started":"2022-08-03T01:51:11.978258Z","shell.execute_reply":"2022-08-03T01:51:12.004600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_num'] = cat_data['Cabin'].apply(lambda x: str(x).split('/')[1] if type(x) == str else x)\ncat_data_test['Cabin_num'] = cat_data_test['Cabin'].apply(lambda x: str(x).split('/')[1] if type(x) == str else x)\ncat_data_df_test['Cabin_num'] = cat_data_df_test['Cabin'].apply(lambda x: str(x).split('/')[1] if type(x) == str else x)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.008314Z","iopub.execute_input":"2022-08-03T01:51:12.009515Z","iopub.status.idle":"2022-08-03T01:51:12.042954Z","shell.execute_reply.started":"2022-08-03T01:51:12.009443Z","shell.execute_reply":"2022-08-03T01:51:12.041253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_side'] = cat_data['Cabin'].apply(lambda x: str(x).split('/')[2] if type(x) == str else x)\ncat_data_test['Cabin_side'] = cat_data_test['Cabin'].apply(lambda x: str(x).split('/')[2] if type(x) == str else x)\ncat_data_df_test['Cabin_side'] = cat_data_df_test['Cabin'].apply(lambda x: str(x).split('/')[2] if type(x) == str else x)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.045046Z","iopub.execute_input":"2022-08-03T01:51:12.046307Z","iopub.status.idle":"2022-08-03T01:51:12.076889Z","shell.execute_reply.started":"2022-08-03T01:51:12.046245Z","shell.execute_reply":"2022-08-03T01:51:12.075266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.drop('Cabin', axis=1, inplace= True)\ncat_data_test.drop('Cabin', axis=1, inplace= True)\ncat_data.drop('Cabin', axis=1, inplace= True)\ncat_data_df_test.drop('Cabin', axis=1, inplace= True)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.079838Z","iopub.execute_input":"2022-08-03T01:51:12.081121Z","iopub.status.idle":"2022-08-03T01:51:12.103305Z","shell.execute_reply.started":"2022-08-03T01:51:12.081053Z","shell.execute_reply":"2022-08-03T01:51:12.101483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.106270Z","iopub.execute_input":"2022-08-03T01:51:12.107486Z","iopub.status.idle":"2022-08-03T01:51:12.130235Z","shell.execute_reply.started":"2022-08-03T01:51:12.107423Z","shell.execute_reply":"2022-08-03T01:51:12.128807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_side'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.132725Z","iopub.execute_input":"2022-08-03T01:51:12.133802Z","iopub.status.idle":"2022-08-03T01:51:12.149146Z","shell.execute_reply.started":"2022-08-03T01:51:12.133741Z","shell.execute_reply":"2022-08-03T01:51:12.147517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_deck'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.154700Z","iopub.execute_input":"2022-08-03T01:51:12.155221Z","iopub.status.idle":"2022-08-03T01:51:12.165719Z","shell.execute_reply.started":"2022-08-03T01:51:12.155177Z","shell.execute_reply":"2022-08-03T01:51:12.164698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data_df_test","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.167319Z","iopub.execute_input":"2022-08-03T01:51:12.168655Z","iopub.status.idle":"2022-08-03T01:51:12.193865Z","shell.execute_reply.started":"2022-08-03T01:51:12.168604Z","shell.execute_reply":"2022-08-03T01:51:12.192116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(cat_data.isnull(),cmap = 'viridis', yticklabels=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.196400Z","iopub.execute_input":"2022-08-03T01:51:12.197512Z","iopub.status.idle":"2022-08-03T01:51:12.473137Z","shell.execute_reply.started":"2022-08-03T01:51:12.197452Z","shell.execute_reply":"2022-08-03T01:51:12.471493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(cat_data['Cabin_num'], bins=50)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.475161Z","iopub.execute_input":"2022-08-03T01:51:12.476833Z","iopub.status.idle":"2022-08-03T01:51:12.831781Z","shell.execute_reply.started":"2022-08-03T01:51:12.476768Z","shell.execute_reply":"2022-08-03T01:51:12.830374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(cat_data['Cabin_num'].astype(float))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:12.833810Z","iopub.execute_input":"2022-08-03T01:51:12.834688Z","iopub.status.idle":"2022-08-03T01:51:13.056679Z","shell.execute_reply.started":"2022-08-03T01:51:12.834644Z","shell.execute_reply":"2022-08-03T01:51:13.055048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data['Cabin_side'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.058427Z","iopub.execute_input":"2022-08-03T01:51:13.058867Z","iopub.status.idle":"2022-08-03T01:51:13.073059Z","shell.execute_reply.started":"2022-08-03T01:51:13.058831Z","shell.execute_reply":"2022-08-03T01:51:13.071542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\ndef impute_cabin_side(row):\n    if type(row) != str:\n        return random.choice(['S','P'])\n    else:\n        return row\n    \ndef impute_cabin_deck(row):\n    if type(row) != str:\n        return random.choice(['F','G'])\n    else:\n        return row\n    \n\ncat_data['Cabin_side'] = cat_data['Cabin_side'].apply(lambda x : impute_cabin_side(x))\ncat_data['Cabin_deck'] = cat_data['Cabin_deck'].apply(lambda x : impute_cabin_deck(x))\n\ncat_data_test['Cabin_side'] = cat_data_test['Cabin_side'].apply(lambda x : impute_cabin_side(x))\ncat_data_test['Cabin_deck'] = cat_data_test['Cabin_deck'].apply(lambda x : impute_cabin_deck(x))\n\ncat_data_df_test['Cabin_side'] = cat_data_df_test['Cabin_side'].apply(lambda x : impute_cabin_side(x))\ncat_data_df_test['Cabin_deck'] = cat_data_df_test['Cabin_deck'].apply(lambda x : impute_cabin_deck(x))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.075253Z","iopub.execute_input":"2022-08-03T01:51:13.077150Z","iopub.status.idle":"2022-08-03T01:51:13.111893Z","shell.execute_reply.started":"2022-08-03T01:51:13.077058Z","shell.execute_reply":"2022-08-03T01:51:13.110267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data.drop('Cabin_num',axis=1, inplace=True)\ncat_data_test.drop('Cabin_num',axis=1, inplace=True)\ncat_data_df_test.drop('Cabin_num',axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.113575Z","iopub.execute_input":"2022-08-03T01:51:13.114014Z","iopub.status.idle":"2022-08-03T01:51:13.126941Z","shell.execute_reply.started":"2022-08-03T01:51:13.113975Z","shell.execute_reply":"2022-08-03T01:51:13.125660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.128940Z","iopub.execute_input":"2022-08-03T01:51:13.129430Z","iopub.status.idle":"2022-08-03T01:51:13.142899Z","shell.execute_reply.started":"2022-08-03T01:51:13.129387Z","shell.execute_reply":"2022-08-03T01:51:13.141554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.144789Z","iopub.execute_input":"2022-08-03T01:51:13.145233Z","iopub.status.idle":"2022-08-03T01:51:13.163836Z","shell.execute_reply.started":"2022-08-03T01:51:13.145193Z","shell.execute_reply":"2022-08-03T01:51:13.162771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data_df_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.173955Z","iopub.execute_input":"2022-08-03T01:51:13.175453Z","iopub.status.idle":"2022-08-03T01:51:13.188642Z","shell.execute_reply.started":"2022-08-03T01:51:13.175396Z","shell.execute_reply":"2022-08-03T01:51:13.187310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_num_train_transormed.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.191523Z","iopub.execute_input":"2022-08-03T01:51:13.192454Z","iopub.status.idle":"2022-08-03T01:51:13.204120Z","shell.execute_reply.started":"2022-08-03T01:51:13.192409Z","shell.execute_reply":"2022-08-03T01:51:13.202549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_num_test.shape, cat_data_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.206073Z","iopub.execute_input":"2022-08-03T01:51:13.206556Z","iopub.status.idle":"2022-08-03T01:51:13.218865Z","shell.execute_reply.started":"2022-08-03T01:51:13.206514Z","shell.execute_reply":"2022-08-03T01:51:13.217270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.221410Z","iopub.execute_input":"2022-08-03T01:51:13.222016Z","iopub.status.idle":"2022-08-03T01:51:13.241048Z","shell.execute_reply.started":"2022-08-03T01:51:13.221962Z","shell.execute_reply":"2022-08-03T01:51:13.239372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_input_train = pd.concat([cat_data.reset_index(drop=True), X_impute_num_train_transormed.reset_index(drop=True)], axis=1)\nX_input_test = pd.concat([cat_data_test.reset_index(drop=True), X_impute_num_test_transormed.reset_index(drop=True)], axis=1)\nX_input_df_test = pd.concat([cat_data_df_test.reset_index(drop=True), X_impute_num_df_test_transormed.reset_index(drop=True)], axis=1)\nX_input_train.shape, X_input_test.shape, X_input_df_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.243148Z","iopub.execute_input":"2022-08-03T01:51:13.243983Z","iopub.status.idle":"2022-08-03T01:51:13.262594Z","shell.execute_reply.started":"2022-08-03T01:51:13.243931Z","shell.execute_reply":"2022-08-03T01:51:13.260483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_input_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.264905Z","iopub.execute_input":"2022-08-03T01:51:13.265845Z","iopub.status.idle":"2022-08-03T01:51:13.286004Z","shell.execute_reply.started":"2022-08-03T01:51:13.265790Z","shell.execute_reply":"2022-08-03T01:51:13.284320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_input_df_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.288500Z","iopub.execute_input":"2022-08-03T01:51:13.290552Z","iopub.status.idle":"2022-08-03T01:51:13.304914Z","shell.execute_reply.started":"2022-08-03T01:51:13.290482Z","shell.execute_reply":"2022-08-03T01:51:13.303649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_input_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.306450Z","iopub.execute_input":"2022-08-03T01:51:13.308046Z","iopub.status.idle":"2022-08-03T01:51:13.334864Z","shell.execute_reply.started":"2022-08-03T01:51:13.307982Z","shell.execute_reply":"2022-08-03T01:51:13.333350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_cat = ColumnTransformer([\n    ('mode',imp_mode,list(X_input_train.columns[:4]))\n],remainder='passthrough')\n","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.337292Z","iopub.execute_input":"2022-08-03T01:51:13.337787Z","iopub.status.idle":"2022-08-03T01:51:13.348923Z","shell.execute_reply.started":"2022-08-03T01:51:13.337745Z","shell.execute_reply":"2022-08-03T01:51:13.347697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_cat.fit(X_input_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.350694Z","iopub.execute_input":"2022-08-03T01:51:13.351158Z","iopub.status.idle":"2022-08-03T01:51:13.384953Z","shell.execute_reply.started":"2022-08-03T01:51:13.351102Z","shell.execute_reply":"2022-08-03T01:51:13.383441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_cat.transformers_","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.387696Z","iopub.execute_input":"2022-08-03T01:51:13.388207Z","iopub.status.idle":"2022-08-03T01:51:13.398355Z","shell.execute_reply.started":"2022-08-03T01:51:13.388161Z","shell.execute_reply":"2022-08-03T01:51:13.397011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"impute_cat_train = missing_cat.transform(X_input_train)\nimpute_cat_test = missing_cat.transform(X_input_test)\nimpute_cat_df_test = missing_cat.transform(X_input_df_test)\n\nX_impute_cat_train = pd.DataFrame(impute_cat_train, columns=X_input_train.columns)\nX_impute_cat_test = pd.DataFrame(impute_cat_test, columns=X_input_test.columns)\nX_impute_cat_df_test = pd.DataFrame(impute_cat_df_test, columns=X_input_df_test.columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.400496Z","iopub.execute_input":"2022-08-03T01:51:13.402340Z","iopub.status.idle":"2022-08-03T01:51:13.439923Z","shell.execute_reply.started":"2022-08-03T01:51:13.402280Z","shell.execute_reply":"2022-08-03T01:51:13.438545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_input_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.441757Z","iopub.execute_input":"2022-08-03T01:51:13.442214Z","iopub.status.idle":"2022-08-03T01:51:13.456754Z","shell.execute_reply.started":"2022-08-03T01:51:13.442160Z","shell.execute_reply":"2022-08-03T01:51:13.455524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_cat_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.458498Z","iopub.execute_input":"2022-08-03T01:51:13.459112Z","iopub.status.idle":"2022-08-03T01:51:13.476074Z","shell.execute_reply.started":"2022-08-03T01:51:13.459063Z","shell.execute_reply":"2022-08-03T01:51:13.474594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_cat_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.478107Z","iopub.execute_input":"2022-08-03T01:51:13.478711Z","iopub.status.idle":"2022-08-03T01:51:13.497834Z","shell.execute_reply.started":"2022-08-03T01:51:13.478663Z","shell.execute_reply":"2022-08-03T01:51:13.495805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_cat_df_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.500446Z","iopub.execute_input":"2022-08-03T01:51:13.500930Z","iopub.status.idle":"2022-08-03T01:51:13.518270Z","shell.execute_reply.started":"2022-08-03T01:51:13.500890Z","shell.execute_reply":"2022-08-03T01:51:13.515641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_impute_cat_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.520764Z","iopub.execute_input":"2022-08-03T01:51:13.521273Z","iopub.status.idle":"2022-08-03T01:51:13.548590Z","shell.execute_reply.started":"2022-08-03T01:51:13.521232Z","shell.execute_reply":"2022-08-03T01:51:13.546049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scaler = RobustScaler() \n'''no change in the accuracy. Used when dataset has more outlier's. This dataset has more outlier but didn't change accuracy.'''\n#scaler = MaxAbsScaler() \n'''decrement on the decision tree accuracy. used when dataset has more 0's(sparse). this dataset has more 0's but accuracy didn't changed'''\nscaler = MinMaxScaler()\n#scaler = StandardScaler() #decrement in accuracy of DT\n'''almost similar to minmaxscaler()''' \nencoder = OneHotEncoder(handle_unknown='ignore')","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.551547Z","iopub.execute_input":"2022-08-03T01:51:13.552020Z","iopub.status.idle":"2022-08-03T01:51:13.563927Z","shell.execute_reply.started":"2022-08-03T01:51:13.551979Z","shell.execute_reply":"2022-08-03T01:51:13.562703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preprocess = ColumnTransformer([\n    ('enc',encoder,slice(0,6)),\n    ('scale',scaler,slice(6,13))\n])\n\n#preprocess.fit(X_input)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.566099Z","iopub.execute_input":"2022-08-03T01:51:13.566556Z","iopub.status.idle":"2022-08-03T01:51:13.582572Z","shell.execute_reply.started":"2022-08-03T01:51:13.566517Z","shell.execute_reply":"2022-08-03T01:51:13.581156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe = Pipeline([\n    ('missing_cat',missing_cat),\n    ('preprocess',preprocess)\n])","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.584238Z","iopub.execute_input":"2022-08-03T01:51:13.584658Z","iopub.status.idle":"2022-08-03T01:51:13.599478Z","shell.execute_reply.started":"2022-08-03T01:51:13.584613Z","shell.execute_reply":"2022-08-03T01:51:13.597708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pipe.fit(X_input_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.602253Z","iopub.execute_input":"2022-08-03T01:51:13.603069Z","iopub.status.idle":"2022-08-03T01:51:13.668270Z","shell.execute_reply.started":"2022-08-03T01:51:13.602816Z","shell.execute_reply":"2022-08-03T01:51:13.666857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = pipe.transform(X_input_train)\nX_test = pipe.transform(X_input_test)\nX_df_test = pipe.transform(X_input_df_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.671052Z","iopub.execute_input":"2022-08-03T01:51:13.671583Z","iopub.status.idle":"2022-08-03T01:51:13.739642Z","shell.execute_reply.started":"2022-08-03T01:51:13.671544Z","shell.execute_reply":"2022-08-03T01:51:13.738243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape, X_test.shape, X_df_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.745695Z","iopub.execute_input":"2022-08-03T01:51:13.746259Z","iopub.status.idle":"2022-08-03T01:51:13.757058Z","shell.execute_reply.started":"2022-08-03T01:51:13.746210Z","shell.execute_reply":"2022-08-03T01:51:13.755478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = np.where(y_train == False ,0 , 1)\ny_test = np.where(y_test == False ,0 , 1)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.758454Z","iopub.execute_input":"2022-08-03T01:51:13.758862Z","iopub.status.idle":"2022-08-03T01:51:13.772196Z","shell.execute_reply.started":"2022-08-03T01:51:13.758821Z","shell.execute_reply":"2022-08-03T01:51:13.770634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.774219Z","iopub.execute_input":"2022-08-03T01:51:13.774809Z","iopub.status.idle":"2022-08-03T01:51:13.789992Z","shell.execute_reply.started":"2022-08-03T01:51:13.774686Z","shell.execute_reply":"2022-08-03T01:51:13.788418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nlg_reg = LogisticRegression(solver='saga',max_iter=1000, penalty='l2')\nlg_reg.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:13.791698Z","iopub.execute_input":"2022-08-03T01:51:13.792311Z","iopub.status.idle":"2022-08-03T01:51:14.169981Z","shell.execute_reply.started":"2022-08-03T01:51:13.792250Z","shell.execute_reply":"2022-08-03T01:51:14.168495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, f1_score, precision_score, confusion_matrix\nprint(lg_reg.score(X_train, y_train))\ny_pred = lg_reg.predict(X_test)\n\n\nprint(accuracy_score(y_pred, y_test))\nprint(confusion_matrix(y_pred, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:14.172113Z","iopub.execute_input":"2022-08-03T01:51:14.172664Z","iopub.status.idle":"2022-08-03T01:51:14.192957Z","shell.execute_reply.started":"2022-08-03T01:51:14.172622Z","shell.execute_reply":"2022-08-03T01:51:14.189530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:14.196488Z","iopub.execute_input":"2022-08-03T01:51:14.200743Z","iopub.status.idle":"2022-08-03T01:51:14.215685Z","shell.execute_reply.started":"2022-08-03T01:51:14.200636Z","shell.execute_reply":"2022-08-03T01:51:14.213735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"LR\",np.mean(cross_val_score(lg_reg,X_train,y_train,scoring='accuracy',cv=10)))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:14.218279Z","iopub.execute_input":"2022-08-03T01:51:14.220118Z","iopub.status.idle":"2022-08-03T01:51:17.993860Z","shell.execute_reply.started":"2022-08-03T01:51:14.220031Z","shell.execute_reply":"2022-08-03T01:51:17.991932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf2 = DecisionTreeClassifier(min_samples_leaf = 95,min_samples_split = 30, criterion = 'entropy', splitter = 'best',max_features = 11)\nclf2.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:17.996363Z","iopub.execute_input":"2022-08-03T01:51:17.997581Z","iopub.status.idle":"2022-08-03T01:51:18.040191Z","shell.execute_reply.started":"2022-08-03T01:51:17.997505Z","shell.execute_reply":"2022-08-03T01:51:18.038021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(clf2.score(X_train, y_train))\ny_pred = clf2.predict(X_test)\n\nprint(accuracy_score(y_pred, y_test))\nprint(confusion_matrix(y_pred, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:18.042969Z","iopub.execute_input":"2022-08-03T01:51:18.045199Z","iopub.status.idle":"2022-08-03T01:51:18.070417Z","shell.execute_reply.started":"2022-08-03T01:51:18.045086Z","shell.execute_reply":"2022-08-03T01:51:18.068465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"DT\",np.mean(cross_val_score(clf2,X_train,y_train,scoring='accuracy',cv=3)))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:18.072609Z","iopub.execute_input":"2022-08-03T01:51:18.073601Z","iopub.status.idle":"2022-08-03T01:51:18.141400Z","shell.execute_reply.started":"2022-08-03T01:51:18.073524Z","shell.execute_reply":"2022-08-03T01:51:18.139992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rfc = RandomForestClassifier(max_depth=4,criterion='gini',min_samples_split=115)\nrfc.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:18.143459Z","iopub.execute_input":"2022-08-03T01:51:18.145041Z","iopub.status.idle":"2022-08-03T01:51:18.600424Z","shell.execute_reply.started":"2022-08-03T01:51:18.144990Z","shell.execute_reply":"2022-08-03T01:51:18.598889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(rfc.score(X_train, y_train))\ny_pred = rfc.predict(X_test)\n\nprint(accuracy_score(y_pred, y_test))\nprint(confusion_matrix(y_pred, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:18.602213Z","iopub.execute_input":"2022-08-03T01:51:18.602696Z","iopub.status.idle":"2022-08-03T01:51:18.729053Z","shell.execute_reply.started":"2022-08-03T01:51:18.602656Z","shell.execute_reply":"2022-08-03T01:51:18.727615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"RF\",np.mean(cross_val_score(rfc,X_train,y_train,scoring='accuracy',cv=3)))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:18.731152Z","iopub.execute_input":"2022-08-03T01:51:18.732083Z","iopub.status.idle":"2022-08-03T01:51:19.910247Z","shell.execute_reply.started":"2022-08-03T01:51:18.732031Z","shell.execute_reply":"2022-08-03T01:51:19.908883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC(kernel='poly', degree=5, C=0.01)\nsvc.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:19.912709Z","iopub.execute_input":"2022-08-03T01:51:19.913236Z","iopub.status.idle":"2022-08-03T01:51:21.614624Z","shell.execute_reply.started":"2022-08-03T01:51:19.913192Z","shell.execute_reply":"2022-08-03T01:51:21.613634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nprint(svc.score(X_train, y_train))\ny_pred = svc.predict(X_test)\n\nprint(accuracy_score(y_pred, y_test))\nprint(confusion_matrix(y_pred, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:21.616354Z","iopub.execute_input":"2022-08-03T01:51:21.617475Z","iopub.status.idle":"2022-08-03T01:51:23.072298Z","shell.execute_reply.started":"2022-08-03T01:51:21.617432Z","shell.execute_reply":"2022-08-03T01:51:23.070865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Predicting on Test Data","metadata":{}},{"cell_type":"code","source":"test_predict = lg_reg.predict(X_df_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:51:23.074349Z","iopub.execute_input":"2022-08-03T01:51:23.075413Z","iopub.status.idle":"2022-08-03T01:51:23.092588Z","shell.execute_reply.started":"2022-08-03T01:51:23.075372Z","shell.execute_reply":"2022-08-03T01:51:23.090929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_predict","metadata":{"execution":{"iopub.status.busy":"2022-08-03T01:53:02.850894Z","iopub.execute_input":"2022-08-03T01:53:02.851510Z","iopub.status.idle":"2022-08-03T01:53:02.861811Z","shell.execute_reply.started":"2022-08-03T01:53:02.851455Z","shell.execute_reply":"2022-08-03T01:53:02.860023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_result = pd.DataFrame([passenger_id_test, np.where(test_predict == 0, False, True)], ['PassengerId','Transported']).T\nfinal_result","metadata":{"execution":{"iopub.status.busy":"2022-08-03T02:03:05.561329Z","iopub.execute_input":"2022-08-03T02:03:05.562259Z","iopub.status.idle":"2022-08-03T02:03:05.727081Z","shell.execute_reply.started":"2022-08-03T02:03:05.562207Z","shell.execute_reply":"2022-08-03T02:03:05.725534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_result.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-03T02:05:30.603847Z","iopub.execute_input":"2022-08-03T02:05:30.604930Z","iopub.status.idle":"2022-08-03T02:05:30.624554Z","shell.execute_reply.started":"2022-08-03T02:05:30.604878Z","shell.execute_reply":"2022-08-03T02:05:30.622699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}