{"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":"#  <center>Titanikda suzishga tayyormisiz?⚓️🛳\n<center>Machine Leaning dasturchilari uchun Titanik bu \"Hello World\" kabi sodda🔭","metadata":{"execution":{"iopub.status.busy":"2022-05-24T05:48:32.755999Z","iopub.execute_input":"2022-05-24T05:48:32.75681Z","iopub.status.idle":"2022-05-24T05:48:32.78783Z","shell.execute_reply.started":"2022-05-24T05:48:32.756711Z","shell.execute_reply":"2022-05-24T05:48:32.786792Z"}}},{"cell_type":"markdown","source":"<table>\n  <tr><td>\n    <img src=\"https://miro.medium.com/max/1400/1*Q59ONUgBl159KgMJvghShA.jpeg\"\nalt=\"Fashion MNIST sprite\"  length = \"1500\" width=\"1500\">\n  </td></tr>\n  <tr><td align=\"center\">\n    <b>Figure 1. Diabetes Classification Using ANNs\n  </td></tr>\n</table>","metadata":{}},{"cell_type":"markdown","source":"> Muammo qanday? \n\n> Vazifamiz,yo‘lovchilar ro‘yxatini olib, yo’lovchilarning qaysi biri omon qolgan va kimlar tirik qolmaganini aniqlash uchun ehtimollikni bashorat qilish.","metadata":{}},{"cell_type":"markdown","source":"# 1. Kutubxona va ma'lumotlarni yuklab olamiz📬","metadata":{}},{"cell_type":"code","source":"# pandas kutubxonasini import qilib olamiz!\n# Pandas ma'lumotlarni tozalash va tahlil qilish uchun \n# ishlatiladigan Data Science va Machine Learning 'da eng ko'p qo'llaniladigan kutubxona.\nimport pandas as pd\n\n# musobaqa tomonidan taqdim etilgan data'larni o'zgaruvchi ochib tenglab olamiz\ntrain = pd.read_csv('../input/titanic/train.csv')\ntest = pd.read_csv('../input/titanic/test.csv')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-17T15:24:24.485335Z","iopub.execute_input":"2022-07-17T15:24:24.485671Z","iopub.status.idle":"2022-07-17T15:24:24.541210Z","shell.execute_reply.started":"2022-07-17T15:24:24.485590Z","shell.execute_reply":"2022-07-17T15:24:24.540561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# head funksiyasi yordamida train data'mizning 10 ta qatorini ko'ramiz\ntrain.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.542894Z","iopub.execute_input":"2022-07-17T15:24:24.543145Z","iopub.status.idle":"2022-07-17T15:24:24.567649Z","shell.execute_reply.started":"2022-07-17T15:24:24.543112Z","shell.execute_reply":"2022-07-17T15:24:24.566846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# head funksiyasi yordamida test data'mizning \n# boshidagi 5 ta qatorini ko'rib olamiz\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.569929Z","iopub.execute_input":"2022-07-17T15:24:24.570493Z","iopub.status.idle":"2022-07-17T15:24:24.586323Z","shell.execute_reply.started":"2022-07-17T15:24:24.570453Z","shell.execute_reply":"2022-07-17T15:24:24.585705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# shape funksiyasi train data ichidagi qatorlar va ustunlar sonini \n# chop etib beradi train data 'miz ichida 891 qator \n# va 12 ustundan iborat ma'lumot bor!\ntrain.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.588046Z","iopub.execute_input":"2022-07-17T15:24:24.588393Z","iopub.status.idle":"2022-07-17T15:24:24.593842Z","shell.execute_reply.started":"2022-07-17T15:24:24.588357Z","shell.execute_reply":"2022-07-17T15:24:24.593180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# shape funksiyasi test data ichidagi qatorlar \n# va ustunlar sonini chop etib beradi\n# test data 'miz ichida 418 qator va 11 ustundan iborat \n# ma'lumot bor!\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.594974Z","iopub.execute_input":"2022-07-17T15:24:24.595737Z","iopub.status.idle":"2022-07-17T15:24:24.602660Z","shell.execute_reply.started":"2022-07-17T15:24:24.595697Z","shell.execute_reply":"2022-07-17T15:24:24.601935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train data'ning har bir ustulari haqida ma'lumot \n# turlarini birma-bir ko'rib chiqamiz\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.603999Z","iopub.execute_input":"2022-07-17T15:24:24.604846Z","iopub.status.idle":"2022-07-17T15:24:24.626848Z","shell.execute_reply.started":"2022-07-17T15:24:24.604810Z","shell.execute_reply":"2022-07-17T15:24:24.626051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test data'ning har bir ustulari haqida ma'lumot \n# turlarini birma-bir ko'rib chiqamiz\ntest.info()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.628260Z","iopub.execute_input":"2022-07-17T15:24:24.628518Z","iopub.status.idle":"2022-07-17T15:24:24.640272Z","shell.execute_reply.started":"2022-07-17T15:24:24.628484Z","shell.execute_reply":"2022-07-17T15:24:24.639609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Yetishmayotgan qiymatlar bilan ishlaymiz⁉️\nBu eng murakkab qismlardan biridir, negaki bizda yoqotilgan qiymatlar bo'lib biz ularni tiklashga harakat qilishimiz kerak. Yetishmayotgan ma'lumotlar tushunchasi: bu ko'rib chiqilayotgan kuzatish uchun o'zgaruvchi olinmagan ma'lumotldir. Maqolalarga ko'ra, yetishmayotgan ma'lumotlar tahlilning statistik kuchini pasaytiradi, bu esa natijalarning haqiqiyligini buzishi mumkin.\n\n(Finding the missing values)","metadata":{}},{"cell_type":"code","source":"# train data'dagi yetishmayotgan qiymatlarni sonini topish\n# Age ustunida 177 o'rinda yo'lovchilar yoshlari ko'rsatilmagan\n# Cabin ustunida 687 va Embarked ustunida esa \n# 2 o'rinda yetishmayotgan qiymatlar mavjud\ntrain.isnull().sum()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.641991Z","iopub.execute_input":"2022-07-17T15:24:24.642840Z","iopub.status.idle":"2022-07-17T15:24:24.653002Z","shell.execute_reply.started":"2022-07-17T15:24:24.642799Z","shell.execute_reply":"2022-07-17T15:24:24.652317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test data'dagi yetishmayotgan qiymatlarni sonini topish\ntest.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.654022Z","iopub.execute_input":"2022-07-17T15:24:24.654345Z","iopub.status.idle":"2022-07-17T15:24:24.663089Z","shell.execute_reply.started":"2022-07-17T15:24:24.654309Z","shell.execute_reply":"2022-07-17T15:24:24.662249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. Ma'lumotlarni vizual ko'rinishga olib kelamiz📈📊\nBu shunchaki ajoyib, siz jarayonni vizual kuzatishingiz mumkin!🥳🤩\n\n(Data Vizualization)","metadata":{}},{"cell_type":"code","source":"# data visualization uchun matplotlib va \n# seaborn libary'larni import qilib olamiz\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nsns.set() ","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:24.664382Z","iopub.execute_input":"2022-07-17T15:24:24.664954Z","iopub.status.idle":"2022-07-17T15:24:25.469731Z","shell.execute_reply.started":"2022-07-17T15:24:24.664826Z","shell.execute_reply":"2022-07-17T15:24:25.468916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# bar chart graph uchun seaborn libary 'ni \n# import qilib olamiz\nimport seaborn as sns\nsns.set() ","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:25.472812Z","iopub.execute_input":"2022-07-17T15:24:25.473008Z","iopub.status.idle":"2022-07-17T15:24:25.477361Z","shell.execute_reply.started":"2022-07-17T15:24:25.472982Z","shell.execute_reply":"2022-07-17T15:24:25.476169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# bar_chart nomli funksiya ochib olamiz. \n# Biz Survived (yaralangan) yo'lovchilar va dead (vafot etgan) \n# yo'lovchilarning grafiklarini tuzib chiqmoqchimiz\n\ndef bar_chart(feature):\n    survived = train[train['Survived']==1][feature].value_counts()\n    dead = train[train['Survived']==0][feature].value_counts()\n    df = pd.DataFrame([survived,dead])\n    df.index = ['Survived','Dead']\n    df.plot(kind='bar',stacked=True, figsize=(10,5))\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:25.479150Z","iopub.execute_input":"2022-07-17T15:24:25.479643Z","iopub.status.idle":"2022-07-17T15:24:25.487459Z","shell.execute_reply.started":"2022-07-17T15:24:25.479604Z","shell.execute_reply":"2022-07-17T15:24:25.486204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Olovrang-ayollar, ko'k-erkaklar.\n# Demak, kemada avval ayollar ko'proq yaralanganlar, \n# vafot etish ko'rsatkichi esa \n# erkaklarda nisbatan ko'p ekan\n\nbar_chart('Sex')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:25.488951Z","iopub.execute_input":"2022-07-17T15:24:25.489298Z","iopub.status.idle":"2022-07-17T15:24:25.734754Z","shell.execute_reply.started":"2022-07-17T15:24:25.489264Z","shell.execute_reply":"2022-07-17T15:24:25.734094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Kemada umumiy hisobda uchta klass bo'lgan edi. \n# Yaralangan insonlar soni deyarli teng, vafot etish esa \n# asosan uchinchi klassda yuqori bo'lgan ekan\n\nbar_chart('Pclass')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:25.736025Z","iopub.execute_input":"2022-07-17T15:24:25.736426Z","iopub.status.idle":"2022-07-17T15:24:25.949749Z","shell.execute_reply.started":"2022-07-17T15:24:25.736388Z","shell.execute_reply":"2022-07-17T15:24:25.949053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bar_chart('SibSp')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:25.950862Z","iopub.execute_input":"2022-07-17T15:24:25.951305Z","iopub.status.idle":"2022-07-17T15:24:26.208074Z","shell.execute_reply.started":"2022-07-17T15:24:25.951257Z","shell.execute_reply":"2022-07-17T15:24:26.207392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bar_chart('Parch')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.209404Z","iopub.execute_input":"2022-07-17T15:24:26.209802Z","iopub.status.idle":"2022-07-17T15:24:26.464691Z","shell.execute_reply.started":"2022-07-17T15:24:26.209763Z","shell.execute_reply":"2022-07-17T15:24:26.464019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Embarked sayohatchining qayerdan minganini bildiradi.\n# Embark uchun uchta mumkin bo'lgan qiymat mavjud - \n# Sautgempton, Cherbourg va Kvinstaun.\n# (Southampton, Cherbourg, Queenstown) \n# Odamlarning 70% dan ortig'i Sautgemptondan uchgan. 20% dan sal kamrog'i \n# Cherbourgdan, qolganlari esa Kvinstaundan.\nbar_chart('Embarked')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.467882Z","iopub.execute_input":"2022-07-17T15:24:26.468085Z","iopub.status.idle":"2022-07-17T15:24:26.681877Z","shell.execute_reply.started":"2022-07-17T15:24:26.468060Z","shell.execute_reply":"2022-07-17T15:24:26.681076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.683277Z","iopub.execute_input":"2022-07-17T15:24:26.683520Z","iopub.status.idle":"2022-07-17T15:24:26.697303Z","shell.execute_reply.started":"2022-07-17T15:24:26.683487Z","shell.execute_reply":"2022-07-17T15:24:26.696637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.698824Z","iopub.execute_input":"2022-07-17T15:24:26.699304Z","iopub.status.idle":"2022-07-17T15:24:26.720676Z","shell.execute_reply.started":"2022-07-17T15:24:26.699266Z","shell.execute_reply":"2022-07-17T15:24:26.719944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_test_data = [train, test] \n# train va test dataset'larini birlashtirish\n\nfor dataset in train_test_data:\n    dataset['Title'] = dataset['Name'].str.extract(' ([A-Za-z]+)\\.', expand=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.723209Z","iopub.execute_input":"2022-07-17T15:24:26.723638Z","iopub.status.idle":"2022-07-17T15:24:26.732108Z","shell.execute_reply.started":"2022-07-17T15:24:26.723600Z","shell.execute_reply":"2022-07-17T15:24:26.731299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['Title'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.733873Z","iopub.execute_input":"2022-07-17T15:24:26.734310Z","iopub.status.idle":"2022-07-17T15:24:26.743566Z","shell.execute_reply.started":"2022-07-17T15:24:26.734267Z","shell.execute_reply":"2022-07-17T15:24:26.742802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test data'dagi Title qatorlarining sonini aniqlash\ntest['Title'].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.744951Z","iopub.execute_input":"2022-07-17T15:24:26.745209Z","iopub.status.idle":"2022-07-17T15:24:26.752462Z","shell.execute_reply.started":"2022-07-17T15:24:26.745176Z","shell.execute_reply":"2022-07-17T15:24:26.751588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3.1 Ma'lumotlarni vizual ko'rinshga olib kelamiz","metadata":{}},{"cell_type":"markdown","source":"Yuqorida siz bilan ushbu jarayonlarni train data uchun qo'llagan edik. Endi test data 'da sinab ko'rmoqchimiz!","metadata":{}},{"cell_type":"code","source":"title_mapping = {\"Mr\": 0, \"Miss\": 1, \"Mrs\": 2, \n                 \"Master\": 3, \"Dr\": 3, \"Rev\": 3, \"Col\": 3, \"Major\": 3, \"Mlle\": 3,\"Countess\": 3,\n                 \"Ms\": 3, \"Lady\": 3, \"Jonkheer\": 3, \"Don\": 3, \"Dona\" : 3, \"Mme\": 3,\"Capt\": 3,\"Sir\": 3 }\nfor dataset in train_test_data:\n    dataset['Title'] = dataset['Title'].map(title_mapping)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.754050Z","iopub.execute_input":"2022-07-17T15:24:26.754390Z","iopub.status.idle":"2022-07-17T15:24:26.763655Z","shell.execute_reply.started":"2022-07-17T15:24:26.754356Z","shell.execute_reply":"2022-07-17T15:24:26.762911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.764668Z","iopub.execute_input":"2022-07-17T15:24:26.764932Z","iopub.status.idle":"2022-07-17T15:24:26.783754Z","shell.execute_reply.started":"2022-07-17T15:24:26.764897Z","shell.execute_reply":"2022-07-17T15:24:26.783050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.785137Z","iopub.execute_input":"2022-07-17T15:24:26.785472Z","iopub.status.idle":"2022-07-17T15:24:26.801800Z","shell.execute_reply.started":"2022-07-17T15:24:26.785438Z","shell.execute_reply":"2022-07-17T15:24:26.801025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bar_chart('Title')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:26.803123Z","iopub.execute_input":"2022-07-17T15:24:26.803392Z","iopub.status.idle":"2022-07-17T15:24:27.027105Z","shell.execute_reply.started":"2022-07-17T15:24:26.803356Z","shell.execute_reply":"2022-07-17T15:24:27.026417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# delete unnecessary feature from dataset\ntrain.drop('Name', axis=1, inplace=True)\ntest.drop('Name', axis=1, inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.028425Z","iopub.execute_input":"2022-07-17T15:24:27.028837Z","iopub.status.idle":"2022-07-17T15:24:27.036634Z","shell.execute_reply.started":"2022-07-17T15:24:27.028797Z","shell.execute_reply":"2022-07-17T15:24:27.035968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.037971Z","iopub.execute_input":"2022-07-17T15:24:27.038254Z","iopub.status.idle":"2022-07-17T15:24:27.057098Z","shell.execute_reply.started":"2022-07-17T15:24:27.038218Z","shell.execute_reply":"2022-07-17T15:24:27.055727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.058438Z","iopub.execute_input":"2022-07-17T15:24:27.058620Z","iopub.status.idle":"2022-07-17T15:24:27.076952Z","shell.execute_reply.started":"2022-07-17T15:24:27.058597Z","shell.execute_reply":"2022-07-17T15:24:27.075796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sex_mapping = {\"male\": 0, \"female\": 1}\nfor dataset in train_test_data:\n    dataset['Sex'] = dataset['Sex'].map(sex_mapping)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.079036Z","iopub.execute_input":"2022-07-17T15:24:27.079484Z","iopub.status.idle":"2022-07-17T15:24:27.086041Z","shell.execute_reply.started":"2022-07-17T15:24:27.079447Z","shell.execute_reply":"2022-07-17T15:24:27.085365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bar_chart('Sex')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.087478Z","iopub.execute_input":"2022-07-17T15:24:27.087783Z","iopub.status.idle":"2022-07-17T15:24:27.290868Z","shell.execute_reply.started":"2022-07-17T15:24:27.087695Z","shell.execute_reply":"2022-07-17T15:24:27.290208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.293034Z","iopub.execute_input":"2022-07-17T15:24:27.293532Z","iopub.status.idle":"2022-07-17T15:24:27.308659Z","shell.execute_reply.started":"2022-07-17T15:24:27.293494Z","shell.execute_reply":"2022-07-17T15:24:27.308025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# yetishmayotgan yoshni har bir nom uchun o'rtacha\n# yosh bilan to'ldiring (Mr, Mrs, Miss, Others)\ntrain[\"Age\"].fillna(train.groupby(\"Title\")[\"Age\"].transform(\"median\"), inplace=True)\ntest[\"Age\"].fillna(test.groupby(\"Title\")[\"Age\"].transform(\"median\"), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.310200Z","iopub.execute_input":"2022-07-17T15:24:27.310701Z","iopub.status.idle":"2022-07-17T15:24:27.321287Z","shell.execute_reply.started":"2022-07-17T15:24:27.310663Z","shell.execute_reply":"2022-07-17T15:24:27.320712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train data'ning boshidagi 30 qatorni\n# to'ldirgan holda chop etish\ntrain.head(30)\ntrain.groupby(\"Title\")[\"Age\"].transform(\"median\")","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.322607Z","iopub.execute_input":"2022-07-17T15:24:27.322868Z","iopub.status.idle":"2022-07-17T15:24:27.335175Z","shell.execute_reply.started":"2022-07-17T15:24:27.322831Z","shell.execute_reply":"2022-07-17T15:24:27.334450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# yosh oralig'ida zararlangan va vafot etganlarni ko'rish\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\n \nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.341300Z","iopub.execute_input":"2022-07-17T15:24:27.341670Z","iopub.status.idle":"2022-07-17T15:24:27.797841Z","shell.execute_reply.started":"2022-07-17T15:24:27.341641Z","shell.execute_reply":"2022-07-17T15:24:27.797200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 0 dan 20 yosh oralig'idagi insonlarning zararlanish \n# va vafot etishlarini ko'rish\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(0, 20)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:27.798921Z","iopub.execute_input":"2022-07-17T15:24:27.800323Z","iopub.status.idle":"2022-07-17T15:24:28.295495Z","shell.execute_reply.started":"2022-07-17T15:24:27.800275Z","shell.execute_reply":"2022-07-17T15:24:28.293737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 20 yoshdan 30 yoshgacha bo'lganlarning \n# zararlanish va vafot etish ko'rsatkichlari\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(20, 30)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:28.296865Z","iopub.execute_input":"2022-07-17T15:24:28.297119Z","iopub.status.idle":"2022-07-17T15:24:28.883803Z","shell.execute_reply.started":"2022-07-17T15:24:28.297085Z","shell.execute_reply":"2022-07-17T15:24:28.883140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 30 yoshdan 40 yoshgacha bo'lganlarning\n# zararlanish va vafot etish ko'rsatkichlari\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(30, 40)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:28.886121Z","iopub.execute_input":"2022-07-17T15:24:28.886385Z","iopub.status.idle":"2022-07-17T15:24:29.360361Z","shell.execute_reply.started":"2022-07-17T15:24:28.886357Z","shell.execute_reply":"2022-07-17T15:24:29.358527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 40 yoshdan 60 yoshgacha bo'lganlarning\n# zararlanish va vafot etish ko'rsatkichlari\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(40, 60)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:29.361994Z","iopub.execute_input":"2022-07-17T15:24:29.362336Z","iopub.status.idle":"2022-07-17T15:24:29.861936Z","shell.execute_reply.started":"2022-07-17T15:24:29.362281Z","shell.execute_reply":"2022-07-17T15:24:29.861146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(40, 60)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:29.864120Z","iopub.execute_input":"2022-07-17T15:24:29.864607Z","iopub.status.idle":"2022-07-17T15:24:30.362848Z","shell.execute_reply.started":"2022-07-17T15:24:29.864567Z","shell.execute_reply":"2022-07-17T15:24:30.362180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 60 yoshdan 80 yoshgacha bo'lganlarning \n# zararlanish va vafot etish ko'rsatkichlari\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Age',shade= True)\nfacet.set(xlim=(0, train['Age'].max()))\nfacet.add_legend()\nplt.xlim(60)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.364124Z","iopub.execute_input":"2022-07-17T15:24:30.364543Z","iopub.status.idle":"2022-07-17T15:24:30.855087Z","shell.execute_reply.started":"2022-07-17T15:24:30.364498Z","shell.execute_reply":"2022-07-17T15:24:30.852228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.856580Z","iopub.execute_input":"2022-07-17T15:24:30.857115Z","iopub.status.idle":"2022-07-17T15:24:30.879437Z","shell.execute_reply.started":"2022-07-17T15:24:30.857067Z","shell.execute_reply":"2022-07-17T15:24:30.878719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.info()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.880662Z","iopub.execute_input":"2022-07-17T15:24:30.881085Z","iopub.status.idle":"2022-07-17T15:24:30.894833Z","shell.execute_reply.started":"2022-07-17T15:24:30.881046Z","shell.execute_reply":"2022-07-17T15:24:30.894152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dataset in train_test_data:\n    dataset.loc[ dataset['Age'] <= 16, 'Age'] = 0\n    dataset.loc[(dataset['Age'] > 16) & (dataset['Age'] <= 26), 'Age'] = 1\n    dataset.loc[(dataset['Age'] > 26) & (dataset['Age'] <= 36), 'Age'] = 2\n    dataset.loc[(dataset['Age'] > 36) & (dataset['Age'] <= 62), 'Age'] = 3\n    dataset.loc[ dataset['Age'] > 62, 'Age'] = 1","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.895973Z","iopub.execute_input":"2022-07-17T15:24:30.898310Z","iopub.status.idle":"2022-07-17T15:24:30.913623Z","shell.execute_reply.started":"2022-07-17T15:24:30.898273Z","shell.execute_reply":"2022-07-17T15:24:30.912940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.914868Z","iopub.execute_input":"2022-07-17T15:24:30.915443Z","iopub.status.idle":"2022-07-17T15:24:30.930541Z","shell.execute_reply.started":"2022-07-17T15:24:30.915405Z","shell.execute_reply":"2022-07-17T15:24:30.929823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bar_chart('Age')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:30.931693Z","iopub.execute_input":"2022-07-17T15:24:30.932075Z","iopub.status.idle":"2022-07-17T15:24:31.159896Z","shell.execute_reply.started":"2022-07-17T15:24:30.932038Z","shell.execute_reply":"2022-07-17T15:24:31.159219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Embarked ustunidagi missing qiymatlarni to'ldirish uchun chipta \n# class'laridan foydalanamiz  \nPclass1 = train[train['Pclass']==1]['Embarked'].value_counts()\nPclass2 = train[train['Pclass']==2]['Embarked'].value_counts()\nPclass3 = train[train['Pclass']==3]['Embarked'].value_counts()\ndf = pd.DataFrame([Pclass1, Pclass2, Pclass3])\ndf.index = ['1st class','2nd class', '3rd class']\ndf.plot(kind='bar',stacked=True, figsize=(10,5))","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.160974Z","iopub.execute_input":"2022-07-17T15:24:31.161651Z","iopub.status.idle":"2022-07-17T15:24:31.395147Z","shell.execute_reply.started":"2022-07-17T15:24:31.161611Z","shell.execute_reply":"2022-07-17T15:24:31.394456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# bar_chart dagi ma'lumotdan foydalanib biz Embarked dagi missing value ni to'ldiramiz\nfor dataset in train_test_data:\n    dataset['Embarked'] = dataset['Embarked'].fillna('S')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.396921Z","iopub.execute_input":"2022-07-17T15:24:31.397337Z","iopub.status.idle":"2022-07-17T15:24:31.403258Z","shell.execute_reply.started":"2022-07-17T15:24:31.397298Z","shell.execute_reply":"2022-07-17T15:24:31.402484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.404666Z","iopub.execute_input":"2022-07-17T15:24:31.404979Z","iopub.status.idle":"2022-07-17T15:24:31.421202Z","shell.execute_reply.started":"2022-07-17T15:24:31.404941Z","shell.execute_reply":"2022-07-17T15:24:31.420335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Embarked ustunidagi S, C, Q qiymatlarini almashtirib olamiz\nembarked_mapping = {\"S\": 0, \"C\": 1, \"Q\": 2}\nfor dataset in train_test_data:\n    dataset['Embarked'] = dataset['Embarked'].map(embarked_mapping)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.422580Z","iopub.execute_input":"2022-07-17T15:24:31.423006Z","iopub.status.idle":"2022-07-17T15:24:31.431659Z","shell.execute_reply.started":"2022-07-17T15:24:31.422966Z","shell.execute_reply":"2022-07-17T15:24:31.430865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# yetishmayotgan tarifni har bir Pclass uchun\n# o'rtacha tarif bilan to'ldirib olamiz\ntrain[\"Fare\"].fillna(train.groupby(\"Pclass\")[\"Fare\"].transform(\"median\"), inplace=True)\ntest[\"Fare\"].fillna(test.groupby(\"Pclass\")[\"Fare\"].transform(\"median\"), inplace=True)\ntrain.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.433102Z","iopub.execute_input":"2022-07-17T15:24:31.433434Z","iopub.status.idle":"2022-07-17T15:24:31.455289Z","shell.execute_reply.started":"2022-07-17T15:24:31.433396Z","shell.execute_reply":"2022-07-17T15:24:31.454645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Qaysi class dan foydalangan yo'lovchilar \n# ko'proq vafot etganliklarini aniqlaymiz\nfacet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Fare',shade= True)\nfacet.set(xlim=(0, train['Fare'].max()))\nfacet.add_legend()  \n \nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.456110Z","iopub.execute_input":"2022-07-17T15:24:31.456397Z","iopub.status.idle":"2022-07-17T15:24:31.901666Z","shell.execute_reply.started":"2022-07-17T15:24:31.456363Z","shell.execute_reply":"2022-07-17T15:24:31.901011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Fare',shade= True)\nfacet.set(xlim=(0, train['Fare'].max()))\nfacet.add_legend()\nplt.xlim(0, 20)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:31.903048Z","iopub.execute_input":"2022-07-17T15:24:31.903315Z","iopub.status.idle":"2022-07-17T15:24:32.396706Z","shell.execute_reply.started":"2022-07-17T15:24:31.903279Z","shell.execute_reply":"2022-07-17T15:24:32.394815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Fare',shade= True)\nfacet.set(xlim=(0, train['Fare'].max()))\nfacet.add_legend()\nplt.xlim(0, 30)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:32.398174Z","iopub.execute_input":"2022-07-17T15:24:32.398432Z","iopub.status.idle":"2022-07-17T15:24:32.889425Z","shell.execute_reply.started":"2022-07-17T15:24:32.398397Z","shell.execute_reply":"2022-07-17T15:24:32.885376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'Fare',shade= True)\nfacet.set(xlim=(0, train['Fare'].max()))\nfacet.add_legend()\nplt.xlim(0)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:32.891027Z","iopub.execute_input":"2022-07-17T15:24:32.891529Z","iopub.status.idle":"2022-07-17T15:24:33.557125Z","shell.execute_reply.started":"2022-07-17T15:24:32.891486Z","shell.execute_reply":"2022-07-17T15:24:33.556450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# bizga berilgan numerical chipta narxlarini \n# kategorik narxlarga o'girib olamiz\nfor dataset in train_test_data:\n    dataset.loc[ dataset['Fare'] <= 17, 'Fare'] = 0\n    dataset.loc[(dataset['Fare'] > 17) & (dataset['Fare'] <= 30), 'Fare'] = 1\n    dataset.loc[(dataset['Fare'] > 30) & (dataset['Fare'] <= 100), 'Fare'] = 2\n    dataset.loc[ dataset['Fare'] > 100, 'Fare'] = 3","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.558375Z","iopub.execute_input":"2022-07-17T15:24:33.558617Z","iopub.status.idle":"2022-07-17T15:24:33.572778Z","shell.execute_reply.started":"2022-07-17T15:24:33.558583Z","shell.execute_reply":"2022-07-17T15:24:33.571831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.574198Z","iopub.execute_input":"2022-07-17T15:24:33.574814Z","iopub.status.idle":"2022-07-17T15:24:33.588829Z","shell.execute_reply.started":"2022-07-17T15:24:33.574774Z","shell.execute_reply":"2022-07-17T15:24:33.587911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.Cabin.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.590113Z","iopub.execute_input":"2022-07-17T15:24:33.590503Z","iopub.status.idle":"2022-07-17T15:24:33.601598Z","shell.execute_reply.started":"2022-07-17T15:24:33.590467Z","shell.execute_reply":"2022-07-17T15:24:33.600835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dataset in train_test_data:\n    dataset['Cabin'] = dataset['Cabin'].str[:1]\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.602804Z","iopub.execute_input":"2022-07-17T15:24:33.603660Z","iopub.status.idle":"2022-07-17T15:24:33.609915Z","shell.execute_reply.started":"2022-07-17T15:24:33.603620Z","shell.execute_reply":"2022-07-17T15:24:33.609181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Pclass1 = train[train['Pclass']==1]['Cabin'].value_counts()\nPclass2 = train[train['Pclass']==2]['Cabin'].value_counts()\nPclass3 = train[train['Pclass']==3]['Cabin'].value_counts()\ndf = pd.DataFrame([Pclass1, Pclass2, Pclass3])\ndf.index = ['1st class','2nd class', '3rd class']\ndf.plot(kind='bar',stacked=True, figsize=(10,5))\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.611129Z","iopub.execute_input":"2022-07-17T15:24:33.611506Z","iopub.status.idle":"2022-07-17T15:24:33.916788Z","shell.execute_reply.started":"2022-07-17T15:24:33.611467Z","shell.execute_reply":"2022-07-17T15:24:33.916115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cabin_mapping = {\"A\": 0, \"B\": 0.4, \"C\": 0.8, \"D\": 1.2, \"E\": 1.6, \"F\": 2, \"G\": 2.4, \"T\": 2.8}\nfor dataset in train_test_data:\n    dataset['Cabin'] = dataset['Cabin'].map(cabin_mapping)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.917931Z","iopub.execute_input":"2022-07-17T15:24:33.918590Z","iopub.status.idle":"2022-07-17T15:24:33.927055Z","shell.execute_reply.started":"2022-07-17T15:24:33.918545Z","shell.execute_reply":"2022-07-17T15:24:33.926401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# fill missing Fare with median fare for each Pclass\ntrain[\"Cabin\"].fillna(train.groupby(\"Pclass\")[\"Cabin\"].transform(\"median\"), inplace=True)\ntest[\"Cabin\"].fillna(test.groupby(\"Pclass\")[\"Cabin\"].transform(\"median\"), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.929741Z","iopub.execute_input":"2022-07-17T15:24:33.929970Z","iopub.status.idle":"2022-07-17T15:24:33.938936Z","shell.execute_reply.started":"2022-07-17T15:24:33.929933Z","shell.execute_reply":"2022-07-17T15:24:33.938288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"FamilySize\"] = train[\"SibSp\"] + train[\"Parch\"] + 1\ntest[\"FamilySize\"] = test[\"SibSp\"] + test[\"Parch\"] + 1\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.941112Z","iopub.execute_input":"2022-07-17T15:24:33.941698Z","iopub.status.idle":"2022-07-17T15:24:33.949928Z","shell.execute_reply.started":"2022-07-17T15:24:33.941658Z","shell.execute_reply":"2022-07-17T15:24:33.949140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"facet = sns.FacetGrid(train, hue=\"Survived\",aspect=4)\nfacet.map(sns.kdeplot,'FamilySize',shade= True)\nfacet.set(xlim=(0, train['FamilySize'].max()))\nfacet.add_legend()\nplt.xlim(0)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:33.951304Z","iopub.execute_input":"2022-07-17T15:24:33.951964Z","iopub.status.idle":"2022-07-17T15:24:34.427742Z","shell.execute_reply.started":"2022-07-17T15:24:33.951925Z","shell.execute_reply":"2022-07-17T15:24:34.427015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"family_mapping = {1: 0, 2: 0.4, 3: 0.8, 4: 1.2, 5: 1.6, 6: 2, 7: 2.4, 8: 2.8, 9: 3.2, 10: 3.6, 11: 4}\nfor dataset in train_test_data:\n    dataset['FamilySize'] = dataset['FamilySize'].map(family_mapping)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.428914Z","iopub.execute_input":"2022-07-17T15:24:34.429235Z","iopub.status.idle":"2022-07-17T15:24:34.436092Z","shell.execute_reply.started":"2022-07-17T15:24:34.429198Z","shell.execute_reply":"2022-07-17T15:24:34.435392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.437371Z","iopub.execute_input":"2022-07-17T15:24:34.438034Z","iopub.status.idle":"2022-07-17T15:24:34.456859Z","shell.execute_reply.started":"2022-07-17T15:24:34.437994Z","shell.execute_reply":"2022-07-17T15:24:34.456000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.459201Z","iopub.execute_input":"2022-07-17T15:24:34.459676Z","iopub.status.idle":"2022-07-17T15:24:34.474860Z","shell.execute_reply.started":"2022-07-17T15:24:34.459639Z","shell.execute_reply":"2022-07-17T15:24:34.473854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features_drop = ['Ticket', 'SibSp', 'Parch']\ntrain = train.drop(features_drop, axis=1)\ntest = test.drop(features_drop, axis=1)\ntrain = train.drop(['PassengerId'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.476278Z","iopub.execute_input":"2022-07-17T15:24:34.476540Z","iopub.status.idle":"2022-07-17T15:24:34.486031Z","shell.execute_reply.started":"2022-07-17T15:24:34.476503Z","shell.execute_reply":"2022-07-17T15:24:34.485341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = train.drop('Survived', axis=1)\ntarget = train['Survived']\n\ntrain_data.shape, target.shape\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.487466Z","iopub.execute_input":"2022-07-17T15:24:34.487720Z","iopub.status.idle":"2022-07-17T15:24:34.495064Z","shell.execute_reply.started":"2022-07-17T15:24:34.487680Z","shell.execute_reply":"2022-07-17T15:24:34.494315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.496533Z","iopub.execute_input":"2022-07-17T15:24:34.497086Z","iopub.status.idle":"2022-07-17T15:24:34.513948Z","shell.execute_reply.started":"2022-07-17T15:24:34.497048Z","shell.execute_reply":"2022-07-17T15:24:34.513226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Model","metadata":{}},{"cell_type":"code","source":"# Yuklash Classifier Modullarini\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.svm import SVC\n\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.515656Z","iopub.execute_input":"2022-07-17T15:24:34.516552Z","iopub.status.idle":"2022-07-17T15:24:34.807414Z","shell.execute_reply.started":"2022-07-17T15:24:34.516514Z","shell.execute_reply":"2022-07-17T15:24:34.806627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.808922Z","iopub.execute_input":"2022-07-17T15:24:34.809242Z","iopub.status.idle":"2022-07-17T15:24:34.820682Z","shell.execute_reply.started":"2022-07-17T15:24:34.809202Z","shell.execute_reply":"2022-07-17T15:24:34.819648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import KFold\nfrom sklearn.model_selection import cross_val_score\nk_fold = KFold(n_splits=10, shuffle=True, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.822137Z","iopub.execute_input":"2022-07-17T15:24:34.822407Z","iopub.status.idle":"2022-07-17T15:24:34.829703Z","shell.execute_reply.started":"2022-07-17T15:24:34.822373Z","shell.execute_reply":"2022-07-17T15:24:34.828846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = KNeighborsClassifier(n_neighbors = 13)\nscoring = 'accuracy'\nscore = cross_val_score(clf, train_data, target, cv=k_fold, n_jobs=1, scoring=scoring)\nprint(score)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.830989Z","iopub.execute_input":"2022-07-17T15:24:34.831725Z","iopub.status.idle":"2022-07-17T15:24:34.921182Z","shell.execute_reply.started":"2022-07-17T15:24:34.831685Z","shell.execute_reply":"2022-07-17T15:24:34.920485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# kNN Score\nround(np.mean(score)*100, 2)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.922422Z","iopub.execute_input":"2022-07-17T15:24:34.922817Z","iopub.status.idle":"2022-07-17T15:24:34.928875Z","shell.execute_reply.started":"2022-07-17T15:24:34.922770Z","shell.execute_reply":"2022-07-17T15:24:34.927910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = DecisionTreeClassifier()\nscoring = 'accuracy'\nscore = cross_val_score(clf, train_data, target, cv=k_fold, n_jobs=1, scoring=scoring)\nprint(score)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.930411Z","iopub.execute_input":"2022-07-17T15:24:34.930735Z","iopub.status.idle":"2022-07-17T15:24:34.983369Z","shell.execute_reply.started":"2022-07-17T15:24:34.930676Z","shell.execute_reply":"2022-07-17T15:24:34.982683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# decision tree natijasini hisoblaymiz\nround(np.mean(score)*100, 2)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.984425Z","iopub.execute_input":"2022-07-17T15:24:34.985028Z","iopub.status.idle":"2022-07-17T15:24:34.991129Z","shell.execute_reply.started":"2022-07-17T15:24:34.984987Z","shell.execute_reply":"2022-07-17T15:24:34.990339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = RandomForestClassifier(n_estimators=13)\nscoring = 'accuracy'\nscore = cross_val_score(clf, train_data, target, cv=k_fold, n_jobs=1, scoring=scoring)\nprint(score)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:34.992430Z","iopub.execute_input":"2022-07-17T15:24:34.993009Z","iopub.status.idle":"2022-07-17T15:24:35.264737Z","shell.execute_reply.started":"2022-07-17T15:24:34.992974Z","shell.execute_reply":"2022-07-17T15:24:35.264015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Random Forest natijasini hisoblaymiz\nround(np.mean(score)*100, 2)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.265983Z","iopub.execute_input":"2022-07-17T15:24:35.266401Z","iopub.status.idle":"2022-07-17T15:24:35.272880Z","shell.execute_reply.started":"2022-07-17T15:24:35.266361Z","shell.execute_reply":"2022-07-17T15:24:35.272133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = GaussianNB()\nscoring = 'accuracy'\nscore = cross_val_score(clf, train_data, target, cv=k_fold, n_jobs=1, scoring=scoring)\nprint(score)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.274264Z","iopub.execute_input":"2022-07-17T15:24:35.274512Z","iopub.status.idle":"2022-07-17T15:24:35.323432Z","shell.execute_reply.started":"2022-07-17T15:24:35.274480Z","shell.execute_reply":"2022-07-17T15:24:35.322699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Naive Bayes natijasini hisoblaymiz\nround(np.mean(score)*100, 2)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.324764Z","iopub.execute_input":"2022-07-17T15:24:35.325009Z","iopub.status.idle":"2022-07-17T15:24:35.332031Z","shell.execute_reply.started":"2022-07-17T15:24:35.324975Z","shell.execute_reply":"2022-07-17T15:24:35.331117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = SVC()\nscoring = 'accuracy'\nscore = cross_val_score(clf, train_data, target, cv=k_fold, n_jobs=1, scoring=scoring)\nprint(score)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.333676Z","iopub.execute_input":"2022-07-17T15:24:35.334225Z","iopub.status.idle":"2022-07-17T15:24:35.586561Z","shell.execute_reply.started":"2022-07-17T15:24:35.334186Z","shell.execute_reply":"2022-07-17T15:24:35.585835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"round(np.mean(score)*100,2)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.587794Z","iopub.execute_input":"2022-07-17T15:24:35.588043Z","iopub.status.idle":"2022-07-17T15:24:35.596192Z","shell.execute_reply.started":"2022-07-17T15:24:35.588003Z","shell.execute_reply":"2022-07-17T15:24:35.595295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = SVC()\nclf.fit(train_data, target)\n\ntest_data = test.drop(\"PassengerId\", axis=1).copy()\nprediction = clf.predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.597694Z","iopub.execute_input":"2022-07-17T15:24:35.598821Z","iopub.status.idle":"2022-07-17T15:24:35.639771Z","shell.execute_reply.started":"2022-07-17T15:24:35.598771Z","shell.execute_reply":"2022-07-17T15:24:35.639137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Natijani qabul qilish uchun submission.csv nomli file ochib olamiz","metadata":{}},{"cell_type":"code","source":"submission = pd.DataFrame({\n        \"PassengerId\": test[\"PassengerId\"],\n        \"Survived\": prediction\n    })\n\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.641122Z","iopub.execute_input":"2022-07-17T15:24:35.641640Z","iopub.status.idle":"2022-07-17T15:24:35.649957Z","shell.execute_reply.started":"2022-07-17T15:24:35.641594Z","shell.execute_reply":"2022-07-17T15:24:35.649277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Pastdagi qatorni run qilganingizdan so'ng, o'ng tarafda yuqori qismda Output ichida yangi submission.csv file paydo bo'ladi! Siz uni saqlab Titanic musobaqasiga yo'llashingiz mumkin!","metadata":{}},{"cell_type":"code","source":"submission = pd.read_csv('submission.csv')\nsubmission.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T15:24:35.651664Z","iopub.execute_input":"2022-07-17T15:24:35.651919Z","iopub.status.idle":"2022-07-17T15:24:35.664804Z","shell.execute_reply.started":"2022-07-17T15:24:35.651886Z","shell.execute_reply":"2022-07-17T15:24:35.664099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <center>Qoyil, siz buni uddaladingiz!🥳🎉 </center>","metadata":{}},{"cell_type":"markdown","source":">   <center>Notebook bilan tanishib chiqdingiz buning uchun alohida raxmat, agar sizda muammo bulsa izohlarda yozishdan tortinmang!</center>","metadata":{}}]}