{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nfrom matplotlib import style\nimport seaborn as sns\n\nfrom sklearn.metrics import accuracy_score, confusion_matrix, classification_report, plot_confusion_matrix, precision_score, recall_score\n\nfrom sklearn.preprocessing import StandardScaler\n\nfrom sklearn.linear_model import LogisticRegression\n\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-09T14:33:41.959207Z","iopub.execute_input":"2022-08-09T14:33:41.959832Z","iopub.status.idle":"2022-08-09T14:33:42.883597Z","shell.execute_reply.started":"2022-08-09T14:33:41.959715Z","shell.execute_reply":"2022-08-09T14:33:42.882551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#importing input data\ntrain = pd.read_csv('../input/titanic/train.csv')\n\ntest = pd.read_csv('../input/titanic/test.csv') \n\nval = pd.read_csv('../input/titanic/gender_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:42.885928Z","iopub.execute_input":"2022-08-09T14:33:42.886725Z","iopub.status.idle":"2022-08-09T14:33:42.925307Z","shell.execute_reply.started":"2022-08-09T14:33:42.886675Z","shell.execute_reply":"2022-08-09T14:33:42.924315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:42.926741Z","iopub.execute_input":"2022-08-09T14:33:42.927607Z","iopub.status.idle":"2022-08-09T14:33:42.964916Z","shell.execute_reply.started":"2022-08-09T14:33:42.927571Z","shell.execute_reply":"2022-08-09T14:33:42.963899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:42.966765Z","iopub.execute_input":"2022-08-09T14:33:42.967302Z","iopub.status.idle":"2022-08-09T14:33:42.993015Z","shell.execute_reply.started":"2022-08-09T14:33:42.967268Z","shell.execute_reply":"2022-08-09T14:33:42.991819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Survived'] = val['Survived']","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:43.138546Z","iopub.execute_input":"2022-08-09T14:33:43.138949Z","iopub.status.idle":"2022-08-09T14:33:43.151251Z","shell.execute_reply.started":"2022-08-09T14:33:43.138918Z","shell.execute_reply":"2022-08-09T14:33:43.149506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:43.410895Z","iopub.execute_input":"2022-08-09T14:33:43.411929Z","iopub.status.idle":"2022-08-09T14:33:43.443995Z","shell.execute_reply.started":"2022-08-09T14:33:43.411888Z","shell.execute_reply":"2022-08-09T14:33:43.441756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#DATA PREP\ntrain.isnull().sum()#finding the missing values ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:43.817034Z","iopub.execute_input":"2022-08-09T14:33:43.818276Z","iopub.status.idle":"2022-08-09T14:33:43.829303Z","shell.execute_reply.started":"2022-08-09T14:33:43.818229Z","shell.execute_reply":"2022-08-09T14:33:43.828499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train= train.dropna(axis=0, subset=['Embarked']) #dropped the whole row as the percent of its low, so dropping them ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:44.184044Z","iopub.execute_input":"2022-08-09T14:33:44.184731Z","iopub.status.idle":"2022-08-09T14:33:44.195768Z","shell.execute_reply.started":"2022-08-09T14:33:44.184693Z","shell.execute_reply":"2022-08-09T14:33:44.193981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:44.406090Z","iopub.execute_input":"2022-08-09T14:33:44.407338Z","iopub.status.idle":"2022-08-09T14:33:44.418772Z","shell.execute_reply.started":"2022-08-09T14:33:44.407291Z","shell.execute_reply":"2022-08-09T14:33:44.417295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Age'] = train['Age'].fillna(train['Age'].median()) #taking the median values of age ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:44.632198Z","iopub.execute_input":"2022-08-09T14:33:44.633506Z","iopub.status.idle":"2022-08-09T14:33:44.650914Z","shell.execute_reply.started":"2022-08-09T14:33:44.633454Z","shell.execute_reply":"2022-08-09T14:33:44.649465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train.drop(['Cabin'], axis=1) ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:44.849597Z","iopub.execute_input":"2022-08-09T14:33:44.850301Z","iopub.status.idle":"2022-08-09T14:33:44.856261Z","shell.execute_reply.started":"2022-08-09T14:33:44.850265Z","shell.execute_reply":"2022-08-09T14:33:44.855215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:45.096274Z","iopub.execute_input":"2022-08-09T14:33:45.096801Z","iopub.status.idle":"2022-08-09T14:33:45.108958Z","shell.execute_reply.started":"2022-08-09T14:33:45.096760Z","shell.execute_reply":"2022-08-09T14:33:45.107435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we see no missing value is left ","metadata":{}},{"cell_type":"code","source":"train.drop(['Name','Ticket'], axis = 1, inplace=True) #As Name and ticket are useless","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:45.287499Z","iopub.execute_input":"2022-08-09T14:33:45.288307Z","iopub.status.idle":"2022-08-09T14:33:45.295547Z","shell.execute_reply.started":"2022-08-09T14:33:45.288263Z","shell.execute_reply":"2022-08-09T14:33:45.294424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:45.490986Z","iopub.execute_input":"2022-08-09T14:33:45.491572Z","iopub.status.idle":"2022-08-09T14:33:45.516049Z","shell.execute_reply.started":"2022-08-09T14:33:45.491527Z","shell.execute_reply":"2022-08-09T14:33:45.514916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Test data Preprocessing\ntest.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:45.694344Z","iopub.execute_input":"2022-08-09T14:33:45.695506Z","iopub.status.idle":"2022-08-09T14:33:45.708067Z","shell.execute_reply.started":"2022-08-09T14:33:45.695457Z","shell.execute_reply":"2022-08-09T14:33:45.706855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Fare'] = test['Fare'].fillna(test['Fare'].median()) #as for the test we can not drop any ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:45.876126Z","iopub.execute_input":"2022-08-09T14:33:45.877394Z","iopub.status.idle":"2022-08-09T14:33:45.884627Z","shell.execute_reply.started":"2022-08-09T14:33:45.877327Z","shell.execute_reply":"2022-08-09T14:33:45.883159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Age'] =test['Age'].fillna(test['Age'].median())","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.060707Z","iopub.execute_input":"2022-08-09T14:33:46.061217Z","iopub.status.idle":"2022-08-09T14:33:46.069544Z","shell.execute_reply.started":"2022-08-09T14:33:46.061176Z","shell.execute_reply":"2022-08-09T14:33:46.068468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=test.drop(['Cabin'], axis=1) # as for the train we have done it, and we want to do the same for the test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.253949Z","iopub.execute_input":"2022-08-09T14:33:46.254398Z","iopub.status.idle":"2022-08-09T14:33:46.263348Z","shell.execute_reply.started":"2022-08-09T14:33:46.254345Z","shell.execute_reply":"2022-08-09T14:33:46.261664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.drop(['Name','Ticket'], axis = 1, inplace=True) #As Name and ticket are useless\ntest","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.442801Z","iopub.execute_input":"2022-08-09T14:33:46.444391Z","iopub.status.idle":"2022-08-09T14:33:46.471420Z","shell.execute_reply.started":"2022-08-09T14:33:46.444315Z","shell.execute_reply":"2022-08-09T14:33:46.470094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.633665Z","iopub.execute_input":"2022-08-09T14:33:46.635153Z","iopub.status.idle":"2022-08-09T14:33:46.657899Z","shell.execute_reply.started":"2022-08-09T14:33:46.635097Z","shell.execute_reply":"2022-08-09T14:33:46.656902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Preparing for dummy variable\ntrain[\"Embarked\"].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.791068Z","iopub.execute_input":"2022-08-09T14:33:46.791918Z","iopub.status.idle":"2022-08-09T14:33:46.800707Z","shell.execute_reply.started":"2022-08-09T14:33:46.791876Z","shell.execute_reply":"2022-08-09T14:33:46.799468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Survived'] = train['Survived'].apply(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:46.964286Z","iopub.execute_input":"2022-08-09T14:33:46.964755Z","iopub.status.idle":"2022-08-09T14:33:46.974032Z","shell.execute_reply.started":"2022-08-09T14:33:46.964718Z","shell.execute_reply":"2022-08-09T14:33:46.972416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Pclass'] = train['Pclass'].apply(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.101206Z","iopub.execute_input":"2022-08-09T14:33:47.101717Z","iopub.status.idle":"2022-08-09T14:33:47.109329Z","shell.execute_reply.started":"2022-08-09T14:33:47.101678Z","shell.execute_reply":"2022-08-09T14:33:47.107935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.251621Z","iopub.execute_input":"2022-08-09T14:33:47.252533Z","iopub.status.idle":"2022-08-09T14:33:47.283168Z","shell.execute_reply.started":"2022-08-09T14:33:47.252484Z","shell.execute_reply":"2022-08-09T14:33:47.281944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_train = pd.get_dummies(train,columns=[\"Sex\"])\nfinal_train.drop('Sex_female', axis = 1, inplace=True)\nfinal_train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.400817Z","iopub.execute_input":"2022-08-09T14:33:47.401898Z","iopub.status.idle":"2022-08-09T14:33:47.434870Z","shell.execute_reply.started":"2022-08-09T14:33:47.401854Z","shell.execute_reply":"2022-08-09T14:33:47.433729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_train = pd.get_dummies(final_train,columns=[\"Pclass\"])\nfinal_train.drop('Pclass_1', axis = 1, inplace=True)\nfinal_train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.559208Z","iopub.execute_input":"2022-08-09T14:33:47.560458Z","iopub.status.idle":"2022-08-09T14:33:47.597511Z","shell.execute_reply.started":"2022-08-09T14:33:47.560353Z","shell.execute_reply":"2022-08-09T14:33:47.596542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_train = pd.get_dummies(final_train,columns=[\"Embarked\"])\nfinal_train.drop('Embarked_C', axis = 1, inplace=True)\nfinal_train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.698834Z","iopub.execute_input":"2022-08-09T14:33:47.699564Z","iopub.status.idle":"2022-08-09T14:33:47.730244Z","shell.execute_reply.started":"2022-08-09T14:33:47.699516Z","shell.execute_reply":"2022-08-09T14:33:47.728949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k = final_train.pop(\"Survived\")","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.807534Z","iopub.execute_input":"2022-08-09T14:33:47.807950Z","iopub.status.idle":"2022-08-09T14:33:47.816193Z","shell.execute_reply.started":"2022-08-09T14:33:47.807916Z","shell.execute_reply":"2022-08-09T14:33:47.812768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = k\nprint(y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:47.925586Z","iopub.execute_input":"2022-08-09T14:33:47.927774Z","iopub.status.idle":"2022-08-09T14:33:47.935924Z","shell.execute_reply.started":"2022-08-09T14:33:47.927720Z","shell.execute_reply":"2022-08-09T14:33:47.934718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.040307Z","iopub.execute_input":"2022-08-09T14:33:48.041514Z","iopub.status.idle":"2022-08-09T14:33:48.051470Z","shell.execute_reply.started":"2022-08-09T14:33:48.041465Z","shell.execute_reply":"2022-08-09T14:33:48.049312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.169047Z","iopub.execute_input":"2022-08-09T14:33:48.170056Z","iopub.status.idle":"2022-08-09T14:33:48.196540Z","shell.execute_reply.started":"2022-08-09T14:33:48.170014Z","shell.execute_reply":"2022-08-09T14:33:48.194752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Survived'] = test['Survived'].apply(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.274351Z","iopub.execute_input":"2022-08-09T14:33:48.275367Z","iopub.status.idle":"2022-08-09T14:33:48.282750Z","shell.execute_reply.started":"2022-08-09T14:33:48.275329Z","shell.execute_reply":"2022-08-09T14:33:48.281271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['Pclass'] = test['Pclass'].apply(str)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.366323Z","iopub.execute_input":"2022-08-09T14:33:48.367742Z","iopub.status.idle":"2022-08-09T14:33:48.374719Z","shell.execute_reply.started":"2022-08-09T14:33:48.367693Z","shell.execute_reply":"2022-08-09T14:33:48.373322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_test = pd.get_dummies(test,columns=[\"Sex\"])\nfinal_test.drop('Sex_female', axis = 1, inplace=True)\nfinal_test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.470555Z","iopub.execute_input":"2022-08-09T14:33:48.471365Z","iopub.status.idle":"2022-08-09T14:33:48.507101Z","shell.execute_reply.started":"2022-08-09T14:33:48.471325Z","shell.execute_reply":"2022-08-09T14:33:48.505662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_test = pd.get_dummies(final_test,columns=[\"Pclass\"])\nfinal_test.drop('Pclass_1', axis = 1, inplace=True)\nfinal_test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.658089Z","iopub.execute_input":"2022-08-09T14:33:48.658600Z","iopub.status.idle":"2022-08-09T14:33:48.694049Z","shell.execute_reply.started":"2022-08-09T14:33:48.658552Z","shell.execute_reply":"2022-08-09T14:33:48.692738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_test = pd.get_dummies(final_test,columns=[\"Embarked\"])\nfinal_test.drop('Embarked_C', axis = 1, inplace=True)\nfinal_test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.794095Z","iopub.execute_input":"2022-08-09T14:33:48.795466Z","iopub.status.idle":"2022-08-09T14:33:48.825336Z","shell.execute_reply.started":"2022-08-09T14:33:48.795417Z","shell.execute_reply":"2022-08-09T14:33:48.824457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test = final_test.pop(\"Survived\")","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.917998Z","iopub.execute_input":"2022-08-09T14:33:48.919230Z","iopub.status.idle":"2022-08-09T14:33:48.926006Z","shell.execute_reply.started":"2022-08-09T14:33:48.919187Z","shell.execute_reply":"2022-08-09T14:33:48.924484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:48.970993Z","iopub.execute_input":"2022-08-09T14:33:48.971783Z","iopub.status.idle":"2022-08-09T14:33:48.979398Z","shell.execute_reply.started":"2022-08-09T14:33:48.971738Z","shell.execute_reply":"2022-08-09T14:33:48.977840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_train","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.051011Z","iopub.execute_input":"2022-08-09T14:33:49.052300Z","iopub.status.idle":"2022-08-09T14:33:49.073913Z","shell.execute_reply.started":"2022-08-09T14:33:49.052261Z","shell.execute_reply":"2022-08-09T14:33:49.072479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_test","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.134334Z","iopub.execute_input":"2022-08-09T14:33:49.134845Z","iopub.status.idle":"2022-08-09T14:33:49.161255Z","shell.execute_reply.started":"2022-08-09T14:33:49.134807Z","shell.execute_reply":"2022-08-09T14:33:49.159786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler= StandardScaler()\n\nscaler.fit(final_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.201550Z","iopub.execute_input":"2022-08-09T14:33:49.202027Z","iopub.status.idle":"2022-08-09T14:33:49.214635Z","shell.execute_reply.started":"2022-08-09T14:33:49.201993Z","shell.execute_reply":"2022-08-09T14:33:49.213729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Logistic_model = LogisticRegression(max_iter=4000)\n\nLogistic_model.fit(final_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.271042Z","iopub.execute_input":"2022-08-09T14:33:49.271575Z","iopub.status.idle":"2022-08-09T14:33:49.386833Z","shell.execute_reply.started":"2022-08-09T14:33:49.271536Z","shell.execute_reply":"2022-08-09T14:33:49.385477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred =  Logistic_model.predict(final_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.389590Z","iopub.execute_input":"2022-08-09T14:33:49.390915Z","iopub.status.idle":"2022-08-09T14:33:49.401817Z","shell.execute_reply.started":"2022-08-09T14:33:49.390847Z","shell.execute_reply":"2022-08-09T14:33:49.400019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.403649Z","iopub.execute_input":"2022-08-09T14:33:49.404328Z","iopub.status.idle":"2022-08-09T14:33:49.416849Z","shell.execute_reply.started":"2022-08-09T14:33:49.404290Z","shell.execute_reply":"2022-08-09T14:33:49.415246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nrf = RandomForestClassifier(n_estimators=2, random_state=0)\nrf.fit(final_train, y_train)\nRF_pred = rf.predict(final_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.429644Z","iopub.execute_input":"2022-08-09T14:33:49.430174Z","iopub.status.idle":"2022-08-09T14:33:49.617011Z","shell.execute_reply.started":"2022-08-09T14:33:49.430135Z","shell.execute_reply":"2022-08-09T14:33:49.615432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,RF_pred)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.619299Z","iopub.execute_input":"2022-08-09T14:33:49.619778Z","iopub.status.idle":"2022-08-09T14:33:49.630235Z","shell.execute_reply.started":"2022-08-09T14:33:49.619740Z","shell.execute_reply":"2022-08-09T14:33:49.628954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame()\nsubmission['PassengerId'] = test['PassengerId']\nsubmission['Survived'] = y_pred\nsubmission.to_csv('GettingStartedWithtitanicmodel.csv',index=False)\nprint(\"Submission was successfully saved!\")","metadata":{"execution":{"iopub.status.busy":"2022-08-09T14:33:49.631927Z","iopub.execute_input":"2022-08-09T14:33:49.632847Z","iopub.status.idle":"2022-08-09T14:33:49.654856Z","shell.execute_reply.started":"2022-08-09T14:33:49.632787Z","shell.execute_reply":"2022-08-09T14:33:49.653475Z"},"trusted":true},"execution_count":null,"outputs":[]}]}