{"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-07-20T04:05:31.022819Z","iopub.execute_input":"2022-07-20T04:05:31.023449Z","iopub.status.idle":"2022-07-20T04:05:31.056413Z","shell.execute_reply.started":"2022-07-20T04:05:31.023356Z","shell.execute_reply":"2022-07-20T04:05:31.055515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train=pd.read_csv(\"../input/titanic/train.csv\")\ndata_test=pd.read_csv(\"../input/titanic/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.057933Z","iopub.execute_input":"2022-07-20T04:05:31.058433Z","iopub.status.idle":"2022-07-20T04:05:31.088332Z","shell.execute_reply.started":"2022-07-20T04:05:31.058402Z","shell.execute_reply":"2022-07-20T04:05:31.087360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.090229Z","iopub.execute_input":"2022-07-20T04:05:31.091511Z","iopub.status.idle":"2022-07-20T04:05:31.120163Z","shell.execute_reply.started":"2022-07-20T04:05:31.091456Z","shell.execute_reply":"2022-07-20T04:05:31.118833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**EDA**\n* Handling missing value\n* Data visualization and exploration\n* Feature Transformation\n* Feature Engeeneering","metadata":{}},{"cell_type":"markdown","source":"**Handling missing value**","metadata":{}},{"cell_type":"code","source":"data_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.140045Z","iopub.execute_input":"2022-07-20T04:05:31.140424Z","iopub.status.idle":"2022-07-20T04:05:31.151400Z","shell.execute_reply.started":"2022-07-20T04:05:31.140393Z","shell.execute_reply":"2022-07-20T04:05:31.150358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.181195Z","iopub.execute_input":"2022-07-20T04:05:31.182030Z","iopub.status.idle":"2022-07-20T04:05:31.192880Z","shell.execute_reply.started":"2022-07-20T04:05:31.181989Z","shell.execute_reply":"2022-07-20T04:05:31.191721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1. Those column that has less than 4 missing value should be removed\n2. Age should be replaced by average age\n3. Cabing -->most frequent","metadata":{}},{"cell_type":"code","source":"def deleteMissingRow(dataset,name):\n    #dataset=dataset[~dataset[name].isna()]\n    return dataset.dropna(subset=[name],how='all')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.220273Z","iopub.execute_input":"2022-07-20T04:05:31.221178Z","iopub.status.idle":"2022-07-20T04:05:31.227385Z","shell.execute_reply.started":"2022-07-20T04:05:31.221123Z","shell.execute_reply":"2022-07-20T04:05:31.226189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train=deleteMissingRow(data_train,'Embarked')\ndata_test=deleteMissingRow(data_test,'Fare')\ndata_test.isnull().sum()\ndata_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.248233Z","iopub.execute_input":"2022-07-20T04:05:31.248619Z","iopub.status.idle":"2022-07-20T04:05:31.271149Z","shell.execute_reply.started":"2022-07-20T04:05:31.248562Z","shell.execute_reply":"2022-07-20T04:05:31.269929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def replwithMean(dataset,name):\n    m=dataset[name].mean()\n    dataset[name]=dataset[name].fillna(m)\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.273801Z","iopub.execute_input":"2022-07-20T04:05:31.274272Z","iopub.status.idle":"2022-07-20T04:05:31.280036Z","shell.execute_reply.started":"2022-07-20T04:05:31.274225Z","shell.execute_reply":"2022-07-20T04:05:31.278642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"replwithMean(data_train,'Age')\nreplwithMean(data_test,'Age')\ndata_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.301941Z","iopub.execute_input":"2022-07-20T04:05:31.302632Z","iopub.status.idle":"2022-07-20T04:05:31.316349Z","shell.execute_reply.started":"2022-07-20T04:05:31.302581Z","shell.execute_reply":"2022-07-20T04:05:31.314819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import SimpleImputer\nimputer=SimpleImputer(strategy='most_frequent')\ndata_train[\"Cabin\"]=imputer.fit_transform(data_train.iloc[:,10:11])","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:31.336836Z","iopub.execute_input":"2022-07-20T04:05:31.337361Z","iopub.status.idle":"2022-07-20T04:05:32.609658Z","shell.execute_reply.started":"2022-07-20T04:05:31.337313Z","shell.execute_reply":"2022-07-20T04:05:32.608246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def replaceWithMostFreq(dataset,name):\n    most_freq=dataset[name].value_counts().idxmax()\n    dataset[name]=dataset[name].fillna(most_freq)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.611695Z","iopub.execute_input":"2022-07-20T04:05:32.612042Z","iopub.status.idle":"2022-07-20T04:05:32.618229Z","shell.execute_reply.started":"2022-07-20T04:05:32.612011Z","shell.execute_reply":"2022-07-20T04:05:32.616816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"replaceWithMostFreq(data_test,'Cabin')\ndata_test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.619817Z","iopub.execute_input":"2022-07-20T04:05:32.620171Z","iopub.status.idle":"2022-07-20T04:05:32.636887Z","shell.execute_reply.started":"2022-07-20T04:05:32.620142Z","shell.execute_reply":"2022-07-20T04:05:32.635865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data Visualisation and Exploration**","metadata":{}},{"cell_type":"code","source":"data_train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.639267Z","iopub.execute_input":"2022-07-20T04:05:32.639818Z","iopub.status.idle":"2022-07-20T04:05:32.680048Z","shell.execute_reply.started":"2022-07-20T04:05:32.639782Z","shell.execute_reply":"2022-07-20T04:05:32.678873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1. Number of Survived by Gender ?\n2. Does The Survival rate depends on Port of Embarkation,number of siblings,Travel Alone ?\n3. Categorize per age \"<15\",\"15-30\",\"30-45\",\"45-60\",\">60\" then plot in pie plot the distribution of age and then Find which group of age has the most rate of survival ?","metadata":{}},{"cell_type":"code","source":"data_train.groupby('Sex').Survived.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.681451Z","iopub.execute_input":"2022-07-20T04:05:32.681840Z","iopub.status.idle":"2022-07-20T04:05:32.695376Z","shell.execute_reply.started":"2022-07-20T04:05:32.681808Z","shell.execute_reply":"2022-07-20T04:05:32.694109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":">  female survived are double than the male that survived ","metadata":{}},{"cell_type":"code","source":"data_train.groupby('Sex').Survived.value_counts().plot(kind='barh')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.697467Z","iopub.execute_input":"2022-07-20T04:05:32.697902Z","iopub.status.idle":"2022-07-20T04:05:32.924679Z","shell.execute_reply.started":"2022-07-20T04:05:32.697869Z","shell.execute_reply":"2022-07-20T04:05:32.923367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.groupby(['Sex','Survived']).size().unstack()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.926380Z","iopub.execute_input":"2022-07-20T04:05:32.926876Z","iopub.status.idle":"2022-07-20T04:05:32.944373Z","shell.execute_reply.started":"2022-07-20T04:05:32.926834Z","shell.execute_reply":"2022-07-20T04:05:32.943413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.groupby(['Sex','Survived']).size().unstack().plot(kind='bar',stacked=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:32.945938Z","iopub.execute_input":"2022-07-20T04:05:32.946361Z","iopub.status.idle":"2022-07-20T04:05:33.139887Z","shell.execute_reply.started":"2022-07-20T04:05:32.946328Z","shell.execute_reply":"2022-07-20T04:05:33.138523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"da=data_train.groupby(['Embarked','Survived']).size().unstack()\nprint(da)\nda.plot(kind='barh',stacked=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.141555Z","iopub.execute_input":"2022-07-20T04:05:33.141933Z","iopub.status.idle":"2022-07-20T04:05:33.352058Z","shell.execute_reply.started":"2022-07-20T04:05:33.141875Z","shell.execute_reply":"2022-07-20T04:05:33.350641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p1C=(da[1].C/(da[0].C+da[1].C))*100\np0C=(da[0].C/(da[0].C+da[1].C))*100\np1S=(da[1].S/(da[0].S+da[1].S))*100\np0S=(da[0].S/(da[0].S+da[1].S))*100\np1Q=(da[1].Q/(da[0].Q+da[1].Q))*100\np0Q=(da[0].Q/(da[0].Q+da[1].Q))*100","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.358182Z","iopub.execute_input":"2022-07-20T04:05:33.359605Z","iopub.status.idle":"2022-07-20T04:05:33.373307Z","shell.execute_reply.started":"2022-07-20T04:05:33.359527Z","shell.execute_reply":"2022-07-20T04:05:33.371412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Percentage survided/not that Embarked in Port C\",p1C,p0C)\nprint(\"Percentage survided/not that Embarked in Port Q\",p1Q,p0Q)\nprint(\"Percentage survided/not that Embarked in Port S\",p1S,p0S)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.374962Z","iopub.execute_input":"2022-07-20T04:05:33.376063Z","iopub.status.idle":"2022-07-20T04:05:33.388145Z","shell.execute_reply.started":"2022-07-20T04:05:33.376006Z","shell.execute_reply":"2022-07-20T04:05:33.386683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train['Relative']=data_train['SibSp']+data_train['Parch']\ndata_train['TravelAlone']=np.where(data_train['Relative']>0,'yes','no')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.390104Z","iopub.execute_input":"2022-07-20T04:05:33.390921Z","iopub.status.idle":"2022-07-20T04:05:33.403731Z","shell.execute_reply.started":"2022-07-20T04:05:33.390873Z","shell.execute_reply":"2022-07-20T04:05:33.402358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.groupby('TravelAlone').Survived.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.405560Z","iopub.execute_input":"2022-07-20T04:05:33.406302Z","iopub.status.idle":"2022-07-20T04:05:33.418878Z","shell.execute_reply.started":"2022-07-20T04:05:33.406253Z","shell.execute_reply":"2022-07-20T04:05:33.417627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.groupby('TravelAlone').Survived.value_counts().plot(kind='barh')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.420091Z","iopub.execute_input":"2022-07-20T04:05:33.420967Z","iopub.status.idle":"2022-07-20T04:05:33.611754Z","shell.execute_reply.started":"2022-07-20T04:05:33.420931Z","shell.execute_reply":"2022-07-20T04:05:33.610629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> Travelling Alone give The most survival Rate","metadata":{}},{"cell_type":"code","source":"def ageCategorize(age):\n    if age<15:\n        return \"<15\"\n    elif age>=15 and age<30:\n        return \"15-30\"\n    elif age>=30 and age<45:\n        return \"30-45\"\n    elif age>=45 and age<60:\n        return \"45-60\"\n    elif age>=60:\n        return \">60\"","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.613447Z","iopub.execute_input":"2022-07-20T04:05:33.613807Z","iopub.status.idle":"2022-07-20T04:05:33.619955Z","shell.execute_reply.started":"2022-07-20T04:05:33.613774Z","shell.execute_reply":"2022-07-20T04:05:33.619010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train['Age_categorized']=data_train['Age'].apply(ageCategorize)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.621348Z","iopub.execute_input":"2022-07-20T04:05:33.621974Z","iopub.status.idle":"2022-07-20T04:05:33.631940Z","shell.execute_reply.started":"2022-07-20T04:05:33.621941Z","shell.execute_reply":"2022-07-20T04:05:33.630759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train['Age_categorized'].head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.633639Z","iopub.execute_input":"2022-07-20T04:05:33.634257Z","iopub.status.idle":"2022-07-20T04:05:33.643439Z","shell.execute_reply.started":"2022-07-20T04:05:33.634224Z","shell.execute_reply":"2022-07-20T04:05:33.642353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train['Age_categorized'].value_counts().plot(kind='pie',autopct=\"%1.1f%%\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.644849Z","iopub.execute_input":"2022-07-20T04:05:33.645863Z","iopub.status.idle":"2022-07-20T04:05:33.792898Z","shell.execute_reply.started":"2022-07-20T04:05:33.645814Z","shell.execute_reply":"2022-07-20T04:05:33.791535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"da=data_train.groupby('Age_categorized').Survived.value_counts()\nprint(da)\nda.plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:33.794416Z","iopub.execute_input":"2022-07-20T04:05:33.795709Z","iopub.status.idle":"2022-07-20T04:05:34.037219Z","shell.execute_reply.started":"2022-07-20T04:05:33.795656Z","shell.execute_reply":"2022-07-20T04:05:34.035993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ageCategoredSurvived=[da[1],da[3],da[5],da[6],da[9]]\nageCategoredSurvived","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.038956Z","iopub.execute_input":"2022-07-20T04:05:34.039297Z","iopub.status.idle":"2022-07-20T04:05:34.051420Z","shell.execute_reply.started":"2022-07-20T04:05:34.039265Z","shell.execute_reply":"2022-07-20T04:05:34.050526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.title(\"Group Age Survived\")\nlabel=[\"15-30\",\"30-45\",\"45-60\",\"<15\",\">60\"]\nplt.pie(ageCategoredSurvived,labels=label,autopct='%1.1f%%')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.053203Z","iopub.execute_input":"2022-07-20T04:05:34.053549Z","iopub.status.idle":"2022-07-20T04:05:34.181587Z","shell.execute_reply.started":"2022-07-20T04:05:34.053516Z","shell.execute_reply":"2022-07-20T04:05:34.178584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> \"Group Age 15-30 ,30-45 \" had most rate of survival","metadata":{}},{"cell_type":"markdown","source":"**Feature Transformation/Selection**","metadata":{}},{"cell_type":"code","source":"data_train['Sex']=np.where(data_train['Sex']=='male',1,0)\ndata_test['Sex']=np.where(data_test['Sex']=='male',1,0)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.183737Z","iopub.execute_input":"2022-07-20T04:05:34.184208Z","iopub.status.idle":"2022-07-20T04:05:34.199236Z","shell.execute_reply.started":"2022-07-20T04:05:34.184159Z","shell.execute_reply":"2022-07-20T04:05:34.197634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nlabel=LabelEncoder()\ndata_train['Cabin']=label.fit_transform(data_train['Cabin'])\ndata_train['Embarked']=label.fit_transform(data_train['Embarked'])\n\ndata_test['Cabin']=label.fit_transform(data_test['Cabin'])\ndata_test['Embarked']=label.fit_transform(data_test['Embarked'])","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.201275Z","iopub.execute_input":"2022-07-20T04:05:34.201787Z","iopub.status.idle":"2022-07-20T04:05:34.224876Z","shell.execute_reply.started":"2022-07-20T04:05:34.201738Z","shell.execute_reply":"2022-07-20T04:05:34.223477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.226676Z","iopub.execute_input":"2022-07-20T04:05:34.227376Z","iopub.status.idle":"2022-07-20T04:05:34.252729Z","shell.execute_reply.started":"2022-07-20T04:05:34.227328Z","shell.execute_reply":"2022-07-20T04:05:34.251561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pid=data_test['PassengerId']","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:43:54.239794Z","iopub.execute_input":"2022-07-20T04:43:54.240180Z","iopub.status.idle":"2022-07-20T04:43:54.245731Z","shell.execute_reply.started":"2022-07-20T04:43:54.240150Z","shell.execute_reply":"2022-07-20T04:43:54.244409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p=list(pid)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:30:29.643127Z","iopub.execute_input":"2022-07-20T05:30:29.643517Z","iopub.status.idle":"2022-07-20T05:30:29.649438Z","shell.execute_reply.started":"2022-07-20T05:30:29.643487Z","shell.execute_reply":"2022-07-20T05:30:29.647967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr=data_train.corr()\ncorr.style.background_gradient(cmap='coolwarm')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.254498Z","iopub.execute_input":"2022-07-20T04:05:34.255186Z","iopub.status.idle":"2022-07-20T04:05:34.366219Z","shell.execute_reply.started":"2022-07-20T04:05:34.255143Z","shell.execute_reply":"2022-07-20T04:05:34.364891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we take value far from 0 that coorelated to Survived\nSex,Pclass,Fare,Cabin,Embarked,Age","metadata":{}},{"cell_type":"code","source":"data_tr=data_train.drop(['Relative','Parch','SibSp','PassengerId','TravelAlone','Age_categorized',\n                     'Ticket','Name'\n                     ],axis=1)\ndata_tst=data_test.drop(['Parch','SibSp','PassengerId',\n                     'Ticket','Name'\n                     ],axis=1)\ndata_tst.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.368073Z","iopub.execute_input":"2022-07-20T04:05:34.368780Z","iopub.status.idle":"2022-07-20T04:05:34.391451Z","shell.execute_reply.started":"2022-07-20T04:05:34.368725Z","shell.execute_reply":"2022-07-20T04:05:34.390234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot age drop outline\nplt.figure(figsize=(5,5))\ndata_tr['Age'].plot(kind='box')\n ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.393203Z","iopub.execute_input":"2022-07-20T04:05:34.394083Z","iopub.status.idle":"2022-07-20T04:05:34.585456Z","shell.execute_reply.started":"2022-07-20T04:05:34.394042Z","shell.execute_reply":"2022-07-20T04:05:34.584627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#remove outlier\nmean,std=data_tr['Age'].mean(),data_tr['Age'].std()\ncutoff=std*3\nlower,upper=mean-cutoff,mean+cutoff\ndata_tr=data_tr[data_tr['Age']>lower]\ndata_tr=data_tr[data_tr['Age']<upper]\ndata_tst=data_tst[data_tst['Age']>lower]\ndata_tst=data_tst[data_tst['Age']<upper]\n\nlower,upper","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.591753Z","iopub.execute_input":"2022-07-20T04:05:34.593146Z","iopub.status.idle":"2022-07-20T04:05:34.609753Z","shell.execute_reply.started":"2022-07-20T04:05:34.593087Z","shell.execute_reply":"2022-07-20T04:05:34.608456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_tst.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.611828Z","iopub.execute_input":"2022-07-20T04:05:34.613274Z","iopub.status.idle":"2022-07-20T04:05:34.632709Z","shell.execute_reply.started":"2022-07-20T04:05:34.613208Z","shell.execute_reply":"2022-07-20T04:05:34.631466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_tr=data_tr.iloc[:,1:7]\nX_tst=data_tst.iloc[:,0:7]\ny_tr=data_tr.iloc[:,0]\n","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.634541Z","iopub.execute_input":"2022-07-20T04:05:34.635479Z","iopub.status.idle":"2022-07-20T04:05:34.646003Z","shell.execute_reply.started":"2022-07-20T04:05:34.635428Z","shell.execute_reply":"2022-07-20T04:05:34.644340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_tst.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:05:34.648197Z","iopub.execute_input":"2022-07-20T04:05:34.649087Z","iopub.status.idle":"2022-07-20T04:05:34.670072Z","shell.execute_reply.started":"2022-07-20T04:05:34.649034Z","shell.execute_reply":"2022-07-20T04:05:34.669155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=np.array(X_tr)\nX_test=np.array(X_tst)\ny_train=np.array(y_tr)\nX_test.shape\ny_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:24:09.843213Z","iopub.execute_input":"2022-07-20T05:24:09.843655Z","iopub.status.idle":"2022-07-20T05:24:09.856997Z","shell.execute_reply.started":"2022-07-20T05:24:09.843620Z","shell.execute_reply":"2022-07-20T05:24:09.855815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nlg=LogisticRegression()\nlg.fit(X_train,y_train)\ny_pred=lg.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T04:25:52.758160Z","iopub.execute_input":"2022-07-20T04:25:52.758623Z","iopub.status.idle":"2022-07-20T04:25:52.790123Z","shell.execute_reply.started":"2022-07-20T04:25:52.758587Z","shell.execute_reply":"2022-07-20T04:25:52.789095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingClassifier\nclf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,max_depth=1, random_state=0)\nclf.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:24:28.502530Z","iopub.execute_input":"2022-07-20T05:24:28.502922Z","iopub.status.idle":"2022-07-20T05:24:28.581944Z","shell.execute_reply.started":"2022-07-20T05:24:28.502891Z","shell.execute_reply":"2022-07-20T05:24:28.580652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pr=clf.predict(X_test)\npr=list(pr)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:24:37.143057Z","iopub.execute_input":"2022-07-20T05:24:37.144158Z","iopub.status.idle":"2022-07-20T05:24:37.150496Z","shell.execute_reply.started":"2022-07-20T05:24:37.144113Z","shell.execute_reply":"2022-07-20T05:24:37.149652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n=[p,pr]","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:36:39.333626Z","iopub.execute_input":"2022-07-20T05:36:39.334083Z","iopub.status.idle":"2022-07-20T05:36:39.339629Z","shell.execute_reply.started":"2022-07-20T05:36:39.334046Z","shell.execute_reply":"2022-07-20T05:36:39.338304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dat=pd.DataFrame(n)\ndat=dat.pivot(columns=[i for i in range(416)])\nd=dat.to_csv(\"data.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:57:19.722964Z","iopub.execute_input":"2022-07-20T05:57:19.723357Z","iopub.status.idle":"2022-07-20T05:57:19.996390Z","shell.execute_reply.started":"2022-07-20T05:57:19.723325Z","shell.execute_reply":"2022-07-20T05:57:19.995112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-20T05:50:28.818083Z","iopub.execute_input":"2022-07-20T05:50:28.818467Z","iopub.status.idle":"2022-07-20T05:50:28.830033Z","shell.execute_reply.started":"2022-07-20T05:50:28.818436Z","shell.execute_reply":"2022-07-20T05:50:28.828785Z"},"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":{"trusted":true},"execution_count":null,"outputs":[]}]}