{"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 seaborn as sns\nimport matplotlib.pyplot as plt \nfrom sklearn.ensemble import ExtraTreesClassifier\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score\nfrom sklearn import svm\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.neighbors  import KNeighborsClassifier","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-16T00:01:02.865348Z","iopub.execute_input":"2022-07-16T00:01:02.866126Z","iopub.status.idle":"2022-07-16T00:01:03.562413Z","shell.execute_reply.started":"2022-07-16T00:01:02.866054Z","shell.execute_reply":"2022-07-16T00:01:03.560986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Reading the training and the testing data**","metadata":{"execution":{"iopub.status.busy":"2022-07-15T23:13:58.036942Z","iopub.execute_input":"2022-07-15T23:13:58.037452Z","iopub.status.idle":"2022-07-15T23:13:58.043171Z","shell.execute_reply.started":"2022-07-15T23:13:58.037399Z","shell.execute_reply":"2022-07-15T23:13:58.041905Z"}}},{"cell_type":"code","source":"train= pd.read_csv(\"../input/titanic/train.csv\")\npred=pd.read_csv(\"../input/titanic/test.csv\", header=0)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:06.656081Z","iopub.execute_input":"2022-07-16T00:01:06.657331Z","iopub.status.idle":"2022-07-16T00:01:06.679861Z","shell.execute_reply.started":"2022-07-16T00:01:06.657264Z","shell.execute_reply":"2022-07-16T00:01:06.678028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# **Displaying the top 10 data in training and testing data**","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:08.192239Z","iopub.execute_input":"2022-07-16T00:01:08.192697Z","iopub.status.idle":"2022-07-16T00:01:08.219884Z","shell.execute_reply.started":"2022-07-16T00:01:08.192663Z","shell.execute_reply":"2022-07-16T00:01:08.218300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:08.404299Z","iopub.execute_input":"2022-07-16T00:01:08.404978Z","iopub.status.idle":"2022-07-16T00:01:08.424834Z","shell.execute_reply.started":"2022-07-16T00:01:08.404941Z","shell.execute_reply":"2022-07-16T00:01:08.423152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#number of rows in test and train\nprint(\"Number of rows in Train dataset: \",train.shape[0], \" Number of rows in Test dataset: \", pred.shape[0])","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:08.571731Z","iopub.execute_input":"2022-07-16T00:01:08.572194Z","iopub.status.idle":"2022-07-16T00:01:08.579078Z","shell.execute_reply.started":"2022-07-16T00:01:08.572156Z","shell.execute_reply":"2022-07-16T00:01:08.577680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#number of columns in test and train\nprint(\"Number of columns in Train dataset: \",pred.shape[1], \" Number of columns in Test dataset: \", pred.shape[1])","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:09.043314Z","iopub.execute_input":"2022-07-16T00:01:09.044771Z","iopub.status.idle":"2022-07-16T00:01:09.051789Z","shell.execute_reply.started":"2022-07-16T00:01:09.044723Z","shell.execute_reply":"2022-07-16T00:01:09.050359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#info in train\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:09.241934Z","iopub.execute_input":"2022-07-16T00:01:09.243147Z","iopub.status.idle":"2022-07-16T00:01:09.259980Z","shell.execute_reply.started":"2022-07-16T00:01:09.243089Z","shell.execute_reply":"2022-07-16T00:01:09.258729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Decribe the train\ntrain.describe(include=\"all\")","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:09.439525Z","iopub.execute_input":"2022-07-16T00:01:09.440198Z","iopub.status.idle":"2022-07-16T00:01:09.488689Z","shell.execute_reply.started":"2022-07-16T00:01:09.440163Z","shell.execute_reply":"2022-07-16T00:01:09.487427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Cleaning the dataset:**\n1.     Removing the Null values\n2.     Dropping the unwanted columns\n3.     Adding New columns if needed\n4.     Formatting the columns","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"#to find the percentage of null:\ndef percentagenull(df):\n    percentage= ((df.isna().sum()/df.isna().count())*100).sort_values(ascending=False)\n    count= df.isna().sum().sort_values(ascending=False)\n    dfff= pd.concat([count, percentage], axis=1,keys=['the Count', 'Percentage of null'])\n    return dfff\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:10.223819Z","iopub.execute_input":"2022-07-16T00:01:10.224262Z","iopub.status.idle":"2022-07-16T00:01:10.232059Z","shell.execute_reply.started":"2022-07-16T00:01:10.224229Z","shell.execute_reply":"2022-07-16T00:01:10.230416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"percentagenull(train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:10.842639Z","iopub.execute_input":"2022-07-16T00:01:10.843745Z","iopub.status.idle":"2022-07-16T00:01:10.868748Z","shell.execute_reply.started":"2022-07-16T00:01:10.843697Z","shell.execute_reply":"2022-07-16T00:01:10.866983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"percentagenull(pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:11.027099Z","iopub.execute_input":"2022-07-16T00:01:11.027536Z","iopub.status.idle":"2022-07-16T00:01:11.049252Z","shell.execute_reply.started":"2022-07-16T00:01:11.027504Z","shell.execute_reply":"2022-07-16T00:01:11.047657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dropping the column cabin because it has more percentage of null and the cabin can be found from the fare rate and pclass\ntrain.drop('Cabin', axis=1, inplace=True)\npred.drop('Cabin', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:11.215804Z","iopub.execute_input":"2022-07-16T00:01:11.216291Z","iopub.status.idle":"2022-07-16T00:01:11.225013Z","shell.execute_reply.started":"2022-07-16T00:01:11.216255Z","shell.execute_reply":"2022-07-16T00:01:11.223641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#fill up or replace the null in the age with the mean of age\ntrain[\"Age\"].replace(np.nan, train[\"Age\"].mean(), inplace=True)\ntrain[\"Age\"].isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:11.400736Z","iopub.execute_input":"2022-07-16T00:01:11.401189Z","iopub.status.idle":"2022-07-16T00:01:11.412407Z","shell.execute_reply.started":"2022-07-16T00:01:11.401155Z","shell.execute_reply":"2022-07-16T00:01:11.411078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#replace or fill the Embarkment with the mode\ntrain[\"Embarked\"].replace(np.nan, train.Embarked.mode()[0], inplace=True)\ntrain[\"Embarked\"].isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:11.576680Z","iopub.execute_input":"2022-07-16T00:01:11.577154Z","iopub.status.idle":"2022-07-16T00:01:11.590121Z","shell.execute_reply.started":"2022-07-16T00:01:11.577117Z","shell.execute_reply":"2022-07-16T00:01:11.588579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred[\"Embarked\"].replace(np.nan, pred.Embarked.mode()[0], inplace=True)\npred[\"Age\"].replace(np.nan, pred[\"Age\"].mean(), inplace=True)\npred[\"Fare\"].replace(np.nan, pred[\"Fare\"].mean(),inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:11.786166Z","iopub.execute_input":"2022-07-16T00:01:11.786617Z","iopub.status.idle":"2022-07-16T00:01:11.796351Z","shell.execute_reply.started":"2022-07-16T00:01:11.786581Z","shell.execute_reply":"2022-07-16T00:01:11.795330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:12.109975Z","iopub.execute_input":"2022-07-16T00:01:12.111020Z","iopub.status.idle":"2022-07-16T00:01:12.122651Z","shell.execute_reply.started":"2022-07-16T00:01:12.110977Z","shell.execute_reply":"2022-07-16T00:01:12.121666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Dropping the Ticket and Name because both has no recurring pattern\ntrain.drop(['Ticket','Name'], axis=1, inplace=True)\npred.drop(['Ticket','Name'], axis=1, inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:12.325498Z","iopub.execute_input":"2022-07-16T00:01:12.325958Z","iopub.status.idle":"2022-07-16T00:01:12.334336Z","shell.execute_reply.started":"2022-07-16T00:01:12.325922Z","shell.execute_reply":"2022-07-16T00:01:12.333089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Simple visualization of Sex and the Survival count**","metadata":{}},{"cell_type":"code","source":"dd=train[['Sex', 'Survived']].groupby(['Survived'], as_index=False).count()\ndd.plot(kind='bar',figsize=(10, 5))\nplt.xlabel(\"Sex\")\nplt.ylabel(\"Survived\")\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:12.902520Z","iopub.execute_input":"2022-07-16T00:01:12.903036Z","iopub.status.idle":"2022-07-16T00:01:13.137256Z","shell.execute_reply.started":"2022-07-16T00:01:12.902997Z","shell.execute_reply":"2022-07-16T00:01:13.135913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#formating the columns sex and embarked\ntrain=pd.get_dummies(train, prefix=[\"Sex\",\"Embarked\"])\npred=pd.get_dummies(pred, prefix=[\"Sex\",\"Embarked\"])\n","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:13.169483Z","iopub.execute_input":"2022-07-16T00:01:13.169948Z","iopub.status.idle":"2022-07-16T00:01:13.190852Z","shell.execute_reply.started":"2022-07-16T00:01:13.169911Z","shell.execute_reply":"2022-07-16T00:01:13.189304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Adding a new column Relatives**","metadata":{"execution":{"iopub.status.busy":"2022-07-15T23:29:53.251356Z","iopub.execute_input":"2022-07-15T23:29:53.251860Z","iopub.status.idle":"2022-07-15T23:29:53.274625Z","shell.execute_reply.started":"2022-07-15T23:29:53.251820Z","shell.execute_reply":"2022-07-15T23:29:53.273592Z"}}},{"cell_type":"code","source":"# combining the SibSp and Parch together into one relative column and dropping the two columns\ndef merges(df):\n    relatives=[]\n    for i in df[\"SibSp\"].values.tolist():\n        relatives.append(i)\n    relatives1=[]\n    for i in df[\"Parch\"].values.tolist():\n        relatives1.append(i)    \n    re=[]\n\n    for i in range(0, len(relatives)):\n        re.append(relatives[i]+relatives1[i])  \n    df1=pd.DataFrame(re, columns=['Relatives'])   \n    df= pd.concat([df, df1], axis=1)\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:14.198117Z","iopub.execute_input":"2022-07-16T00:01:14.198517Z","iopub.status.idle":"2022-07-16T00:01:14.207506Z","shell.execute_reply.started":"2022-07-16T00:01:14.198487Z","shell.execute_reply":"2022-07-16T00:01:14.206409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=merges(train)\ntrain.drop(['SibSp','Parch'], axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:14.891955Z","iopub.execute_input":"2022-07-16T00:01:14.892887Z","iopub.status.idle":"2022-07-16T00:01:14.904506Z","shell.execute_reply.started":"2022-07-16T00:01:14.892829Z","shell.execute_reply":"2022-07-16T00:01:14.903253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:15.331165Z","iopub.execute_input":"2022-07-16T00:01:15.332374Z","iopub.status.idle":"2022-07-16T00:01:15.352756Z","shell.execute_reply.started":"2022-07-16T00:01:15.332313Z","shell.execute_reply":"2022-07-16T00:01:15.351016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=merges(pred)\npred.drop(['SibSp','Parch'], axis=1, inplace=True)\npred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:15.621566Z","iopub.execute_input":"2022-07-16T00:01:15.622093Z","iopub.status.idle":"2022-07-16T00:01:15.646818Z","shell.execute_reply.started":"2022-07-16T00:01:15.622054Z","shell.execute_reply":"2022-07-16T00:01:15.645432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Feature Importance:**\n1.     Using the ExtraTreeClassifier feature importance\n2.     Using heatmap to detect the correlaion between features","metadata":{}},{"cell_type":"code","source":"x=train.drop('Survived', axis=1)\ny=train['Survived']","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:16.270613Z","iopub.execute_input":"2022-07-16T00:01:16.271103Z","iopub.status.idle":"2022-07-16T00:01:16.280332Z","shell.execute_reply.started":"2022-07-16T00:01:16.271066Z","shell.execute_reply":"2022-07-16T00:01:16.279007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=ExtraTreesClassifier()\nmodel.fit(x,y)\nprint(model.feature_importances_)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:16.484849Z","iopub.execute_input":"2022-07-16T00:01:16.486295Z","iopub.status.idle":"2022-07-16T00:01:16.692740Z","shell.execute_reply.started":"2022-07-16T00:01:16.486236Z","shell.execute_reply":"2022-07-16T00:01:16.691367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fi=pd.Series(model.feature_importances_, index=x.columns)\nfi.plot(kind=\"barh\")","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:16.694460Z","iopub.execute_input":"2022-07-16T00:01:16.694812Z","iopub.status.idle":"2022-07-16T00:01:16.951852Z","shell.execute_reply.started":"2022-07-16T00:01:16.694776Z","shell.execute_reply":"2022-07-16T00:01:16.950001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#heatmap for the corelation\nplt.figure(figsize=(40,15))\nsns.heatmap(train.corr(), annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:16.954722Z","iopub.execute_input":"2022-07-16T00:01:16.956067Z","iopub.status.idle":"2022-07-16T00:01:17.901856Z","shell.execute_reply.started":"2022-07-16T00:01:16.955984Z","shell.execute_reply":"2022-07-16T00:01:17.900553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.regplot(train['PassengerId'], train['Survived'], data=train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:17.904284Z","iopub.execute_input":"2022-07-16T00:01:17.905373Z","iopub.status.idle":"2022-07-16T00:01:18.271907Z","shell.execute_reply.started":"2022-07-16T00:01:17.905324Z","shell.execute_reply":"2022-07-16T00:01:18.270237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Dropping passengerId as we can see the correlation of passengerId is near to zero with respect to Survived\ntrain.drop('PassengerId', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:18.274207Z","iopub.execute_input":"2022-07-16T00:01:18.275047Z","iopub.status.idle":"2022-07-16T00:01:18.282225Z","shell.execute_reply.started":"2022-07-16T00:01:18.274982Z","shell.execute_reply":"2022-07-16T00:01:18.281165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Preprocessing the data**","metadata":{}},{"cell_type":"code","source":"X_train, X_test, y_train, y_test= train_test_split(x, y, test_size=20, random_state=1)\nX_train=StandardScaler().fit_transform(X_train)\nX_test=StandardScaler().fit_transform(X_test)\npred=StandardScaler().fit_transform(pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:18.883157Z","iopub.execute_input":"2022-07-16T00:01:18.883803Z","iopub.status.idle":"2022-07-16T00:01:18.908367Z","shell.execute_reply.started":"2022-07-16T00:01:18.883754Z","shell.execute_reply":"2022-07-16T00:01:18.906448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Logistic Regression:**","metadata":{}},{"cell_type":"code","source":"lr = LogisticRegression()\nparams = { \"penalty\": (\"l1\", \"l2\", \"elasticnet\"), \"tol\": (0.1, 0.01, 0.001, 0.0001), \"C\": (10.0, 1.0, 0.1, 0.01)}\nmodelLR = GridSearchCV(lr, params, cv=10)\nmodelLR.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:19.486553Z","iopub.execute_input":"2022-07-16T00:01:19.487329Z","iopub.status.idle":"2022-07-16T00:01:20.799647Z","shell.execute_reply.started":"2022-07-16T00:01:19.487288Z","shell.execute_reply":"2022-07-16T00:01:20.798225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelLR.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:20.801803Z","iopub.execute_input":"2022-07-16T00:01:20.802148Z","iopub.status.idle":"2022-07-16T00:01:20.809461Z","shell.execute_reply.started":"2022-07-16T00:01:20.802119Z","shell.execute_reply":"2022-07-16T00:01:20.808092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **SVM:**","metadata":{}},{"cell_type":"code","source":"modelSVM=svm.SVC(kernel='rbf')\nmodelSVM.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:21.531476Z","iopub.execute_input":"2022-07-16T00:01:21.531941Z","iopub.status.idle":"2022-07-16T00:01:21.571270Z","shell.execute_reply.started":"2022-07-16T00:01:21.531906Z","shell.execute_reply":"2022-07-16T00:01:21.569505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelSVM.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:21.748687Z","iopub.execute_input":"2022-07-16T00:01:21.749524Z","iopub.status.idle":"2022-07-16T00:01:21.758058Z","shell.execute_reply.started":"2022-07-16T00:01:21.749462Z","shell.execute_reply":"2022-07-16T00:01:21.756642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Decision Tree Classifier**","metadata":{}},{"cell_type":"code","source":"modelDTC=DecisionTreeClassifier(criterion=\"entropy\")\nmodelDTC.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:22.287745Z","iopub.execute_input":"2022-07-16T00:01:22.288588Z","iopub.status.idle":"2022-07-16T00:01:22.305517Z","shell.execute_reply.started":"2022-07-16T00:01:22.288544Z","shell.execute_reply":"2022-07-16T00:01:22.303539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(modelDTC.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:22.579202Z","iopub.execute_input":"2022-07-16T00:01:22.579635Z","iopub.status.idle":"2022-07-16T00:01:22.587390Z","shell.execute_reply.started":"2022-07-16T00:01:22.579601Z","shell.execute_reply":"2022-07-16T00:01:22.585922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **KNeighborsClassifier**","metadata":{}},{"cell_type":"code","source":"n=KNeighborsClassifier(n_neighbors=4)\nn.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:23.907219Z","iopub.execute_input":"2022-07-16T00:01:23.907964Z","iopub.status.idle":"2022-07-16T00:01:23.918432Z","shell.execute_reply.started":"2022-07-16T00:01:23.907925Z","shell.execute_reply":"2022-07-16T00:01:23.917449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(accuracy_score(n.predict(X_test),y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:24.899944Z","iopub.execute_input":"2022-07-16T00:01:24.901555Z","iopub.status.idle":"2022-07-16T00:01:24.912355Z","shell.execute_reply.started":"2022-07-16T00:01:24.901491Z","shell.execute_reply":"2022-07-16T00:01:24.910964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"report = pd.DataFrame({\n    \"Model\" : [\"Logistic Regression:\", \"SVM\", \"Decision Tree Classifier\", \"KNeighborsClassifier\"],\n    \"Accuracy score\" : [accuracy_score(modelLR.predict(X_test),y_test), accuracy_score(modelSVM.predict(X_test),y_test),accuracy_score(modelDTC.predict(X_test),y_test),accuracy_score(n.predict(X_test),y_test)]\n})\nreport.sort_values(by = \"Accuracy score\")","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:25.675422Z","iopub.execute_input":"2022-07-16T00:01:25.676594Z","iopub.status.idle":"2022-07-16T00:01:25.697797Z","shell.execute_reply.started":"2022-07-16T00:01:25.676545Z","shell.execute_reply":"2022-07-16T00:01:25.696294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Prediction using Logistic Regression:**","metadata":{}},{"cell_type":"code","source":"prediction= modelLR.predict(pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:51.318051Z","iopub.execute_input":"2022-07-16T00:01:51.318529Z","iopub.status.idle":"2022-07-16T00:01:51.325603Z","shell.execute_reply.started":"2022-07-16T00:01:51.318498Z","shell.execute_reply":"2022-07-16T00:01:51.324605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:54.076457Z","iopub.execute_input":"2022-07-16T00:01:54.077266Z","iopub.status.idle":"2022-07-16T00:01:54.086392Z","shell.execute_reply.started":"2022-07-16T00:01:54.077210Z","shell.execute_reply":"2022-07-16T00:01:54.085229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred1=pd.read_csv('../input/titanic/test.csv')\nsub=pd.DataFrame({'PassengerID': pred1[\"PassengerId\"], 'Survived': prediction})","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:56.362611Z","iopub.execute_input":"2022-07-16T00:01:56.364169Z","iopub.status.idle":"2022-07-16T00:01:56.378512Z","shell.execute_reply.started":"2022-07-16T00:01:56.364106Z","shell.execute_reply":"2022-07-16T00:01:56.377439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:57.041260Z","iopub.execute_input":"2022-07-16T00:01:57.042090Z","iopub.status.idle":"2022-07-16T00:01:57.057996Z","shell.execute_reply.started":"2022-07-16T00:01:57.042027Z","shell.execute_reply":"2022-07-16T00:01:57.056565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-16T00:01:58.358622Z","iopub.execute_input":"2022-07-16T00:01:58.359516Z","iopub.status.idle":"2022-07-16T00:01:58.369502Z","shell.execute_reply.started":"2022-07-16T00:01:58.359473Z","shell.execute_reply":"2022-07-16T00:01:58.368178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **THANK YOU SO MUCH FOR VIEWING MY NOTEBOOK. YOUR FEEDBACK IS MORE IMPORTANT FOR MY IMPROVEMENT!**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}}]}