{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This is practice related to the Logic and Control section of the Datacamp course Intermediate Python for Data Science\n", "\n", "Much of what we need to know is rooted in common sense. For example, Suppose our friend Sally says *Ann went to the party*. If we saw pictures of the party and Ann was indeed there we would say that Sally is telling the truth ... or we would say her statement *Ann went to the party* is true. As English-speakers we also know the meaning of 'and' and 'or'. So if Sally said to us:\n", "\n", "> *I will go to the party if Ann and Jane go, or if you go*\n", "\n", "If we told Sally that we would go then she would be truthful if she went as well, and we would say she lied (or her statement was false) if she said she still wasn't going to the party. Here's a question:\n", "\n", "> *Suppose Sally didn't go to the party; Ann went to the party; and Jane did not go. Is the above statement true or false?*\n", "\n", "In the DataCamp course we learned how we can express these conditionals in Python. For example:\n", "\n", " if ann == 'yes' and jane == 'yes':\n", " print('I will go to the party')\n", " else:\n", " print('I will not go to the party')\n", "\n", "This rudiment gives us some practice with this.\n", "\n", "# Titanic\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to work with a data set of the passengers of the Titanic. Let's load it in and take a look at it." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
PassengerId
103Braund, Mr. Owen Harrismale22.010A/5 211717.2500NaNS
211Cumings, Mrs. John Bradley (Florence Briggs Th...female38.010PC 1759971.2833C85C
313Heikkinen, Miss. Lainafemale26.000STON/O2. 31012827.9250NaNS
411Futrelle, Mrs. Jacques Heath (Lily May Peel)female35.01011380353.1000C123S
503Allen, Mr. William Henrymale35.0003734508.0500NaNS
603Moran, Mr. JamesmaleNaN003308778.4583NaNQ
701McCarthy, Mr. Timothy Jmale54.0001746351.8625E46S
803Palsson, Master. Gosta Leonardmale2.03134990921.0750NaNS
913Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)female27.00234774211.1333NaNS
1012Nasser, Mrs. Nicholas (Adele Achem)female14.01023773630.0708NaNC
1113Sandstrom, Miss. Marguerite Rutfemale4.011PP 954916.7000G6S
1211Bonnell, Miss. Elizabethfemale58.00011378326.5500C103S
1303Saundercock, Mr. William Henrymale20.000A/5. 21518.0500NaNS
1403Andersson, Mr. Anders Johanmale39.01534708231.2750NaNS
1503Vestrom, Miss. Hulda Amanda Adolfinafemale14.0003504067.8542NaNS
1612Hewlett, Mrs. (Mary D Kingcome)female55.00024870616.0000NaNS
1703Rice, Master. Eugenemale2.04138265229.1250NaNQ
1812Williams, Mr. Charles EugenemaleNaN0024437313.0000NaNS
1903Vander Planke, Mrs. Julius (Emelia Maria Vande...female31.01034576318.0000NaNS
2013Masselmani, Mrs. FatimafemaleNaN0026497.2250NaNC
2102Fynney, Mr. Joseph Jmale35.00023986526.0000NaNS
2212Beesley, Mr. Lawrencemale34.00024869813.0000D56S
2313McGowan, Miss. Anna \"Annie\"female15.0003309238.0292NaNQ
2411Sloper, Mr. William Thompsonmale28.00011378835.5000A6S
2503Palsson, Miss. Torborg Danirafemale8.03134990921.0750NaNS
2613Asplund, Mrs. Carl Oscar (Selma Augusta Emilia...female38.01534707731.3875NaNS
2703Emir, Mr. Farred ChehabmaleNaN0026317.2250NaNC
2801Fortune, Mr. Charles Alexandermale19.03219950263.0000C23 C25 C27S
2913O'Dwyer, Miss. Ellen \"Nellie\"femaleNaN003309597.8792NaNQ
3003Todoroff, Mr. LaliomaleNaN003492167.8958NaNS
....................................
86202Giles, Mr. Frederick Edwardmale21.0102813411.5000NaNS
86311Swift, Mrs. Frederick Joel (Margaret Welles Ba...female48.0001746625.9292D17S
86403Sage, Miss. Dorothy Edith \"Dolly\"femaleNaN82CA. 234369.5500NaNS
86502Gill, Mr. John Williammale24.00023386613.0000NaNS
86612Bystrom, Mrs. (Karolina)female42.00023685213.0000NaNS
86712Duran y More, Miss. Asuncionfemale27.010SC/PARIS 214913.8583NaNC
86801Roebling, Mr. Washington Augustus IImale31.000PC 1759050.4958A24S
86903van Melkebeke, Mr. PhilemonmaleNaN003457779.5000NaNS
87013Johnson, Master. Harold Theodormale4.01134774211.1333NaNS
87103Balkic, Mr. Cerinmale26.0003492487.8958NaNS
87211Beckwith, Mrs. Richard Leonard (Sallie Monypeny)female47.0111175152.5542D35S
87301Carlsson, Mr. Frans Olofmale33.0006955.0000B51 B53 B55S
87403Vander Cruyssen, Mr. Victormale47.0003457659.0000NaNS
87512Abelson, Mrs. Samuel (Hannah Wizosky)female28.010P/PP 338124.0000NaNC
87613Najib, Miss. Adele Kiamie \"Jane\"female15.00026677.2250NaNC
87703Gustafsson, Mr. Alfred Ossianmale20.00075349.8458NaNS
87803Petroff, Mr. Nedeliomale19.0003492127.8958NaNS
87903Laleff, Mr. KristomaleNaN003492177.8958NaNS
88011Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)female56.0011176783.1583C50C
88112Shelley, Mrs. William (Imanita Parrish Hall)female25.00123043326.0000NaNS
88203Markun, Mr. Johannmale33.0003492577.8958NaNS
88303Dahlberg, Miss. Gerda Ulrikafemale22.000755210.5167NaNS
88402Banfield, Mr. Frederick Jamesmale28.000C.A./SOTON 3406810.5000NaNS
88503Sutehall, Mr. Henry Jrmale25.000SOTON/OQ 3920767.0500NaNS
88603Rice, Mrs. William (Margaret Norton)female39.00538265229.1250NaNQ
88702Montvila, Rev. Juozasmale27.00021153613.0000NaNS
88811Graham, Miss. Margaret Edithfemale19.00011205330.0000B42S
88903Johnston, Miss. Catherine Helen \"Carrie\"femaleNaN12W./C. 660723.4500NaNS
89011Behr, Mr. Karl Howellmale26.00011136930.0000C148C
89103Dooley, Mr. Patrickmale32.0003703767.7500NaNQ
\n", "

891 rows × 11 columns

\n", "
" ], "text/plain": [ " Survived Pclass \\\n", "PassengerId \n", "1 0 3 \n", "2 1 1 \n", "3 1 3 \n", "4 1 1 \n", "5 0 3 \n", "6 0 3 \n", "7 0 1 \n", "8 0 3 \n", "9 1 3 \n", "10 1 2 \n", "11 1 3 \n", "12 1 1 \n", "13 0 3 \n", "14 0 3 \n", "15 0 3 \n", "16 1 2 \n", "17 0 3 \n", "18 1 2 \n", "19 0 3 \n", "20 1 3 \n", "21 0 2 \n", "22 1 2 \n", "23 1 3 \n", "24 1 1 \n", "25 0 3 \n", "26 1 3 \n", "27 0 3 \n", "28 0 1 \n", "29 1 3 \n", "30 0 3 \n", "... ... ... \n", "862 0 2 \n", "863 1 1 \n", "864 0 3 \n", "865 0 2 \n", "866 1 2 \n", "867 1 2 \n", "868 0 1 \n", "869 0 3 \n", "870 1 3 \n", "871 0 3 \n", "872 1 1 \n", "873 0 1 \n", "874 0 3 \n", "875 1 2 \n", "876 1 3 \n", "877 0 3 \n", "878 0 3 \n", "879 0 3 \n", "880 1 1 \n", "881 1 2 \n", "882 0 3 \n", "883 0 3 \n", "884 0 2 \n", "885 0 3 \n", "886 0 3 \n", "887 0 2 \n", "888 1 1 \n", "889 0 3 \n", "890 1 1 \n", "891 0 3 \n", "\n", " Name Sex Age \\\n", "PassengerId \n", "1 Braund, Mr. Owen Harris male 22.0 \n", "2 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 \n", "3 Heikkinen, Miss. Laina female 26.0 \n", "4 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 \n", "5 Allen, Mr. William Henry male 35.0 \n", "6 Moran, Mr. James male NaN \n", "7 McCarthy, Mr. Timothy J male 54.0 \n", "8 Palsson, Master. Gosta Leonard male 2.0 \n", "9 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 \n", "10 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 \n", "11 Sandstrom, Miss. Marguerite Rut female 4.0 \n", "12 Bonnell, Miss. Elizabeth female 58.0 \n", "13 Saundercock, Mr. William Henry male 20.0 \n", "14 Andersson, Mr. Anders Johan male 39.0 \n", "15 Vestrom, Miss. Hulda Amanda Adolfina female 14.0 \n", "16 Hewlett, Mrs. (Mary D Kingcome) female 55.0 \n", "17 Rice, Master. Eugene male 2.0 \n", "18 Williams, Mr. Charles Eugene male NaN \n", "19 Vander Planke, Mrs. Julius (Emelia Maria Vande... female 31.0 \n", "20 Masselmani, Mrs. Fatima female NaN \n", "21 Fynney, Mr. Joseph J male 35.0 \n", "22 Beesley, Mr. Lawrence male 34.0 \n", "23 McGowan, Miss. Anna \"Annie\" female 15.0 \n", "24 Sloper, Mr. William Thompson male 28.0 \n", "25 Palsson, Miss. Torborg Danira female 8.0 \n", "26 Asplund, Mrs. Carl Oscar (Selma Augusta Emilia... female 38.0 \n", "27 Emir, Mr. Farred Chehab male NaN \n", "28 Fortune, Mr. Charles Alexander male 19.0 \n", "29 O'Dwyer, Miss. Ellen \"Nellie\" female NaN \n", "30 Todoroff, Mr. Lalio male NaN \n", "... ... ... ... \n", "862 Giles, Mr. Frederick Edward male 21.0 \n", "863 Swift, Mrs. Frederick Joel (Margaret Welles Ba... female 48.0 \n", "864 Sage, Miss. Dorothy Edith \"Dolly\" female NaN \n", "865 Gill, Mr. John William male 24.0 \n", "866 Bystrom, Mrs. (Karolina) female 42.0 \n", "867 Duran y More, Miss. Asuncion female 27.0 \n", "868 Roebling, Mr. Washington Augustus II male 31.0 \n", "869 van Melkebeke, Mr. Philemon male NaN \n", "870 Johnson, Master. Harold Theodor male 4.0 \n", "871 Balkic, Mr. Cerin male 26.0 \n", "872 Beckwith, Mrs. Richard Leonard (Sallie Monypeny) female 47.0 \n", "873 Carlsson, Mr. Frans Olof male 33.0 \n", "874 Vander Cruyssen, Mr. Victor male 47.0 \n", "875 Abelson, Mrs. Samuel (Hannah Wizosky) female 28.0 \n", "876 Najib, Miss. Adele Kiamie \"Jane\" female 15.0 \n", "877 Gustafsson, Mr. Alfred Ossian male 20.0 \n", "878 Petroff, Mr. Nedelio male 19.0 \n", "879 Laleff, Mr. Kristo male NaN \n", "880 Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) female 56.0 \n", "881 Shelley, Mrs. William (Imanita Parrish Hall) female 25.0 \n", "882 Markun, Mr. Johann male 33.0 \n", "883 Dahlberg, Miss. Gerda Ulrika female 22.0 \n", "884 Banfield, Mr. Frederick James male 28.0 \n", "885 Sutehall, Mr. Henry Jr male 25.0 \n", "886 Rice, Mrs. William (Margaret Norton) female 39.0 \n", "887 Montvila, Rev. Juozas male 27.0 \n", "888 Graham, Miss. Margaret Edith female 19.0 \n", "889 Johnston, Miss. Catherine Helen \"Carrie\" female NaN \n", "890 Behr, Mr. Karl Howell male 26.0 \n", "891 Dooley, Mr. Patrick male 32.0 \n", "\n", " SibSp Parch Ticket Fare Cabin Embarked \n", "PassengerId \n", "1 1 0 A/5 21171 7.2500 NaN S \n", "2 1 0 PC 17599 71.2833 C85 C \n", "3 0 0 STON/O2. 3101282 7.9250 NaN S \n", "4 1 0 113803 53.1000 C123 S \n", "5 0 0 373450 8.0500 NaN S \n", "6 0 0 330877 8.4583 NaN Q \n", "7 0 0 17463 51.8625 E46 S \n", "8 3 1 349909 21.0750 NaN S \n", "9 0 2 347742 11.1333 NaN S \n", "10 1 0 237736 30.0708 NaN C \n", "11 1 1 PP 9549 16.7000 G6 S \n", "12 0 0 113783 26.5500 C103 S \n", "13 0 0 A/5. 2151 8.0500 NaN S \n", "14 1 5 347082 31.2750 NaN S \n", "15 0 0 350406 7.8542 NaN S \n", "16 0 0 248706 16.0000 NaN S \n", "17 4 1 382652 29.1250 NaN Q \n", "18 0 0 244373 13.0000 NaN S \n", "19 1 0 345763 18.0000 NaN S \n", "20 0 0 2649 7.2250 NaN C \n", "21 0 0 239865 26.0000 NaN S \n", "22 0 0 248698 13.0000 D56 S \n", "23 0 0 330923 8.0292 NaN Q \n", "24 0 0 113788 35.5000 A6 S \n", "25 3 1 349909 21.0750 NaN S \n", "26 1 5 347077 31.3875 NaN S \n", "27 0 0 2631 7.2250 NaN C \n", "28 3 2 19950 263.0000 C23 C25 C27 S \n", "29 0 0 330959 7.8792 NaN Q \n", "30 0 0 349216 7.8958 NaN S \n", "... ... ... ... ... ... ... \n", "862 1 0 28134 11.5000 NaN S \n", "863 0 0 17466 25.9292 D17 S \n", "864 8 2 CA. 2343 69.5500 NaN S \n", "865 0 0 233866 13.0000 NaN S \n", "866 0 0 236852 13.0000 NaN S \n", "867 1 0 SC/PARIS 2149 13.8583 NaN C \n", "868 0 0 PC 17590 50.4958 A24 S \n", "869 0 0 345777 9.5000 NaN S \n", "870 1 1 347742 11.1333 NaN S \n", "871 0 0 349248 7.8958 NaN S \n", "872 1 1 11751 52.5542 D35 S \n", "873 0 0 695 5.0000 B51 B53 B55 S \n", "874 0 0 345765 9.0000 NaN S \n", "875 1 0 P/PP 3381 24.0000 NaN C \n", "876 0 0 2667 7.2250 NaN C \n", "877 0 0 7534 9.8458 NaN S \n", "878 0 0 349212 7.8958 NaN S \n", "879 0 0 349217 7.8958 NaN S \n", "880 0 1 11767 83.1583 C50 C \n", "881 0 1 230433 26.0000 NaN S \n", "882 0 0 349257 7.8958 NaN S \n", "883 0 0 7552 10.5167 NaN S \n", "884 0 0 C.A./SOTON 34068 10.5000 NaN S \n", "885 0 0 SOTON/OQ 392076 7.0500 NaN S \n", "886 0 5 382652 29.1250 NaN Q \n", "887 0 0 211536 13.0000 NaN S \n", "888 0 0 112053 30.0000 B42 S \n", "889 1 2 W./C. 6607 23.4500 NaN S \n", "890 0 0 111369 30.0000 C148 C \n", "891 0 0 370376 7.7500 NaN Q \n", "\n", "[891 rows x 11 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "titanic_data = pd.read_csv('https://s3.amazonaws.com/content.udacity-data.com/courses/ud359/titanic_data.csv')\n", "titanic_data.set_index('PassengerId', inplace=True)\n", "titanic_data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are what some of the columns mean:\n", "\n", "* Survived - a '1' indicates the person survived; a '0' means they did not survive.\n", "* Pclass - passenger class: 1st class, 2nd class, 3rd class\n", "* SibSp - whether they were traveling with a sibling or spouse.\n", "* Parch - number of parents or children aboard\n", "* ticket - ticket number\n", "* Embarked\tPort of Embarkation\tC = Cherbourg, Q = Queenstown, S = Southampton\n", "\n", "Your task is to examine the data and using the intuition you gained to come up with a way to predict whether a person survived or not. You can't use the PassengerId or Survived columns in your rule but anything else is fair game." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def predict(passenger):\n", " # Your code here\n", " # You should return 1 if you think the person survived and 0 if you think they didn't\n", " # For example, if you think males survived but females didn't you would write:\n", " if passenger['Sex'] == 'male':\n", " return 1\n", " else:\n", " return 0\n", "\n", "# You can started with this example rule for now.\n", "# When you execute this code cell nothing will appear but the system will remember your rule." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You just need to execute the following code block to see how good your rule was." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accuracy: 21.32%\n" ] } ], "source": [ "predictions = []\n", " #df = pandas.read_csv(file_path)\n", "for passenger_index, passenger in titanic_data.iterrows():\n", " predictions.append(predict(passenger))\n", " \n", "predictions\n", "\n", "\n", "from sklearn.metrics import accuracy_score\n", "score = accuracy_score(titanic_data['Survived'], predictions) \n", "print('Accuracy: %4.2f%%' % (score * 100))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### good luck!\n", "\n", "\n", "Here is the formula for how much xp you will gain:\n", "\n", "\n", "## $$xp= 2000 + (accuracy - 78) * 1000$$\n", "\n", "For example suppose your accuracy was 79.21. Your xp will be\n", "\n", "$$xp= 2000 + (79.21 - 78) * 1000 = 2000 + (1.21 * 1000) = 2000 + 1210 = 3210$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }