{"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":" ","metadata":{},"execution_count":null,"outputs":[]},{"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 \nimport pandas as pd \n\nimport matplotlib.pyplot as plt\nplt.style.use(\"seaborn-whitegrid\")\n\nimport seaborn as sns\n\nfrom collections import Counter\nimport warnings\nwarnings.filterwarnings(\"ignore\")\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-28T19:36:07.516345Z","iopub.execute_input":"2022-07-28T19:36:07.516714Z","iopub.status.idle":"2022-07-28T19:36:08.346837Z","shell.execute_reply.started":"2022-07-28T19:36:07.516684Z","shell.execute_reply":"2022-07-28T19:36:08.345567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Bilgilendirme\n \nTitanik kazasının datasetiyni kullanarak yapılan çalışma\n","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/titanic/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/titanic/test.csv\")\ntest_PassengerId = test_df[\"PassengerId\"]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.350372Z","iopub.execute_input":"2022-07-28T19:36:08.351056Z","iopub.status.idle":"2022-07-28T19:36:08.386011Z","shell.execute_reply.started":"2022-07-28T19:36:08.351010Z","shell.execute_reply":"2022-07-28T19:36:08.385088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.columns\n#DataFrame'in satirlarini gormek icin yazılan kod satiri","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.389169Z","iopub.execute_input":"2022-07-28T19:36:08.390124Z","iopub.status.idle":"2022-07-28T19:36:08.399602Z","shell.execute_reply.started":"2022-07-28T19:36:08.390087Z","shell.execute_reply":"2022-07-28T19:36:08.398475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.402298Z","iopub.execute_input":"2022-07-28T19:36:08.403628Z","iopub.status.idle":"2022-07-28T19:36:08.425858Z","shell.execute_reply.started":"2022-07-28T19:36:08.403451Z","shell.execute_reply":"2022-07-28T19:36:08.424698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.427239Z","iopub.execute_input":"2022-07-28T19:36:08.428227Z","iopub.status.idle":"2022-07-28T19:36:08.475765Z","shell.execute_reply.started":"2022-07-28T19:36:08.428195Z","shell.execute_reply":"2022-07-28T19:36:08.474191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Variable Description\nPassengerId \nSurvived\nPclass \nName \nSex \nAge \nSibSp \nParc \nTicket \nFare \nCabin \nEmbarked","metadata":{}},{"cell_type":"code","source":"train_df.info()\n#object=string","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.478543Z","iopub.execute_input":"2022-07-28T19:36:08.479246Z","iopub.status.idle":"2022-07-28T19:36:08.498985Z","shell.execute_reply.started":"2022-07-28T19:36:08.479180Z","shell.execute_reply":"2022-07-28T19:36:08.497776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Variable Analysis","metadata":{}},{"cell_type":"code","source":"def bar_plot(variable):\n    \n    \"\"\"\"\n    input : variable ex:\"Sex\"\n    output : bar plot & value count\n    \n    \"\"\"\n    #feature\n    var = train_df[variable]\n    #deger/ornek sayisi\n    varValue = var.value_counts()\n    \n    #gorsellestirme\n    plt.figure(figsize = (9,3))\n    plt.bar(varValue.index, varValue)\n    plt.xticks(varValue.index, varValue.index.values)\n    plt.ylabel(\"Frequency\")\n    plt.title(variable)\n    plt.show()\n    print(\"{}:\\n {}\".format(variable,varValue))","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.500508Z","iopub.execute_input":"2022-07-28T19:36:08.501131Z","iopub.status.idle":"2022-07-28T19:36:08.508394Z","shell.execute_reply.started":"2022-07-28T19:36:08.501083Z","shell.execute_reply":"2022-07-28T19:36:08.507287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"category1 = [\"Survived\", \"Sex\", \"Pclass\",\"Embarked\",\"SibSp\", \"Parch\",\"Age\" ]\nfor c in category1:\n    bar_plot(c)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:08.509844Z","iopub.execute_input":"2022-07-28T19:36:08.511165Z","iopub.status.idle":"2022-07-28T19:36:10.461061Z","shell.execute_reply.started":"2022-07-28T19:36:08.511119Z","shell.execute_reply":"2022-07-28T19:36:10.459712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"category2= [\"Cabin\", \"Name\",\"Ticket\", \"Age\"]\nfor c in category2:\n     print(\"{}:\\n\".format(train_df[c].value_counts()))\n  ","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:10.464037Z","iopub.execute_input":"2022-07-28T19:36:10.464363Z","iopub.status.idle":"2022-07-28T19:36:10.477394Z","shell.execute_reply.started":"2022-07-28T19:36:10.464335Z","shell.execute_reply":"2022-07-28T19:36:10.476209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_hist(variable):\n    plt.figure(figsize = (9,3))\n    plt.hist(train_df[variable], bins = 10 )\n    plt.xlabel(variable)\n    plt.ylabel(\"Frequency\")\n    plt.title(\"{} distribution with hist\".format(variable))\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:10.482306Z","iopub.execute_input":"2022-07-28T19:36:10.483056Z","iopub.status.idle":"2022-07-28T19:36:10.489741Z","shell.execute_reply.started":"2022-07-28T19:36:10.483020Z","shell.execute_reply":"2022-07-28T19:36:10.488542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numericVar = [\"Fare\", \"Age\", \"PassengerId\"]\nfor n in numericVar:\n    plot_hist(n)\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:10.491451Z","iopub.execute_input":"2022-07-28T19:36:10.492181Z","iopub.status.idle":"2022-07-28T19:36:11.065658Z","shell.execute_reply.started":"2022-07-28T19:36:10.492136Z","shell.execute_reply":"2022-07-28T19:36:11.064807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# # **#Basic Data Analysis**","metadata":{}},{"cell_type":"code","source":"# Pclass vs Survived\n#Insanlarin sinifsal farkliliklari ve hayatta kalma olasiliklari arasindaki iliskiyi inceleyecegiz\n","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.067025Z","iopub.execute_input":"2022-07-28T19:36:11.067553Z","iopub.status.idle":"2022-07-28T19:36:11.070760Z","shell.execute_reply.started":"2022-07-28T19:36:11.067520Z","shell.execute_reply":"2022-07-28T19:36:11.070017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[[\"Pclass\",\"Survived\"]].groupby([\"Survived\"], as_index = False).mean().sort_values(by=\"Pclass\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.072103Z","iopub.execute_input":"2022-07-28T19:36:11.072427Z","iopub.status.idle":"2022-07-28T19:36:11.098569Z","shell.execute_reply.started":"2022-07-28T19:36:11.072397Z","shell.execute_reply":"2022-07-28T19:36:11.096802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[[\"Pclass\",\"Survived\"]].groupby([\"Pclass\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.100145Z","iopub.execute_input":"2022-07-28T19:36:11.102274Z","iopub.status.idle":"2022-07-28T19:36:11.116602Z","shell.execute_reply.started":"2022-07-28T19:36:11.102225Z","shell.execute_reply":"2022-07-28T19:36:11.115635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"train_df[[\"Pclass\",\"Survived\"]].groupby([\"Pclass\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.118027Z","iopub.execute_input":"2022-07-28T19:36:11.118635Z","iopub.status.idle":"2022-07-28T19:36:11.131661Z","shell.execute_reply.started":"2022-07-28T19:36:11.118605Z","shell.execute_reply":"2022-07-28T19:36:11.130463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sex vs survived\ntrain_df[[\"Sex\",\"Survived\"]].groupby([\"Sex\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.133323Z","iopub.execute_input":"2022-07-28T19:36:11.134080Z","iopub.status.idle":"2022-07-28T19:36:11.149016Z","shell.execute_reply.started":"2022-07-28T19:36:11.134029Z","shell.execute_reply":"2022-07-28T19:36:11.148166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pclass vs survived\ntrain_df[[\"Pclass\",\"Survived\"]].groupby([\"Pclass\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.150245Z","iopub.execute_input":"2022-07-28T19:36:11.150804Z","iopub.status.idle":"2022-07-28T19:36:11.170886Z","shell.execute_reply.started":"2022-07-28T19:36:11.150768Z","shell.execute_reply":"2022-07-28T19:36:11.170025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#sibsp vs survived\ntrain_df[[\"SibSp\",\"Survived\"]].groupby([\"SibSp\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.172257Z","iopub.execute_input":"2022-07-28T19:36:11.173337Z","iopub.status.idle":"2022-07-28T19:36:11.192466Z","shell.execute_reply.started":"2022-07-28T19:36:11.173286Z","shell.execute_reply":"2022-07-28T19:36:11.191144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#parch(parent or children) vs survived\ntrain_df[[\"Parch\",\"Survived\"]].groupby([\"Parch\"], as_index = False).mean().sort_values(by=\"Survived\",ascending = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.194371Z","iopub.execute_input":"2022-07-28T19:36:11.195188Z","iopub.status.idle":"2022-07-28T19:36:11.211151Z","shell.execute_reply.started":"2022-07-28T19:36:11.195140Z","shell.execute_reply":"2022-07-28T19:36:11.210119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Outlier Detection**","metadata":{}},{"cell_type":"code","source":"def detect_outliers(df,features):\n    outlier_indices = []\n    \n    for c in features:\n      \n        Q1 = np.percentile(df[c],25)\n        Q3 = np.percentile(df[c],75)\n        IQR = Q3 - Q1\n        outlier_step = IQR * 1.5\n        outlier_list_col = df [(df[c] < Q1 - outlier_step) | (df[c] > Q3 + outlier_step )].index\n        outlier_indices.extend(outlier_list_col)\n    \n    outlier_indices = Counter(outlier_indices)\n        #1 tane outlier degeri varsa kalabilir ancak 2 veya daha fazlaysa onu cikarmak icin bu kod satiri yazildi\n    multiple_outliers = list(i for i, v in outlier_indices.items() if v > 1 )\n    return multiple_outliers","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.212417Z","iopub.execute_input":"2022-07-28T19:36:11.213315Z","iopub.status.idle":"2022-07-28T19:36:11.223147Z","shell.execute_reply.started":"2022-07-28T19:36:11.213267Z","shell.execute_reply":"2022-07-28T19:36:11.222039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.loc[detect_outliers(train_df,[\"SibSp\",\"Fare\",\"PassengerId\"])]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.224540Z","iopub.execute_input":"2022-07-28T19:36:11.224858Z","iopub.status.idle":"2022-07-28T19:36:11.253801Z","shell.execute_reply.started":"2022-07-28T19:36:11.224829Z","shell.execute_reply":"2022-07-28T19:36:11.252652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = train_df.drop(detect_outliers(train_df,[\"Age\",\"SibSp\",\"Parch\",\"Fare\"]))","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.255170Z","iopub.execute_input":"2022-07-28T19:36:11.255495Z","iopub.status.idle":"2022-07-28T19:36:11.265253Z","shell.execute_reply.started":"2022-07-28T19:36:11.255466Z","shell.execute_reply":"2022-07-28T19:36:11.264244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **MISSING VALUE**","metadata":{}},{"cell_type":"code","source":"train_df_len = len(train_df)\ntrain_df = pd.concat([train_df,test_df], axis = 0).reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.266233Z","iopub.execute_input":"2022-07-28T19:36:11.266905Z","iopub.status.idle":"2022-07-28T19:36:11.277805Z","shell.execute_reply.started":"2022-07-28T19:36:11.266861Z","shell.execute_reply":"2022-07-28T19:36:11.276619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.279175Z","iopub.execute_input":"2022-07-28T19:36:11.280120Z","iopub.status.idle":"2022-07-28T19:36:11.298853Z","shell.execute_reply.started":"2022-07-28T19:36:11.280076Z","shell.execute_reply":"2022-07-28T19:36:11.297694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Find Missing Value**","metadata":{}},{"cell_type":"code","source":"train_df.columns[train_df.isnull().any()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.300164Z","iopub.execute_input":"2022-07-28T19:36:11.301273Z","iopub.status.idle":"2022-07-28T19:36:11.310446Z","shell.execute_reply.started":"2022-07-28T19:36:11.301238Z","shell.execute_reply":"2022-07-28T19:36:11.309302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isnull().sum()\n#asagidaki degerler ozelliklerin toplam kac tanesinin kayıip oldugu bilgisi\n#ornegin; 252 adet yolcunun yasi bilinmiyor gibi","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.311869Z","iopub.execute_input":"2022-07-28T19:36:11.312676Z","iopub.status.idle":"2022-07-28T19:36:11.322295Z","shell.execute_reply.started":"2022-07-28T19:36:11.312639Z","shell.execute_reply":"2022-07-28T19:36:11.321482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Fill Missing Value**","metadata":{}},{"cell_type":"code","source":"train_df[train_df[\"Embarked\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.323382Z","iopub.execute_input":"2022-07-28T19:36:11.324291Z","iopub.status.idle":"2022-07-28T19:36:11.346750Z","shell.execute_reply.started":"2022-07-28T19:36:11.324256Z","shell.execute_reply":"2022-07-28T19:36:11.345618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.boxplot(column=\"Fare\", by = \"Embarked\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.353052Z","iopub.execute_input":"2022-07-28T19:36:11.353986Z","iopub.status.idle":"2022-07-28T19:36:11.557437Z","shell.execute_reply.started":"2022-07-28T19:36:11.353923Z","shell.execute_reply":"2022-07-28T19:36:11.556403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[\"Embarked\"] = train_df[\"Embarked\"].fillna(\"C\")\ntrain_df[train_df[\"Embarked\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.558610Z","iopub.execute_input":"2022-07-28T19:36:11.558890Z","iopub.status.idle":"2022-07-28T19:36:11.572173Z","shell.execute_reply.started":"2022-07-28T19:36:11.558865Z","shell.execute_reply":"2022-07-28T19:36:11.570950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df[\"Fare\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.573638Z","iopub.execute_input":"2022-07-28T19:36:11.574105Z","iopub.status.idle":"2022-07-28T19:36:11.598777Z","shell.execute_reply.started":"2022-07-28T19:36:11.574075Z","shell.execute_reply":"2022-07-28T19:36:11.597743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df [\"Fare\"] = train_df [\"Fare\"].fillna( np.mean(train_df[train_df[\"Pclass\"] == 3][\"Fare\"]))\n#3. sinif yolcularin ne kadar odediklerinin ortalamasi ile bos degerler dolduruldu","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.600849Z","iopub.execute_input":"2022-07-28T19:36:11.602041Z","iopub.status.idle":"2022-07-28T19:36:11.613233Z","shell.execute_reply.started":"2022-07-28T19:36:11.601991Z","shell.execute_reply":"2022-07-28T19:36:11.612333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df[\"Fare\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.614575Z","iopub.execute_input":"2022-07-28T19:36:11.615438Z","iopub.status.idle":"2022-07-28T19:36:11.632815Z","shell.execute_reply.started":"2022-07-28T19:36:11.615406Z","shell.execute_reply":"2022-07-28T19:36:11.632105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" ### ****VISULATION","metadata":{}},{"cell_type":"markdown","source":"# Correlation Between Sibsp -- Parch -- Age -- Fare -- Survived","metadata":{}},{"cell_type":"code","source":"list1 = [ \"SibSp\",\"Parch\",\"Age\",\"Fare\",\"Survived\"]\nsns.heatmap(train_df[list1].corr(),annot = True, fmt = \".2f\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.634089Z","iopub.execute_input":"2022-07-28T19:36:11.634825Z","iopub.status.idle":"2022-07-28T19:36:11.921648Z","shell.execute_reply.started":"2022-07-28T19:36:11.634792Z","shell.execute_reply":"2022-07-28T19:36:11.920380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"## SibSp ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.factorplot(x = \"SibSp\", y = \"Survived\",data = train_df, kind = \"bar\", size = 7)\ng.set_ylabels(\"Survived Probability\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:11.923121Z","iopub.execute_input":"2022-07-28T19:36:11.923541Z","iopub.status.idle":"2022-07-28T19:36:12.401300Z","shell.execute_reply.started":"2022-07-28T19:36:11.923495Z","shell.execute_reply":"2022-07-28T19:36:12.400468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# siyah cizgiler standart sapmalari temsil ediyor.","metadata":{}},{"cell_type":"markdown","source":"# # Parch ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.factorplot(x = \"Parch\", y = \"Survived\",data = train_df, kind = \"bar\", size = 7)\ng.set_ylabels(\"Survived Prob\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:12.402488Z","iopub.execute_input":"2022-07-28T19:36:12.402979Z","iopub.status.idle":"2022-07-28T19:36:12.783525Z","shell.execute_reply.started":"2022-07-28T19:36:12.402935Z","shell.execute_reply":"2022-07-28T19:36:12.782432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Pclass ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.factorplot(x = \"Pclass\", y = \"Survived\",data = train_df, kind = \"bar\", size = 7)\ng.set_ylabels(\"Survived Prob\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:12.784673Z","iopub.execute_input":"2022-07-28T19:36:12.785402Z","iopub.status.idle":"2022-07-28T19:36:13.092728Z","shell.execute_reply.started":"2022-07-28T19:36:12.785366Z","shell.execute_reply":"2022-07-28T19:36:13.091297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Age ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.FacetGrid(train_df, col = \"Survived\")\ng.map(sns.distplot, \"Age\", bins = 30)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:13.094132Z","iopub.execute_input":"2022-07-28T19:36:13.094463Z","iopub.status.idle":"2022-07-28T19:36:13.551091Z","shell.execute_reply.started":"2022-07-28T19:36:13.094432Z","shell.execute_reply":"2022-07-28T19:36:13.550015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* 10 yasindan kucuk cocuklarin kurtulma oranlari yuksek\n* Yasli  yolcular cok az oldukari icin iyi bir kurtulma oranina sahipler","metadata":{}},{"cell_type":"markdown","source":"# Pclass ~ Survived ~ Age","metadata":{}},{"cell_type":"code","source":"g = sns.FacetGrid(train_df, col = \"Survived\", row = \"Pclass\", size = 3)\ng.map(plt.hist, \"Age\", bins = 25)\ng.add_legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:13.552582Z","iopub.execute_input":"2022-07-28T19:36:13.552933Z","iopub.status.idle":"2022-07-28T19:36:14.825586Z","shell.execute_reply.started":"2022-07-28T19:36:13.552902Z","shell.execute_reply":"2022-07-28T19:36:14.824738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Embarked ~ Sex ~ Pclass ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.FacetGrid(train_df, row = \"Embarked\", size = 2)\ng.map(sns.pointplot,\"Pclass\",\"Survived\",\"Sex\")\ng.add_legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:14.826887Z","iopub.execute_input":"2022-07-28T19:36:14.827455Z","iopub.status.idle":"2022-07-28T19:36:15.806111Z","shell.execute_reply.started":"2022-07-28T19:36:14.827421Z","shell.execute_reply":"2022-07-28T19:36:15.805276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# *Kadinlar erkeklere oranla daha yüksek hayatta kalma oranına sahipler.","metadata":{}},{"cell_type":"markdown","source":"# ****Embarked ~ Sex ~ Fare ~ Survived","metadata":{}},{"cell_type":"code","source":"g = sns.FacetGrid(train_df, row = \"Embarked\", col = \"Survived\", size = 3)\ng.map(sns.barplot,\"Sex\",\"Fare\")\ng.add_legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:15.807440Z","iopub.execute_input":"2022-07-28T19:36:15.807974Z","iopub.status.idle":"2022-07-28T19:36:17.062905Z","shell.execute_reply.started":"2022-07-28T19:36:15.807929Z","shell.execute_reply":"2022-07-28T19:36:17.061786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fill Missing: Age Feature","metadata":{}},{"cell_type":"code","source":"train_df[train_df[\"Age\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:17.064423Z","iopub.execute_input":"2022-07-28T19:36:17.064847Z","iopub.status.idle":"2022-07-28T19:36:17.087639Z","shell.execute_reply.started":"2022-07-28T19:36:17.064803Z","shell.execute_reply":"2022-07-28T19:36:17.086435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# *Yukaridaki infolara bakarak yasi bilinmeyen yolcularin ortalama yaslari doldurulabilir.","metadata":{}},{"cell_type":"code","source":"sns.factorplot(x = \"Sex\", y = \"Age\", data = train_df, kind = 'box')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:17.089389Z","iopub.execute_input":"2022-07-28T19:36:17.089810Z","iopub.status.idle":"2022-07-28T19:36:17.329165Z","shell.execute_reply.started":"2022-07-28T19:36:17.089769Z","shell.execute_reply":"2022-07-28T19:36:17.328031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **ortadaki cizgi medyani ifade ediyor ve cinsiyet bizim icin ayirt edici bir ozellik degilmis.","metadata":{}},{"cell_type":"code","source":"sns.factorplot(x = \"Sex\", y = \"Age\", hue = \"Pclass\", data = train_df, kind = 'box')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:17.330543Z","iopub.execute_input":"2022-07-28T19:36:17.330916Z","iopub.status.idle":"2022-07-28T19:36:17.705776Z","shell.execute_reply.started":"2022-07-28T19:36:17.330884Z","shell.execute_reply":"2022-07-28T19:36:17.704398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.factorplot(x = \"Parch\", y = \"Age\", data = train_df, kind = 'box')\nsns.factorplot(x = \"SibSp\", y = \"Age\", data = train_df, kind = 'box')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:17.707712Z","iopub.execute_input":"2022-07-28T19:36:17.708391Z","iopub.status.idle":"2022-07-28T19:36:18.345437Z","shell.execute_reply.started":"2022-07-28T19:36:17.708352Z","shell.execute_reply":"2022-07-28T19:36:18.344113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train_df[[\"Age\", \"Sex\", \"SibSp\",\"Parch\",\"Pclass\"]].corr(),annot = True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:18.347084Z","iopub.execute_input":"2022-07-28T19:36:18.347545Z","iopub.status.idle":"2022-07-28T19:36:18.597911Z","shell.execute_reply.started":"2022-07-28T19:36:18.347499Z","shell.execute_reply":"2022-07-28T19:36:18.596762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index_nan_age = list(train_df[\"Age\"][train_df[\"Age\"].isnull()].index)\nfor i in index_nan_age:\n    age_pred = train_df[\"Age\"][((train_df[\"SibSp\"] == train_df.iloc[i][\"SibSp\"]) &(train_df[\"Parch\"] == train_df.iloc[i][\"Parch\"])& (train_df[\"Pclass\"] == train_df.iloc[i][\"Pclass\"]))].median()\n    age_med = train_df[\"Age\"].median()\n    if not np.isnan(age_pred):\n        train_df[\"Age\"].iloc[i] = age_pred\n    else:\n        train_df[\"Age\"].iloc[i] = age_med","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:18.599549Z","iopub.execute_input":"2022-07-28T19:36:18.599866Z","iopub.status.idle":"2022-07-28T19:36:19.084799Z","shell.execute_reply.started":"2022-07-28T19:36:18.599837Z","shell.execute_reply":"2022-07-28T19:36:19.083526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df[\"Age\"].isnull()]","metadata":{"execution":{"iopub.status.busy":"2022-07-28T19:36:21.650156Z","iopub.execute_input":"2022-07-28T19:36:21.652371Z","iopub.status.idle":"2022-07-28T19:36:21.669798Z","shell.execute_reply.started":"2022-07-28T19:36:21.652300Z","shell.execute_reply":"2022-07-28T19:36:21.668745Z"},"trusted":true},"execution_count":null,"outputs":[]}]}