{"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)\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-13T06:35:53.464485Z","iopub.execute_input":"2022-08-13T06:35:53.465103Z","iopub.status.idle":"2022-08-13T06:35:53.481114Z","shell.execute_reply.started":"2022-08-13T06:35:53.464972Z","shell.execute_reply":"2022-08-13T06:35:53.479795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/titanic/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:24.939528Z","iopub.execute_input":"2022-08-13T06:37:24.940010Z","iopub.status.idle":"2022-08-13T06:37:24.953429Z","shell.execute_reply.started":"2022-08-13T06:37:24.939970Z","shell.execute_reply":"2022-08-13T06:37:24.952357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:26.888901Z","iopub.execute_input":"2022-08-13T06:37:26.889577Z","iopub.status.idle":"2022-08-13T06:37:26.912813Z","shell.execute_reply.started":"2022-08-13T06:37:26.889539Z","shell.execute_reply":"2022-08-13T06:37:26.911486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:36:10.794508Z","iopub.execute_input":"2022-08-13T06:36:10.795023Z","iopub.status.idle":"2022-08-13T06:36:10.803984Z","shell.execute_reply.started":"2022-08-13T06:36:10.794980Z","shell.execute_reply":"2022-08-13T06:36:10.802401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- We can't use name and ticket its different for everyone so we have to drop them","metadata":{}},{"cell_type":"code","source":"df.drop(columns=[\"Name\", \"Ticket\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:34.194352Z","iopub.execute_input":"2022-08-13T06:37:34.194788Z","iopub.status.idle":"2022-08-13T06:37:34.202361Z","shell.execute_reply.started":"2022-08-13T06:37:34.194755Z","shell.execute_reply":"2022-08-13T06:37:34.201106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:36.278773Z","iopub.execute_input":"2022-08-13T06:37:36.279844Z","iopub.status.idle":"2022-08-13T06:37:36.300741Z","shell.execute_reply.started":"2022-08-13T06:37:36.279800Z","shell.execute_reply":"2022-08-13T06:37:36.299624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- lets take cabin out for now later on we will deal with missing values of cabin","metadata":{}},{"cell_type":"code","source":"# droping  missing record from embarked\ndf.dropna(subset=[\"Embarked\"], axis=0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:46.751172Z","iopub.execute_input":"2022-08-13T06:37:46.751604Z","iopub.status.idle":"2022-08-13T06:37:46.760371Z","shell.execute_reply.started":"2022-08-13T06:37:46.751571Z","shell.execute_reply":"2022-08-13T06:37:46.759121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(df[\"Embarked\"].isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:37:49.218569Z","iopub.execute_input":"2022-08-13T06:37:49.219595Z","iopub.status.idle":"2022-08-13T06:37:49.228404Z","shell.execute_reply.started":"2022-08-13T06:37:49.219547Z","shell.execute_reply":"2022-08-13T06:37:49.227253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabindf=  df[\"Cabin\"]\ndf.drop(columns=[\"Cabin\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:04.779995Z","iopub.execute_input":"2022-08-13T06:40:04.780522Z","iopub.status.idle":"2022-08-13T06:40:04.788217Z","shell.execute_reply.started":"2022-08-13T06:40:04.780481Z","shell.execute_reply":"2022-08-13T06:40:04.786765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabindf","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:13.509816Z","iopub.execute_input":"2022-08-13T06:40:13.510289Z","iopub.status.idle":"2022-08-13T06:40:13.521788Z","shell.execute_reply.started":"2022-08-13T06:40:13.510252Z","shell.execute_reply":"2022-08-13T06:40:13.520537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(df[\"Age\"][df[\"Sex\"]==\"male\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:19.628964Z","iopub.execute_input":"2022-08-13T06:40:19.629746Z","iopub.status.idle":"2022-08-13T06:40:19.640325Z","shell.execute_reply.started":"2022-08-13T06:40:19.629704Z","shell.execute_reply":"2022-08-13T06:40:19.638913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(df[\"Age\"][df[\"Sex\"]==\"female\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:21.698861Z","iopub.execute_input":"2022-08-13T06:40:21.699346Z","iopub.status.idle":"2022-08-13T06:40:21.708117Z","shell.execute_reply.started":"2022-08-13T06:40:21.699308Z","shell.execute_reply":"2022-08-13T06:40:21.707214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- in age replacing all male missing values with mean of male and female with mean of female","metadata":{}},{"cell_type":"code","source":"df[\"Age\"] = np.where((df[\"Sex\"]=='male') & (df[\"Age\"].isna()), 30, df[\"Age\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:27.139914Z","iopub.execute_input":"2022-08-13T06:40:27.140803Z","iopub.status.idle":"2022-08-13T06:40:27.148420Z","shell.execute_reply.started":"2022-08-13T06:40:27.140748Z","shell.execute_reply":"2022-08-13T06:40:27.147298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"Age\"] = np.where((df[\"Sex\"]=='female') & (df[\"Age\"].isna()), 27, df[\"Age\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:29.038861Z","iopub.execute_input":"2022-08-13T06:40:29.039297Z","iopub.status.idle":"2022-08-13T06:40:29.047098Z","shell.execute_reply.started":"2022-08-13T06:40:29.039265Z","shell.execute_reply":"2022-08-13T06:40:29.045780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(df[\"Age\"].isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:31.738717Z","iopub.execute_input":"2022-08-13T06:40:31.739177Z","iopub.status.idle":"2022-08-13T06:40:31.746459Z","shell.execute_reply.started":"2022-08-13T06:40:31.739139Z","shell.execute_reply":"2022-08-13T06:40:31.745652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- droping passenger id caz it dont provide any useful information to our model\n\n","metadata":{}},{"cell_type":"code","source":"df.drop(columns=[\"PassengerId\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:44.299533Z","iopub.execute_input":"2022-08-13T06:40:44.300030Z","iopub.status.idle":"2022-08-13T06:40:44.307023Z","shell.execute_reply.started":"2022-08-13T06:40:44.299991Z","shell.execute_reply":"2022-08-13T06:40:44.305950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- setting male = 0 and female = 1 ","metadata":{}},{"cell_type":"code","source":"df.loc[df[\"Sex\"]==\"male\", \"Sex\"] = 0\ndf.loc[df[\"Sex\"]==\"female\", \"Sex\"] = 1","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:47.248645Z","iopub.execute_input":"2022-08-13T06:40:47.249656Z","iopub.status.idle":"2022-08-13T06:40:47.257518Z","shell.execute_reply.started":"2022-08-13T06:40:47.249613Z","shell.execute_reply":"2022-08-13T06:40:47.256295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"Sex\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:50.988501Z","iopub.execute_input":"2022-08-13T06:40:50.989677Z","iopub.status.idle":"2022-08-13T06:40:51.006038Z","shell.execute_reply.started":"2022-08-13T06:40:50.989623Z","shell.execute_reply":"2022-08-13T06:40:51.005000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- setting q , c, s = 3, 2, 1 in embarkment ","metadata":{}},{"cell_type":"code","source":"df.loc[df[\"Embarked\"] == \"Q\", \"Embarked\"]=3\ndf.loc[df[\"Embarked\"] == \"C\", \"Embarked\"]=2\ndf.loc[df[\"Embarked\"] == \"S\", \"Embarked\"]=1","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:55.978804Z","iopub.execute_input":"2022-08-13T06:40:55.979255Z","iopub.status.idle":"2022-08-13T06:40:55.988787Z","shell.execute_reply.started":"2022-08-13T06:40:55.979220Z","shell.execute_reply":"2022-08-13T06:40:55.987370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"Embarked\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:40:58.089068Z","iopub.execute_input":"2022-08-13T06:40:58.089928Z","iopub.status.idle":"2022-08-13T06:40:58.098730Z","shell.execute_reply.started":"2022-08-13T06:40:58.089884Z","shell.execute_reply":"2022-08-13T06:40:58.097515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Now lets create a model to pretict cabin missing values","metadata":{}},{"cell_type":"code","source":"df[\"Cabin\"] = cabindf","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:41:06.999616Z","iopub.execute_input":"2022-08-13T06:41:07.000044Z","iopub.status.idle":"2022-08-13T06:41:07.006402Z","shell.execute_reply.started":"2022-08-13T06:41:07.000007Z","shell.execute_reply":"2022-08-13T06:41:07.005023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"not_null_index = df[df[\"Cabin\"].notnull()].index","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:41:10.258408Z","iopub.execute_input":"2022-08-13T06:41:10.259412Z","iopub.status.idle":"2022-08-13T06:41:10.267088Z","shell.execute_reply.started":"2022-08-13T06:41:10.259370Z","shell.execute_reply":"2022-08-13T06:41:10.266106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = list(not_null_index)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:41:17.988741Z","iopub.execute_input":"2022-08-13T06:41:17.989216Z","iopub.status.idle":"2022-08-13T06:41:17.994829Z","shell.execute_reply.started":"2022-08-13T06:41:17.989175Z","shell.execute_reply":"2022-08-13T06:41:17.993890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"survived = df[\"Survived\"]\nlen(survived)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:43:19.849154Z","iopub.execute_input":"2022-08-13T06:43:19.849626Z","iopub.status.idle":"2022-08-13T06:43:19.857041Z","shell.execute_reply.started":"2022-08-13T06:43:19.849585Z","shell.execute_reply":"2022-08-13T06:43:19.856080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(survived.isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:43:46.204726Z","iopub.execute_input":"2022-08-13T06:43:46.206200Z","iopub.status.idle":"2022-08-13T06:43:46.215748Z","shell.execute_reply.started":"2022-08-13T06:43:46.206155Z","shell.execute_reply":"2022-08-13T06:43:46.214408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:42:18.748431Z","iopub.execute_input":"2022-08-13T06:42:18.748841Z","iopub.status.idle":"2022-08-13T06:42:18.756273Z","shell.execute_reply.started":"2022-08-13T06:42:18.748811Z","shell.execute_reply":"2022-08-13T06:42:18.754981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_df = df.drop(columns=[\"Survived\"])\nnew_df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:43:59.734257Z","iopub.execute_input":"2022-08-13T06:43:59.734674Z","iopub.status.idle":"2022-08-13T06:43:59.758537Z","shell.execute_reply.started":"2022-08-13T06:43:59.734642Z","shell.execute_reply":"2022-08-13T06:43:59.757458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_train = new_df.loc[index]\ncabin_train","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:07.414554Z","iopub.execute_input":"2022-08-13T06:44:07.415054Z","iopub.status.idle":"2022-08-13T06:44:07.440120Z","shell.execute_reply.started":"2022-08-13T06:44:07.415007Z","shell.execute_reply":"2022-08-13T06:44:07.438672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_x = cabin_train.drop(columns=[\"Cabin\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:20.833844Z","iopub.execute_input":"2022-08-13T06:44:20.834610Z","iopub.status.idle":"2022-08-13T06:44:20.842301Z","shell.execute_reply.started":"2022-08-13T06:44:20.834565Z","shell.execute_reply":"2022-08-13T06:44:20.840849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_y = cabin_train[\"Cabin\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:24.083725Z","iopub.execute_input":"2022-08-13T06:44:24.085276Z","iopub.status.idle":"2022-08-13T06:44:24.091419Z","shell.execute_reply.started":"2022-08-13T06:44:24.085215Z","shell.execute_reply":"2022-08-13T06:44:24.090033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import Ridge, Lasso, ElasticNet, RidgeCV, LassoCV, ElasticNetCV, LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:30.039347Z","iopub.execute_input":"2022-08-13T06:44:30.039819Z","iopub.status.idle":"2022-08-13T06:44:30.451294Z","shell.execute_reply.started":"2022-08-13T06:44:30.039778Z","shell.execute_reply":"2022-08-13T06:44:30.449646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lg = LogisticRegression(max_iter=1000)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:32.803698Z","iopub.execute_input":"2022-08-13T06:44:32.804174Z","iopub.status.idle":"2022-08-13T06:44:32.810477Z","shell.execute_reply.started":"2022-08-13T06:44:32.804133Z","shell.execute_reply":"2022-08-13T06:44:32.808973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lg.fit(cabin_x, cabin_y)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:41.324454Z","iopub.execute_input":"2022-08-13T06:44:41.325255Z","iopub.status.idle":"2022-08-13T06:44:42.630813Z","shell.execute_reply.started":"2022-08-13T06:44:41.325208Z","shell.execute_reply":"2022-08-13T06:44:42.629676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_test = new_df.drop(index=not_null_index)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:44:54.394356Z","iopub.execute_input":"2022-08-13T06:44:54.394832Z","iopub.status.idle":"2022-08-13T06:44:54.401602Z","shell.execute_reply.started":"2022-08-13T06:44:54.394791Z","shell.execute_reply":"2022-08-13T06:44:54.400263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_test.drop(columns=[\"Cabin\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:45:12.009628Z","iopub.execute_input":"2022-08-13T06:45:12.010548Z","iopub.status.idle":"2022-08-13T06:45:12.018768Z","shell.execute_reply.started":"2022-08-13T06:45:12.010495Z","shell.execute_reply":"2022-08-13T06:45:12.016998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_pred = lg.predict(cabin_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:45:16.263770Z","iopub.execute_input":"2022-08-13T06:45:16.264271Z","iopub.status.idle":"2022-08-13T06:45:16.274730Z","shell.execute_reply.started":"2022-08-13T06:45:16.264231Z","shell.execute_reply":"2022-08-13T06:45:16.272983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:45:18.533890Z","iopub.execute_input":"2022-08-13T06:45:18.534358Z","iopub.status.idle":"2022-08-13T06:45:18.543922Z","shell.execute_reply.started":"2022-08-13T06:45:18.534313Z","shell.execute_reply":"2022-08-13T06:45:18.542965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_test[\"Cabin\"] = cabin_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:45:31.604584Z","iopub.execute_input":"2022-08-13T06:45:31.605109Z","iopub.status.idle":"2022-08-13T06:45:31.611586Z","shell.execute_reply.started":"2022-08-13T06:45:31.605063Z","shell.execute_reply":"2022-08-13T06:45:31.610158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_train","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:46:02.409473Z","iopub.execute_input":"2022-08-13T06:46:02.409948Z","iopub.status.idle":"2022-08-13T06:46:02.434223Z","shell.execute_reply.started":"2022-08-13T06:46:02.409911Z","shell.execute_reply":"2022-08-13T06:46:02.433011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_test.isnull()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:46:09.949555Z","iopub.execute_input":"2022-08-13T06:46:09.950108Z","iopub.status.idle":"2022-08-13T06:46:09.975880Z","shell.execute_reply.started":"2022-08-13T06:46:09.950056Z","shell.execute_reply":"2022-08-13T06:46:09.974633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_frame = pd.concat([cabin_train, cabin_test])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:46:21.728763Z","iopub.execute_input":"2022-08-13T06:46:21.729282Z","iopub.status.idle":"2022-08-13T06:46:21.739812Z","shell.execute_reply.started":"2022-08-13T06:46:21.729234Z","shell.execute_reply":"2022-08-13T06:46:21.738802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_frame[\"Survived\"] = survived\ndata_frame","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:47:06.709448Z","iopub.execute_input":"2022-08-13T06:47:06.709918Z","iopub.status.idle":"2022-08-13T06:47:06.735074Z","shell.execute_reply.started":"2022-08-13T06:47:06.709880Z","shell.execute_reply":"2022-08-13T06:47:06.733837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_frame.reset_index(drop=True, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:47:24.619494Z","iopub.execute_input":"2022-08-13T06:47:24.619995Z","iopub.status.idle":"2022-08-13T06:47:24.626652Z","shell.execute_reply.started":"2022-08-13T06:47:24.619945Z","shell.execute_reply":"2022-08-13T06:47:24.625625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(data_frame[\"Survived\"].isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:02.350004Z","iopub.execute_input":"2022-08-13T06:48:02.350448Z","iopub.status.idle":"2022-08-13T06:48:02.358717Z","shell.execute_reply.started":"2022-08-13T06:48:02.350414Z","shell.execute_reply":"2022-08-13T06:48:02.357416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = data_frame\ndf","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:10.079382Z","iopub.execute_input":"2022-08-13T06:48:10.079857Z","iopub.status.idle":"2022-08-13T06:48:10.106396Z","shell.execute_reply.started":"2022-08-13T06:48:10.079816Z","shell.execute_reply":"2022-08-13T06:48:10.105053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Outliers removal","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nfig, ax = plt.subplots(figsize=(10, 10))\nsns.boxplot(data=df, ax= ax, width=1.0)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:16.639831Z","iopub.execute_input":"2022-08-13T06:48:16.640319Z","iopub.status.idle":"2022-08-13T06:48:17.024319Z","shell.execute_reply.started":"2022-08-13T06:48:16.640280Z","shell.execute_reply":"2022-08-13T06:48:17.021171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q = df[\"Fare\"].quantile(.82)\nnew_df = df[df[\"Fare\"]<q]\n\nq = new_df[\"Age\"].quantile(.05)\nnew_df = new_df[new_df[\"Age\"]>q]\n\nq = new_df[\"Age\"].quantile(.89)\nnew_df = new_df[new_df[\"Age\"]<q]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:22.828704Z","iopub.execute_input":"2022-08-13T06:48:22.829580Z","iopub.status.idle":"2022-08-13T06:48:22.841738Z","shell.execute_reply.started":"2022-08-13T06:48:22.829539Z","shell.execute_reply":"2022-08-13T06:48:22.840614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 10))\nsns.boxplot(data=new_df, ax= ax, width=1.0)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:27.108910Z","iopub.execute_input":"2022-08-13T06:48:27.109565Z","iopub.status.idle":"2022-08-13T06:48:27.389566Z","shell.execute_reply.started":"2022-08-13T06:48:27.109528Z","shell.execute_reply":"2022-08-13T06:48:27.388184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:34.561753Z","iopub.execute_input":"2022-08-13T06:48:34.562226Z","iopub.status.idle":"2022-08-13T06:48:34.568713Z","shell.execute_reply.started":"2022-08-13T06:48:34.562189Z","shell.execute_reply":"2022-08-13T06:48:34.567721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"Parch\"].max()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:37.103989Z","iopub.execute_input":"2022-08-13T06:48:37.104422Z","iopub.status.idle":"2022-08-13T06:48:37.112047Z","shell.execute_reply.started":"2022-08-13T06:48:37.104384Z","shell.execute_reply":"2022-08-13T06:48:37.110746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:43.239471Z","iopub.execute_input":"2022-08-13T06:48:43.239948Z","iopub.status.idle":"2022-08-13T06:48:43.249206Z","shell.execute_reply.started":"2022-08-13T06:48:43.239908Z","shell.execute_reply":"2022-08-13T06:48:43.247801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = new_df.drop(columns=[\"Survived\"])\ny = new_df[\"Survived\"]\nx","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:45.618508Z","iopub.execute_input":"2022-08-13T06:48:45.619000Z","iopub.status.idle":"2022-08-13T06:48:45.644737Z","shell.execute_reply.started":"2022-08-13T06:48:45.618961Z","shell.execute_reply":"2022-08-13T06:48:45.643487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import Ridge, Lasso, ElasticNet, RidgeCV, LassoCV, ElasticNetCV, LogisticRegression\n","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:55.549715Z","iopub.execute_input":"2022-08-13T06:48:55.550153Z","iopub.status.idle":"2022-08-13T06:48:55.555376Z","shell.execute_reply.started":"2022-08-13T06:48:55.550108Z","shell.execute_reply":"2022-08-13T06:48:55.554337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class LogisticRegressionWithThreshold(LogisticRegression):\n    def predict(self, X, threshold=None):\n        if threshold == None: # If no threshold passed in, simply call the base class predict, effectively threshold=0.5\n            return LogisticRegression.predict(self, X)\n        else:\n            y_proba = LogisticRegression.predict_proba(self, X)[:,1]\n            y_pred_with_threshold = (y_proba >= threshold).astype(int)\n            \n            return y_pred_with_threshold","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:48:58.148768Z","iopub.execute_input":"2022-08-13T06:48:58.149210Z","iopub.status.idle":"2022-08-13T06:48:58.156594Z","shell.execute_reply.started":"2022-08-13T06:48:58.149176Z","shell.execute_reply":"2022-08-13T06:48:58.155364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_frequency_map =  x[\"Cabin\"].value_counts().to_dict()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:03.228530Z","iopub.execute_input":"2022-08-13T06:49:03.229504Z","iopub.status.idle":"2022-08-13T06:49:03.236159Z","shell.execute_reply.started":"2022-08-13T06:49:03.229453Z","shell.execute_reply":"2022-08-13T06:49:03.234773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.Cabin = x.Cabin.map(cabin_frequency_map)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:05.799978Z","iopub.execute_input":"2022-08-13T06:49:05.801069Z","iopub.status.idle":"2022-08-13T06:49:05.807341Z","shell.execute_reply.started":"2022-08-13T06:49:05.801029Z","shell.execute_reply":"2022-08-13T06:49:05.805915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(y.isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:15.569296Z","iopub.execute_input":"2022-08-13T06:49:15.569722Z","iopub.status.idle":"2022-08-13T06:49:15.576643Z","shell.execute_reply.started":"2022-08-13T06:49:15.569690Z","shell.execute_reply":"2022-08-13T06:49:15.575689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgr = LogisticRegression(C=1.623776739188721, max_iter=1000, solver='liblinear')\nlgr.fit(x, y)\ny_pred1 = lgr.predict(x)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:20.728431Z","iopub.execute_input":"2022-08-13T06:49:20.728846Z","iopub.status.idle":"2022-08-13T06:49:20.743513Z","shell.execute_reply.started":"2022-08-13T06:49:20.728813Z","shell.execute_reply":"2022-08-13T06:49:20.742413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgr2 = LogisticRegressionWithThreshold( max_iter=1000)\nlgr2.fit(x, y)\ny_pred2 = lgr2.predict(x, 0.40)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:24.348569Z","iopub.execute_input":"2022-08-13T06:49:24.349002Z","iopub.status.idle":"2022-08-13T06:49:24.422079Z","shell.execute_reply.started":"2022-08-13T06:49:24.348965Z","shell.execute_reply":"2022-08-13T06:49:24.420936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, confusion_matrix, roc_curve, roc_auc_score\ntp, fn, fp, tn = confusion_matrix(y, y_pred1).ravel()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:29.609228Z","iopub.execute_input":"2022-08-13T06:49:29.609700Z","iopub.status.idle":"2022-08-13T06:49:29.617353Z","shell.execute_reply.started":"2022-08-13T06:49:29.609662Z","shell.execute_reply":"2022-08-13T06:49:29.616279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall = tp/(tp+fn)\nrecall","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:31.583630Z","iopub.execute_input":"2022-08-13T06:49:31.584777Z","iopub.status.idle":"2022-08-13T06:49:31.591614Z","shell.execute_reply.started":"2022-08-13T06:49:31.584725Z","shell.execute_reply":"2022-08-13T06:49:31.590161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"precision = tp/(tp+fp)\nprecision","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:34.294130Z","iopub.execute_input":"2022-08-13T06:49:34.294980Z","iopub.status.idle":"2022-08-13T06:49:34.303906Z","shell.execute_reply.started":"2022-08-13T06:49:34.294926Z","shell.execute_reply":"2022-08-13T06:49:34.302614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = (tp+tn)/(tp+fp+fn+tn)\nacc","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:37.623464Z","iopub.execute_input":"2022-08-13T06:49:37.624307Z","iopub.status.idle":"2022-08-13T06:49:37.631804Z","shell.execute_reply.started":"2022-08-13T06:49:37.624262Z","shell.execute_reply":"2022-08-13T06:49:37.630594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tp2, fn2, fp2, tn2 = confusion_matrix(y, y_pred2).ravel()\nrecall2 = tp2/(tp2+fn2)\nprecision2 = tp2/(tp2+fp2)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:44.075303Z","iopub.execute_input":"2022-08-13T06:49:44.076362Z","iopub.status.idle":"2022-08-13T06:49:44.083587Z","shell.execute_reply.started":"2022-08-13T06:49:44.076317Z","shell.execute_reply":"2022-08-13T06:49:44.082227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall2","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:49.750996Z","iopub.execute_input":"2022-08-13T06:49:49.751497Z","iopub.status.idle":"2022-08-13T06:49:49.758740Z","shell.execute_reply.started":"2022-08-13T06:49:49.751436Z","shell.execute_reply":"2022-08-13T06:49:49.757819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"precision2","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:52.118720Z","iopub.execute_input":"2022-08-13T06:49:52.119183Z","iopub.status.idle":"2022-08-13T06:49:52.126667Z","shell.execute_reply.started":"2022-08-13T06:49:52.119142Z","shell.execute_reply":"2022-08-13T06:49:52.125401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = (tp2+tn2)/(tp2+tn2+fp2+fn2)\naccuracy","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:49:56.994441Z","iopub.execute_input":"2022-08-13T06:49:56.994921Z","iopub.status.idle":"2022-08-13T06:49:57.002765Z","shell.execute_reply.started":"2022-08-13T06:49:56.994880Z","shell.execute_reply":"2022-08-13T06:49:57.001571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_multiple_roc_curve(Y_test, model_probs, model_probs2):\n\n    # calculate ROC Curve\n    model_fpr, model_tpr, _ = roc_curve(Y_test, model_probs)\n    model_fpr2, model_tpr2, _= roc_curve(Y_test, model_probs2) \n    \n    # Plot the roc curve for the model and the random model line\n\n    plt.plot(model_fpr, model_tpr, marker='.', label='Model, th=0.50')\n    plt.plot(model_fpr2, model_tpr2, marker='.', label='Model2, th=0.40')\n    # Create labels for the axis\n    plt.xlabel('False Positive Rate')\n    plt.ylabel('True Positive Rate')\n    # show the legend\n    plt.legend()\n    # show the plot\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:38.519213Z","iopub.execute_input":"2022-08-13T06:50:38.519629Z","iopub.status.idle":"2022-08-13T06:50:38.526958Z","shell.execute_reply.started":"2022-08-13T06:50:38.519595Z","shell.execute_reply":"2022-08-13T06:50:38.525946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_multiple_roc_curve(y, y_pred1, y_pred2)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:39.373410Z","iopub.execute_input":"2022-08-13T06:50:39.374557Z","iopub.status.idle":"2022-08-13T06:50:39.534711Z","shell.execute_reply.started":"2022-08-13T06:50:39.374514Z","shell.execute_reply":"2022-08-13T06:50:39.533344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test = pd.read_csv(\"../input/titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:44.663562Z","iopub.execute_input":"2022-08-13T06:50:44.664044Z","iopub.status.idle":"2022-08-13T06:50:44.673381Z","shell.execute_reply.started":"2022-08-13T06:50:44.664004Z","shell.execute_reply":"2022-08-13T06:50:44.672418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:46.794086Z","iopub.execute_input":"2022-08-13T06:50:46.794944Z","iopub.status.idle":"2022-08-13T06:50:46.822332Z","shell.execute_reply.started":"2022-08-13T06:50:46.794890Z","shell.execute_reply":"2022-08-13T06:50:46.821080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test.drop(columns=[\"Name\", \"Ticket\"], inplace=True)\nx_test.dropna(subset=[\"Embarked\"], axis=0, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:52.693694Z","iopub.execute_input":"2022-08-13T06:50:52.694226Z","iopub.status.idle":"2022-08-13T06:50:52.704029Z","shell.execute_reply.started":"2022-08-13T06:50:52.694185Z","shell.execute_reply":"2022-08-13T06:50:52.702777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_cabin = x_test[\"Cabin\"]\ntest_cabin","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:50:55.958523Z","iopub.execute_input":"2022-08-13T06:50:55.959014Z","iopub.status.idle":"2022-08-13T06:50:55.967984Z","shell.execute_reply.started":"2022-08-13T06:50:55.958972Z","shell.execute_reply":"2022-08-13T06:50:55.966976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test.drop(columns=[\"Cabin\"], inplace=True)\nx_test[\"Age\"] = np.where((x_test[\"Sex\"]=='male') & (x_test[\"Age\"].isna()), np.mean(x_test[\"Age\"][x_test[\"Sex\"]==\"male\"]), x_test[\"Age\"])\nx_test[\"Age\"] = np.where((x_test[\"Sex\"]=='female') & (x_test[\"Age\"].isna()), np.mean(x_test[\"Age\"][x_test[\"Sex\"]==\"female\"]), x_test[\"Age\"])\nx_test.loc[x_test[\"Sex\"] == \"male\", \"Sex\"]=0\nx_test.loc[x_test[\"Sex\"] == \"female\", \"Sex\"]=1\nx_test.loc[x_test[\"Embarked\"] == \"Q\", \"Embarked\"]=3\nx_test.loc[x_test[\"Embarked\"] == \"C\", \"Embarked\"]=2\nx_test.loc[x_test[\"Embarked\"] == \"S\", \"Embarked\"]=1","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:06.250044Z","iopub.execute_input":"2022-08-13T06:51:06.250492Z","iopub.status.idle":"2022-08-13T06:51:06.268238Z","shell.execute_reply.started":"2022-08-13T06:51:06.250453Z","shell.execute_reply":"2022-08-13T06:51:06.266668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test.columns","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:08.138438Z","iopub.execute_input":"2022-08-13T06:51:08.138915Z","iopub.status.idle":"2022-08-13T06:51:08.147607Z","shell.execute_reply.started":"2022-08-13T06:51:08.138851Z","shell.execute_reply":"2022-08-13T06:51:08.146209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(x_test[\"Fare\"].isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:13.499134Z","iopub.execute_input":"2022-08-13T06:51:13.500260Z","iopub.status.idle":"2022-08-13T06:51:13.508152Z","shell.execute_reply.started":"2022-08-13T06:51:13.500216Z","shell.execute_reply":"2022-08-13T06:51:13.507056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test[\"Fare\"].fillna(35, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:17.198972Z","iopub.execute_input":"2022-08-13T06:51:17.199860Z","iopub.status.idle":"2022-08-13T06:51:17.205768Z","shell.execute_reply.started":"2022-08-13T06:51:17.199816Z","shell.execute_reply":"2022-08-13T06:51:17.204602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(x_test[\"Fare\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:23.649637Z","iopub.execute_input":"2022-08-13T06:51:23.650120Z","iopub.status.idle":"2022-08-13T06:51:23.659678Z","shell.execute_reply.started":"2022-08-13T06:51:23.650079Z","shell.execute_reply":"2022-08-13T06:51:23.657806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"any(x_test[\"Fare\"].isnull())","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:27.038807Z","iopub.execute_input":"2022-08-13T06:51:27.040306Z","iopub.status.idle":"2022-08-13T06:51:27.048709Z","shell.execute_reply.started":"2022-08-13T06:51:27.040253Z","shell.execute_reply":"2022-08-13T06:51:27.047136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test_passID = x_test[\"PassengerId\"]\nx_test_passID ","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:33.360861Z","iopub.execute_input":"2022-08-13T06:51:33.361339Z","iopub.status.idle":"2022-08-13T06:51:33.371224Z","shell.execute_reply.started":"2022-08-13T06:51:33.361302Z","shell.execute_reply":"2022-08-13T06:51:33.369937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test.drop(columns=[\"PassengerId\"], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:39.750202Z","iopub.execute_input":"2022-08-13T06:51:39.751634Z","iopub.status.idle":"2022-08-13T06:51:39.759065Z","shell.execute_reply.started":"2022-08-13T06:51:39.751574Z","shell.execute_reply":"2022-08-13T06:51:39.757518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:41.698640Z","iopub.execute_input":"2022-08-13T06:51:41.699464Z","iopub.status.idle":"2022-08-13T06:51:41.720193Z","shell.execute_reply.started":"2022-08-13T06:51:41.699413Z","shell.execute_reply":"2022-08-13T06:51:41.718860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_cabin_pred = lg.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:51:52.758924Z","iopub.execute_input":"2022-08-13T06:51:52.760038Z","iopub.status.idle":"2022-08-13T06:51:52.769259Z","shell.execute_reply.started":"2022-08-13T06:51:52.759989Z","shell.execute_reply":"2022-08-13T06:51:52.767697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_cabin_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:52:05.259739Z","iopub.execute_input":"2022-08-13T06:52:05.260897Z","iopub.status.idle":"2022-08-13T06:52:05.268767Z","shell.execute_reply.started":"2022-08-13T06:52:05.260838Z","shell.execute_reply":"2022-08-13T06:52:05.267761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test[\"Cabin\"] = test_cabin_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:53:09.484272Z","iopub.execute_input":"2022-08-13T06:53:09.484707Z","iopub.status.idle":"2022-08-13T06:53:09.491459Z","shell.execute_reply.started":"2022-08-13T06:53:09.484671Z","shell.execute_reply":"2022-08-13T06:53:09.490026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:53:18.643773Z","iopub.execute_input":"2022-08-13T06:53:18.644233Z","iopub.status.idle":"2022-08-13T06:53:18.668034Z","shell.execute_reply.started":"2022-08-13T06:53:18.644196Z","shell.execute_reply":"2022-08-13T06:53:18.666591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_frequency_map2 =  x_test[\"Cabin\"].value_counts().to_dict()\nx_test.Cabin = x_test.Cabin.map(cabin_frequency_map2)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:55:22.368734Z","iopub.execute_input":"2022-08-13T06:55:22.369244Z","iopub.status.idle":"2022-08-13T06:55:22.378833Z","shell.execute_reply.started":"2022-08-13T06:55:22.369207Z","shell.execute_reply":"2022-08-13T06:55:22.377657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_pred = lgr2.predict(x_test, 0.66)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T10:27:24.975979Z","iopub.execute_input":"2022-08-14T10:27:24.976983Z","iopub.status.idle":"2022-08-14T10:27:24.994448Z","shell.execute_reply.started":"2022-08-14T10:27:24.976919Z","shell.execute_reply":"2022-08-14T10:27:24.992773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_pred","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:58:07.793560Z","iopub.execute_input":"2022-08-13T06:58:07.794027Z","iopub.status.idle":"2022-08-13T06:58:07.803300Z","shell.execute_reply.started":"2022-08-13T06:58:07.793983Z","shell.execute_reply":"2022-08-13T06:58:07.802323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Survived = pd.Series(y_test_pred)\nSurvived.rename(\"Survived\")\nPassengerId = x_test_passID\nPassengerId.rename(\"PassengerId\")\nsubmition_df = pd.concat([PassengerId, Survived], axis=1)\nsubmition_df.rename(columns={0:\"Survived\"}, inplace=True)\nsubmition_df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:55:47.079539Z","iopub.execute_input":"2022-08-13T06:55:47.080005Z","iopub.status.idle":"2022-08-13T06:55:47.098570Z","shell.execute_reply.started":"2022-08-13T06:55:47.079969Z","shell.execute_reply":"2022-08-13T06:55:47.097114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"backup_df = submition_df\nbackup_df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:55:52.348919Z","iopub.execute_input":"2022-08-13T06:55:52.349391Z","iopub.status.idle":"2022-08-13T06:55:52.362959Z","shell.execute_reply.started":"2022-08-13T06:55:52.349350Z","shell.execute_reply":"2022-08-13T06:55:52.361622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submition_df.set_index(\"PassengerId\", inplace=True, drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:55:57.648772Z","iopub.execute_input":"2022-08-13T06:55:57.649735Z","iopub.status.idle":"2022-08-13T06:55:57.655787Z","shell.execute_reply.started":"2022-08-13T06:55:57.649685Z","shell.execute_reply":"2022-08-13T06:55:57.654290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submition_df","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:55:59.438703Z","iopub.execute_input":"2022-08-13T06:55:59.439170Z","iopub.status.idle":"2022-08-13T06:55:59.453170Z","shell.execute_reply.started":"2022-08-13T06:55:59.439134Z","shell.execute_reply":"2022-08-13T06:55:59.452003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submition_df.to_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-13T06:56:05.044118Z","iopub.execute_input":"2022-08-13T06:56:05.044556Z","iopub.status.idle":"2022-08-13T06:56:05.053526Z","shell.execute_reply.started":"2022-08-13T06:56:05.044522Z","shell.execute_reply":"2022-08-13T06:56:05.052309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}