{"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":"markdown","source":"# Import libraries","metadata":{}},{"cell_type":"code","source":"import  pandas as pd\nimport warnings\nwarnings.filterwarnings('ignore')\nimport missingno as msn\nimport seaborn as sns\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:55.595858Z","iopub.execute_input":"2022-07-24T16:02:55.597451Z","iopub.status.idle":"2022-07-24T16:02:56.789531Z","shell.execute_reply.started":"2022-07-24T16:02:55.597324Z","shell.execute_reply":"2022-07-24T16:02:56.788655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exracting dataset","metadata":{}},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/titanic/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.791028Z","iopub.execute_input":"2022-07-24T16:02:56.791684Z","iopub.status.idle":"2022-07-24T16:02:56.810305Z","shell.execute_reply.started":"2022-07-24T16:02:56.791654Z","shell.execute_reply":"2022-07-24T16:02:56.809320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"let's see data","metadata":{}},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.811645Z","iopub.execute_input":"2022-07-24T16:02:56.812161Z","iopub.status.idle":"2022-07-24T16:02:56.836510Z","shell.execute_reply.started":"2022-07-24T16:02:56.812129Z","shell.execute_reply":"2022-07-24T16:02:56.835404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"you can see columns and also shape(shape can help us to see how many columns and rows exist)","metadata":{}},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.838858Z","iopub.execute_input":"2022-07-24T16:02:56.839204Z","iopub.status.idle":"2022-07-24T16:02:56.845698Z","shell.execute_reply.started":"2022-07-24T16:02:56.839176Z","shell.execute_reply":"2022-07-24T16:02:56.844542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.847180Z","iopub.execute_input":"2022-07-24T16:02:56.848826Z","iopub.status.idle":"2022-07-24T16:02:56.858073Z","shell.execute_reply.started":"2022-07-24T16:02:56.848772Z","shell.execute_reply":"2022-07-24T16:02:56.856330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.860648Z","iopub.execute_input":"2022-07-24T16:02:56.861805Z","iopub.status.idle":"2022-07-24T16:02:56.897594Z","shell.execute_reply.started":"2022-07-24T16:02:56.861746Z","shell.execute_reply":"2022-07-24T16:02:56.895761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First of all we can see null values of columns using missingno matrix ","metadata":{}},{"cell_type":"code","source":"msn.matrix(df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:56.899368Z","iopub.execute_input":"2022-07-24T16:02:56.899895Z","iopub.status.idle":"2022-07-24T16:02:57.472223Z","shell.execute_reply.started":"2022-07-24T16:02:56.899849Z","shell.execute_reply":"2022-07-24T16:02:57.470966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"then we can multiply all null values of columns using sum","metadata":{}},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:57.473540Z","iopub.execute_input":"2022-07-24T16:02:57.473999Z","iopub.status.idle":"2022-07-24T16:02:57.484524Z","shell.execute_reply.started":"2022-07-24T16:02:57.473962Z","shell.execute_reply":"2022-07-24T16:02:57.483206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Also we can see null values using missingno bar","metadata":{}},{"cell_type":"code","source":"msn.bar(df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:57.486357Z","iopub.execute_input":"2022-07-24T16:02:57.486674Z","iopub.status.idle":"2022-07-24T16:02:58.381040Z","shell.execute_reply.started":"2022-07-24T16:02:57.486647Z","shell.execute_reply":"2022-07-24T16:02:58.379945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"and we can find the percentage of null values of columns like that","metadata":{}},{"cell_type":"code","source":"df.isnull().sum()/df.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.385507Z","iopub.execute_input":"2022-07-24T16:02:58.385842Z","iopub.status.idle":"2022-07-24T16:02:58.396359Z","shell.execute_reply.started":"2022-07-24T16:02:58.385812Z","shell.execute_reply":"2022-07-24T16:02:58.395487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As you see 'cabin' column has many null values ,let's drop this column ","metadata":{}},{"cell_type":"code","source":"df.drop('Cabin', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.397793Z","iopub.execute_input":"2022-07-24T16:02:58.398258Z","iopub.status.idle":"2022-07-24T16:02:58.404180Z","shell.execute_reply.started":"2022-07-24T16:02:58.398228Z","shell.execute_reply":"2022-07-24T16:02:58.403159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy=df.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.405993Z","iopub.execute_input":"2022-07-24T16:02:58.406286Z","iopub.status.idle":"2022-07-24T16:02:58.415441Z","shell.execute_reply.started":"2022-07-24T16:02:58.406259Z","shell.execute_reply":"2022-07-24T16:02:58.414339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.416632Z","iopub.execute_input":"2022-07-24T16:02:58.417184Z","iopub.status.idle":"2022-07-24T16:02:58.439147Z","shell.execute_reply.started":"2022-07-24T16:02:58.417147Z","shell.execute_reply":"2022-07-24T16:02:58.438269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"as you see the 'Cabin' column has dropped","metadata":{}},{"cell_type":"markdown","source":"we can count null values of columns like that","metadata":{}},{"cell_type":"code","source":"df['Age'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.440473Z","iopub.execute_input":"2022-07-24T16:02:58.441014Z","iopub.status.idle":"2022-07-24T16:02:58.451083Z","shell.execute_reply.started":"2022-07-24T16:02:58.440983Z","shell.execute_reply":"2022-07-24T16:02:58.450133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.452294Z","iopub.execute_input":"2022-07-24T16:02:58.452748Z","iopub.status.idle":"2022-07-24T16:02:58.472247Z","shell.execute_reply.started":"2022-07-24T16:02:58.452712Z","shell.execute_reply":"2022-07-24T16:02:58.471343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Age'].isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.473428Z","iopub.execute_input":"2022-07-24T16:02:58.473877Z","iopub.status.idle":"2022-07-24T16:02:58.480900Z","shell.execute_reply.started":"2022-07-24T16:02:58.473848Z","shell.execute_reply":"2022-07-24T16:02:58.479893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's describe data to see mean ,std,min,max and other values","metadata":{}},{"cell_type":"code","source":"df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.482139Z","iopub.execute_input":"2022-07-24T16:02:58.482785Z","iopub.status.idle":"2022-07-24T16:02:58.519458Z","shell.execute_reply.started":"2022-07-24T16:02:58.482752Z","shell.execute_reply":"2022-07-24T16:02:58.518578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data visualization","metadata":{}},{"cell_type":"code","source":"df['Survived'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.520619Z","iopub.execute_input":"2022-07-24T16:02:58.521149Z","iopub.status.idle":"2022-07-24T16:02:58.528017Z","shell.execute_reply.started":"2022-07-24T16:02:58.521116Z","shell.execute_reply":"2022-07-24T16:02:58.527190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,9))\nsns.set_palette('dark')\nsns.countplot(x='Survived',data=df)\nplt.title('Survival and mortality values')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.529243Z","iopub.execute_input":"2022-07-24T16:02:58.529881Z","iopub.status.idle":"2022-07-24T16:02:58.719941Z","shell.execute_reply.started":"2022-07-24T16:02:58.529849Z","shell.execute_reply":"2022-07-24T16:02:58.718361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,9))\nsns.set_palette('pastel')\nsns.countplot(x='Survived',hue='Sex',data=df)\nplt.title('Death and survival values by sex')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.721849Z","iopub.execute_input":"2022-07-24T16:02:58.722434Z","iopub.status.idle":"2022-07-24T16:02:58.957002Z","shell.execute_reply.started":"2022-07-24T16:02:58.722400Z","shell.execute_reply":"2022-07-24T16:02:58.955818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.960731Z","iopub.execute_input":"2022-07-24T16:02:58.961106Z","iopub.status.idle":"2022-07-24T16:02:58.979157Z","shell.execute_reply.started":"2022-07-24T16:02:58.961072Z","shell.execute_reply":"2022-07-24T16:02:58.977678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_palette('dark')\ndf['Pclass'].value_counts().plot.bar()\nplt.title('Ticket class values')\nplt.xlabel('Tickets')\nplt.ylabel('counts')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:58.981032Z","iopub.execute_input":"2022-07-24T16:02:58.981744Z","iopub.status.idle":"2022-07-24T16:02:59.161355Z","shell.execute_reply.started":"2022-07-24T16:02:58.981697Z","shell.execute_reply":"2022-07-24T16:02:59.159976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Name'].value_counts().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.162870Z","iopub.execute_input":"2022-07-24T16:02:59.163349Z","iopub.status.idle":"2022-07-24T16:02:59.174009Z","shell.execute_reply.started":"2022-07-24T16:02:59.163295Z","shell.execute_reply":"2022-07-24T16:02:59.172683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.175895Z","iopub.execute_input":"2022-07-24T16:02:59.176617Z","iopub.status.idle":"2022-07-24T16:02:59.198667Z","shell.execute_reply.started":"2022-07-24T16:02:59.176572Z","shell.execute_reply":"2022-07-24T16:02:59.197857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ticket_class=df['Pclass'].value_counts()\nprint(ticket_class)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.199848Z","iopub.execute_input":"2022-07-24T16:02:59.200390Z","iopub.status.idle":"2022-07-24T16:02:59.206739Z","shell.execute_reply.started":"2022-07-24T16:02:59.200348Z","shell.execute_reply":"2022-07-24T16:02:59.205749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels=ticket_class.index\nsizes=ticket_class.values\nplt.figure(figsize=(12,9))\ncolors=sns.color_palette('hls')\nplt.pie(sizes,labels=labels,autopct='%1.1f%%',\n        shadow=True,colors=colors,startangle=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.208276Z","iopub.execute_input":"2022-07-24T16:02:59.208616Z","iopub.status.idle":"2022-07-24T16:02:59.368145Z","shell.execute_reply.started":"2022-07-24T16:02:59.208587Z","shell.execute_reply":"2022-07-24T16:02:59.366633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"extracting status from 'Name' column","metadata":{}},{"cell_type":"code","source":"df['Name'].map(lambda row: row.split(',')[1].split('.')[0])","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.369711Z","iopub.execute_input":"2022-07-24T16:02:59.370399Z","iopub.status.idle":"2022-07-24T16:02:59.385172Z","shell.execute_reply.started":"2022-07-24T16:02:59.370354Z","shell.execute_reply":"2022-07-24T16:02:59.383786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we can count every status","metadata":{}},{"cell_type":"code","source":"df['Name'].map(lambda row: row.split(',')[1].split('.')[0]).value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.397190Z","iopub.execute_input":"2022-07-24T16:02:59.398058Z","iopub.status.idle":"2022-07-24T16:02:59.413483Z","shell.execute_reply.started":"2022-07-24T16:02:59.398004Z","shell.execute_reply":"2022-07-24T16:02:59.412235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Using data visualization we can see number of status ","metadata":{}},{"cell_type":"code","source":"status=df['Name'].map(lambda row: row.split(',')[1].split('.')[0]).value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.414957Z","iopub.execute_input":"2022-07-24T16:02:59.416225Z","iopub.status.idle":"2022-07-24T16:02:59.424787Z","shell.execute_reply.started":"2022-07-24T16:02:59.416179Z","shell.execute_reply":"2022-07-24T16:02:59.423977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 8))\nsns.barplot(x=status.index, y=status.values)\nplt.title('Number of status')\nplt.xlabel('Status')\nplt.ylabel('Count')\nplt.xticks(rotation=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.426176Z","iopub.execute_input":"2022-07-24T16:02:59.427463Z","iopub.status.idle":"2022-07-24T16:02:59.737081Z","shell.execute_reply.started":"2022-07-24T16:02:59.427417Z","shell.execute_reply":"2022-07-24T16:02:59.735811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"we can find outliers of column","metadata":{}},{"cell_type":"code","source":"df['Age'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.738467Z","iopub.execute_input":"2022-07-24T16:02:59.738890Z","iopub.status.idle":"2022-07-24T16:02:59.751491Z","shell.execute_reply.started":"2022-07-24T16:02:59.738858Z","shell.execute_reply":"2022-07-24T16:02:59.750363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"LET's see data with outliers using boxplot ","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(12,6))\nsns.boxplot(df['Age'])\nplt.title('data with outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.753188Z","iopub.execute_input":"2022-07-24T16:02:59.753896Z","iopub.status.idle":"2022-07-24T16:02:59.937417Z","shell.execute_reply.started":"2022-07-24T16:02:59.753851Z","shell.execute_reply":"2022-07-24T16:02:59.936643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.938717Z","iopub.execute_input":"2022-07-24T16:02:59.939422Z","iopub.status.idle":"2022-07-24T16:02:59.949978Z","shell.execute_reply.started":"2022-07-24T16:02:59.939388Z","shell.execute_reply":"2022-07-24T16:02:59.948564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Age'].median()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.951410Z","iopub.execute_input":"2022-07-24T16:02:59.951841Z","iopub.status.idle":"2022-07-24T16:02:59.960760Z","shell.execute_reply.started":"2022-07-24T16:02:59.951797Z","shell.execute_reply":"2022-07-24T16:02:59.959604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def out_bound(df, col):\n    Q1=df[col].quantile(0.25)\n    Q3=df[col].quantile(0.75)\n    IQR=Q3-Q1\n    lower_bound=Q1-1.5*IQR\n    upper_bound=Q3+1.5*IQR\n    \n    return lower_bound, upper_bound","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.962629Z","iopub.execute_input":"2022-07-24T16:02:59.963354Z","iopub.status.idle":"2022-07-24T16:02:59.972319Z","shell.execute_reply.started":"2022-07-24T16:02:59.963312Z","shell.execute_reply":"2022-07-24T16:02:59.971108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(out_bound(df, 'Age'))","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.973673Z","iopub.execute_input":"2022-07-24T16:02:59.974279Z","iopub.status.idle":"2022-07-24T16:02:59.990996Z","shell.execute_reply.started":"2022-07-24T16:02:59.974233Z","shell.execute_reply":"2022-07-24T16:02:59.989790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can remove also replace outliers.Removing will reduce the shape of data,\nbut replacing wil not reduce the shape of data. \nYou can choose to work one of them.It is up to you.","metadata":{}},{"cell_type":"markdown","source":"# Remove outliers","metadata":{}},{"cell_type":"code","source":"def remove_outliers(data, col):\n    l_b, u_b=out_bound(data, col)\n    \n    return data[ (data[col]>l_b) & (data[col]<u_b) ]","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:02:59.992596Z","iopub.execute_input":"2022-07-24T16:02:59.993176Z","iopub.status.idle":"2022-07-24T16:02:59.999402Z","shell.execute_reply.started":"2022-07-24T16:02:59.993143Z","shell.execute_reply":"2022-07-24T16:02:59.998309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data1=remove_outliers(df, 'Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.001125Z","iopub.execute_input":"2022-07-24T16:03:00.001827Z","iopub.status.idle":"2022-07-24T16:03:00.015387Z","shell.execute_reply.started":"2022-07-24T16:03:00.001782Z","shell.execute_reply":"2022-07-24T16:03:00.013918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,9))\nsns.boxplot(data1['Age'])\nplt.title('data with removed outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.017221Z","iopub.execute_input":"2022-07-24T16:03:00.018055Z","iopub.status.idle":"2022-07-24T16:03:00.200334Z","shell.execute_reply.started":"2022-07-24T16:03:00.018022Z","shell.execute_reply":"2022-07-24T16:03:00.198984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Replace outliers","metadata":{}},{"cell_type":"code","source":"def outliers_equal_bounds(data, col):\n    l_b, u_b=out_bound(data, col)\n    \n    data.loc[(data[col]<l_b), col]=l_b\n    data.loc[(data[col]>u_b), col]=u_b\n    \n    return data\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.201974Z","iopub.execute_input":"2022-07-24T16:03:00.202447Z","iopub.status.idle":"2022-07-24T16:03:00.209568Z","shell.execute_reply.started":"2022-07-24T16:03:00.202401Z","shell.execute_reply":"2022-07-24T16:03:00.208176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data2=outliers_equal_bounds(df, 'Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.211533Z","iopub.execute_input":"2022-07-24T16:03:00.211990Z","iopub.status.idle":"2022-07-24T16:03:00.223325Z","shell.execute_reply.started":"2022-07-24T16:03:00.211947Z","shell.execute_reply":"2022-07-24T16:03:00.222013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's see data with replaced outliers","metadata":{}},{"cell_type":"code","source":"sns.set_palette('bright')\nplt.figure(figsize=(12,9))\nsns.boxplot(data2['Age'])\nplt.title('Data with replaced outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.224397Z","iopub.execute_input":"2022-07-24T16:03:00.225002Z","iopub.status.idle":"2022-07-24T16:03:00.402648Z","shell.execute_reply.started":"2022-07-24T16:03:00.224955Z","shell.execute_reply":"2022-07-24T16:03:00.401437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Real data:', df.shape)\nprint('Data with removed outliers by age:', data1.shape)\nprint('Data with replaced outliers by age:', data2.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.406174Z","iopub.execute_input":"2022-07-24T16:03:00.406766Z","iopub.status.idle":"2022-07-24T16:03:00.413573Z","shell.execute_reply.started":"2022-07-24T16:03:00.406717Z","shell.execute_reply":"2022-07-24T16:03:00.412642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.415098Z","iopub.execute_input":"2022-07-24T16:03:00.415798Z","iopub.status.idle":"2022-07-24T16:03:00.434449Z","shell.execute_reply.started":"2022-07-24T16:03:00.415754Z","shell.execute_reply":"2022-07-24T16:03:00.433269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_palette('dark')\nplt.figure(figsize=(12,9))\nsns.boxplot(x='Sex', y='Age', data=df_copy)\nplt.title('outliers by sex')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.436249Z","iopub.execute_input":"2022-07-24T16:03:00.436964Z","iopub.status.idle":"2022-07-24T16:03:00.679992Z","shell.execute_reply.started":"2022-07-24T16:03:00.436900Z","shell.execute_reply":"2022-07-24T16:03:00.678869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy['Embarked'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.681146Z","iopub.execute_input":"2022-07-24T16:03:00.681996Z","iopub.status.idle":"2022-07-24T16:03:00.692830Z","shell.execute_reply.started":"2022-07-24T16:03:00.681962Z","shell.execute_reply":"2022-07-24T16:03:00.691602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_palette('bright')\nplt.figure(figsize=(12,9))\nplt.title('Survival and death by Port of Embarkation')\nsns.countplot(x='Survived', hue='Embarked', data=df_copy)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.694356Z","iopub.execute_input":"2022-07-24T16:03:00.695517Z","iopub.status.idle":"2022-07-24T16:03:00.996983Z","shell.execute_reply.started":"2022-07-24T16:03:00.695467Z","shell.execute_reply":"2022-07-24T16:03:00.996136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see death and survived values by embarked","metadata":{}},{"cell_type":"code","source":"df_copy.groupby('Embarked')['Survived'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:00.998147Z","iopub.execute_input":"2022-07-24T16:03:00.998601Z","iopub.status.idle":"2022-07-24T16:03:01.008031Z","shell.execute_reply.started":"2022-07-24T16:03:00.998571Z","shell.execute_reply":"2022-07-24T16:03:01.007099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy['SibSp'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.009478Z","iopub.execute_input":"2022-07-24T16:03:01.010115Z","iopub.status.idle":"2022-07-24T16:03:01.017672Z","shell.execute_reply.started":"2022-07-24T16:03:01.010083Z","shell.execute_reply":"2022-07-24T16:03:01.016753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.019784Z","iopub.execute_input":"2022-07-24T16:03:01.020933Z","iopub.status.idle":"2022-07-24T16:03:01.038277Z","shell.execute_reply.started":"2022-07-24T16:03:01.020875Z","shell.execute_reply":"2022-07-24T16:03:01.037287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy['Parch'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.039447Z","iopub.execute_input":"2022-07-24T16:03:01.039949Z","iopub.status.idle":"2022-07-24T16:03:01.047024Z","shell.execute_reply.started":"2022-07-24T16:03:01.039890Z","shell.execute_reply":"2022-07-24T16:03:01.046221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,9))\nsns.countplot(x='Survived', hue='SibSp', data=df_copy)\nplt.title('survived siblings')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.048499Z","iopub.execute_input":"2022-07-24T16:03:01.049324Z","iopub.status.idle":"2022-07-24T16:03:01.325746Z","shell.execute_reply.started":"2022-07-24T16:03:01.049283Z","shell.execute_reply":"2022-07-24T16:03:01.324386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax1 = plt.subplots(figsize=(16, 9))\nsns.set_palette('bright')\nsns.histplot(data = df_copy, x='Age', ax=ax1, bins=25, hue='Survived', kde=True)\nplt.title('Death and survival values by age')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.327353Z","iopub.execute_input":"2022-07-24T16:03:01.327889Z","iopub.status.idle":"2022-07-24T16:03:01.894477Z","shell.execute_reply.started":"2022-07-24T16:03:01.327844Z","shell.execute_reply":"2022-07-24T16:03:01.893128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_palette('pastel')\nplt.figure(figsize=(12,6))\nsns.countplot(x='Survived', hue='Parch', data=df_copy)\nplt.title('children aboard titanic')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:01.896172Z","iopub.execute_input":"2022-07-24T16:03:01.897296Z","iopub.status.idle":"2022-07-24T16:03:02.151785Z","shell.execute_reply.started":"2022-07-24T16:03:01.897260Z","shell.execute_reply":"2022-07-24T16:03:02.150704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"survived=df['Survived'].value_counts()\nprint(survived)","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.153304Z","iopub.execute_input":"2022-07-24T16:03:02.154209Z","iopub.status.idle":"2022-07-24T16:03:02.161039Z","shell.execute_reply.started":"2022-07-24T16:03:02.154175Z","shell.execute_reply":"2022-07-24T16:03:02.159965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels=survived.index\nsizes=survived.values\nplt.figure(figsize=(12,9))\ncolors = sns.color_palette('Paired')\nplt.pie(sizes,labels=labels,autopct='%1.1f%%',\n        shadow=True,colors=colors,startangle=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.162426Z","iopub.execute_input":"2022-07-24T16:03:02.162818Z","iopub.status.idle":"2022-07-24T16:03:02.303115Z","shell.execute_reply.started":"2022-07-24T16:03:02.162787Z","shell.execute_reply":"2022-07-24T16:03:02.301776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.304781Z","iopub.execute_input":"2022-07-24T16:03:02.305884Z","iopub.status.idle":"2022-07-24T16:03:02.330518Z","shell.execute_reply.started":"2022-07-24T16:03:02.305829Z","shell.execute_reply":"2022-07-24T16:03:02.329235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,9))\nsns.distplot(df['Age'])\nplt.title('age density')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.332203Z","iopub.execute_input":"2022-07-24T16:03:02.333281Z","iopub.status.idle":"2022-07-24T16:03:02.602658Z","shell.execute_reply.started":"2022-07-24T16:03:02.333230Z","shell.execute_reply":"2022-07-24T16:03:02.601662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,7))\nsns.set_palette('bright')\nsns.violinplot(x=df['Sex'],y=df['Age'])\nplt.title('age by gender')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.604842Z","iopub.execute_input":"2022-07-24T16:03:02.605199Z","iopub.status.idle":"2022-07-24T16:03:02.820347Z","shell.execute_reply.started":"2022-07-24T16:03:02.605167Z","shell.execute_reply":"2022-07-24T16:03:02.819262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_palette('dark')\nplt.figure(figsize=(16,9))\nsns.countplot(x='Parch', hue='Sex', data=df)\nplt.xticks(rotation=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:02.821982Z","iopub.execute_input":"2022-07-24T16:03:02.822626Z","iopub.status.idle":"2022-07-24T16:03:03.077007Z","shell.execute_reply.started":"2022-07-24T16:03:02.822591Z","shell.execute_reply":"2022-07-24T16:03:03.075895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_copy.corr()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:03.078253Z","iopub.execute_input":"2022-07-24T16:03:03.078571Z","iopub.status.idle":"2022-07-24T16:03:03.099120Z","shell.execute_reply.started":"2022-07-24T16:03:03.078542Z","shell.execute_reply":"2022-07-24T16:03:03.097982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr=df_copy.corr()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:03.100563Z","iopub.execute_input":"2022-07-24T16:03:03.100985Z","iopub.status.idle":"2022-07-24T16:03:03.106437Z","shell.execute_reply.started":"2022-07-24T16:03:03.100956Z","shell.execute_reply":"2022-07-24T16:03:03.105384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8,8))\nplt.title('Correlation Analysis',color='Red',fontsize=20,pad=40)\nmask = np.triu(np.ones_like(corr, dtype = bool))\nsns.heatmap(df.corr(), mask=mask, annot=True, linewidths=.5);\nplt.xticks(rotation=60)\nplt.yticks(rotation = 60)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:03.108487Z","iopub.execute_input":"2022-07-24T16:03:03.108887Z","iopub.status.idle":"2022-07-24T16:03:03.451109Z","shell.execute_reply.started":"2022-07-24T16:03:03.108853Z","shell.execute_reply":"2022-07-24T16:03:03.449937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 6))\nsns.barplot(x=df['Age'].value_counts().index, y=df['Age'].value_counts())\nplt.title('Age values')\nplt.xticks(rotation=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:03.452566Z","iopub.execute_input":"2022-07-24T16:03:03.452882Z","iopub.status.idle":"2022-07-24T16:03:04.465933Z","shell.execute_reply.started":"2022-07-24T16:03:03.452855Z","shell.execute_reply":"2022-07-24T16:03:04.464861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,6))\nsns.kdeplot(df[df['Sex']=='female']['Age'], color='purple', label='female')\nsns.kdeplot(df[df['Sex']=='male']['Age'], color='orange', label='male')\nplt.title('Ages by gender density')\nplt.xticks(rotation='vertical')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-24T16:03:04.467531Z","iopub.execute_input":"2022-07-24T16:03:04.467849Z","iopub.status.idle":"2022-07-24T16:03:04.661351Z","shell.execute_reply.started":"2022-07-24T16:03:04.467819Z","shell.execute_reply":"2022-07-24T16:03:04.660220Z"},"trusted":true},"execution_count":null,"outputs":[]}]}