From 5d8d7e79c8e4a0bea3a97e296e25542110dcca17 Mon Sep 17 00:00:00 2001 From: Chidella Date: Mon, 23 Jul 2018 11:56:12 -0400 Subject: [PATCH 1/2] ContinueLearning, first cut --- .cache/v/cache/lastfailed | 4 + .gitignore | 1 + alice.txt | 17 + assessment.py | 142 -- src/__init__.py | 0 src/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 163 bytes src/__pycache__/assessment.cpython-36.pyc | Bin 0 -> 2496 bytes src/alice.txt | 17 + src/assessment.py | 92 + test/__init__.py | 0 test/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 164 bytes .../test_assessment.cpython-36-PYTEST.pyc | Bin 0 -> 6700 bytes test/alice.txt | 17 + test/example.py | 23 + test/test_assessment.py | 95 + testing.py | 77 - titanic_survivor_model.ipynb | 2045 +++++++++++++++++ 17 files changed, 2311 insertions(+), 219 deletions(-) create mode 100644 .cache/v/cache/lastfailed create mode 100644 .gitignore create mode 100644 alice.txt delete mode 100644 assessment.py create mode 100644 src/__init__.py create mode 100644 src/__pycache__/__init__.cpython-36.pyc create mode 100644 src/__pycache__/assessment.cpython-36.pyc create mode 100644 src/alice.txt create mode 100644 src/assessment.py create mode 100644 test/__init__.py create mode 100644 test/__pycache__/__init__.cpython-36.pyc create mode 100644 test/__pycache__/test_assessment.cpython-36-PYTEST.pyc create mode 100644 test/alice.txt create mode 100644 test/example.py create mode 100644 test/test_assessment.py delete mode 100644 testing.py create mode 100644 titanic_survivor_model.ipynb diff --git a/.cache/v/cache/lastfailed b/.cache/v/cache/lastfailed new file mode 100644 index 0000000..ba39895 --- /dev/null +++ b/.cache/v/cache/lastfailed @@ -0,0 +1,4 @@ +{ + "test/test_assessment.py::test_array_work": true, + "test/test_assessment.py::test_invert_dictionary": true +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..763513e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints diff --git a/alice.txt b/alice.txt new file mode 100644 index 0000000..84bf3cc --- /dev/null +++ b/alice.txt @@ -0,0 +1,17 @@ +Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?' +So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. +There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge. +In another moment down went Alice after it, never once considering how in the world she was to get out again. +The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. +Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it. +'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything about it, even if I fell off the top of the house!' (Which was very likely true.) +Down, down, down. Would the fall NEVER come to an end! 'I wonder how many miles I've fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think—' (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a VERY good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) '—yes, that's about the right distance—but then I wonder what Latitude or Longitude I've got to?' (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.) +Presently she began again. 'I wonder if I shall fall right THROUGH the earth! How funny it'll seem to come out among the people that walk with their heads downward! The Antipathies, I think—' (she was rather glad there WAS no one listening, this time, as it didn't sound at all the right word) '—but I shall have to ask them what the name of the country is, you know. Please, Ma'am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke—fancy CURTSEYING as you're falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she'll think me for asking! No, it'll never do to ask: perhaps I shall see it written up somewhere.' +Down, down, down. There was nothing else to do, so Alice soon began talking again. 'Dinah'll miss me very much to-night, I should think!' (Dinah was the cat.) 'I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I'm afraid, but you might catch a bat, and that's very like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats eat cats?' for, you see, as she couldn't answer either question, it didn't much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over. +Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, 'Oh my ears and whiskers, how late it's getting!' She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof. +There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. +Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted! +Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head through the doorway; 'and even if my head would go through,' thought poor Alice, 'it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only knew how to begin.' For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible. +There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, ('which certainly was not here before,' said Alice,) and round the neck of the bottle was a paper label, with the words 'DRINK ME' beautifully printed on it in large letters. +It was all very well to say 'Drink me,' but the wise little Alice was not going to do THAT in a hurry. 'No, I'll look first,' she said, 'and see whether it's marked "poison" or not'; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they WOULD not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger VERY deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked 'poison,' it is almost certain to disagree with you, sooner or later. +However, this bottle was NOT marked 'poison,' so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off. diff --git a/assessment.py b/assessment.py deleted file mode 100644 index 281675d..0000000 --- a/assessment.py +++ /dev/null @@ -1,142 +0,0 @@ -import numpy as np -import pandas as pd - - -# PYTHON SECTION - -def count_characters(string): - ''' - INPUT: STRING - OUTPUT: DICT (with counts of each character in input string) - - Return a dictionary which contains - a count of the number of times each character appears in the string. - Characters which with a count of 0 should not be included in the - output dictionary. - ''' - pass - - -def invert_dictionary(d): - ''' - INPUT: DICT - OUTPUT: DICT (of sets of input keys indexing the same input values - indexed by the input values) - - Given a dictionary d, return a new dictionary with d's values - as keys and the value for a given key being - the set of d's keys which shared the same value. - e.g. {'a': 2, 'b': 4, 'c': 2} => {2: {'a', 'c'}, 4: {'b'}} - ''' - pass - - -def word_count(filename): - ''' - INPUT: STRING - OUTPUT: INT, INT, INT (a tuple with line, word, - and character count of named INPUT file) - - The INPUT filename is the name of a text file. - The OUTPUT is a tuple containting (in order) - the following stats for the text file: - 1. number of lines - 2. number of words (broken by whitespace) - 3. number of characters - ''' - pass - - -def matrix_multiplication(A, B): - ''' - INPUT: LIST (of length n) OF LIST (of length n) OF INTEGERS, - LIST (of length n) OF LIST (of length n) OF INTEGERS - OUTPUT: LIST OF LIST OF INTEGERS - (storing the product of a matrix multiplication operation) - - Return the matrix which is the product of matrix A and matrix B - where A and B will be (a) integer valued (b) square matrices - (c) of size n-by-n (d) encoded as lists of lists. - - For example: - A = [[2, 3, 4], [6, 4, 2], [-1, 2, 0]] corresponds to the matrix - - | 2 3 4 | - | 6 4 2 | - |-1 2 0 | - - Please do not use numpy. Write your solution in straight python. - ''' - pass - - -# NumPy SECTION - - -def array_work(rows, cols, scalar, matrixA): - ''' - INPUT: INT, INT, INT, NUMPY ARRAY - OUTPUT: NUMPY ARRAY - (of matrix product of r-by-c matrix of "scalar"'s time matrixA) - - Create matrix of size (rows, cols) with elements initialized to the scalar - value. Right multiply that matrix with the passed matrixA (i.e. AB, not - BA). Return the result of the multiplication. You needn't check for - matrix compatibililty, but you accomplish this in a single line. - - E.g., array_work(2, 3, 5, [[3, 4], [5, 6], [7, 8]]) - [[3, 4], [[5, 5, 5], - [5, 6], * [5, 5, 5]] - [7, 8]] - ''' - pass - - -def boolean_indexing(arr, minimum): - ''' - INPUT: NUMPY ARRAY, INT - OUTPUT: NUMPY ARRAY - (of just elements in "arr" greater or equal to "minimum") - - Return an array of only the elements of "arr" that are greater than or - equal to "minimum" - - Ex: - In [1]: boolean_indexing([[3, 4, 5], [6, 7, 8]], 7) - Out[1]: array([7, 8]) - ''' - pass - - -# Pandas SECTION - -def make_series(start, length, index): - ''' - INPUTS: INT, INT, LIST (of length "length") - OUTPUT: PANDAS SERIES (of "length" sequential integers - beginning with "start" and with index "index") - - Create a pandas Series of length "length" with index "index" - and with elements that are sequential integers starting from "start". - You may assume the length of index will be "length". - - E.g., - In [1]: make_series(5, 3, ['a', 'b', 'c']) - Out[1]: - a 5 - b 6 - c 7 - dtype: int64 - ''' - pass - - -def data_frame_work(df, colA, colB, colC): - ''' - INPUT: DATAFRAME, STR, STR, STR - OUTPUT: None - - Insert a column (colC) into the dataframe that is the sum of colA and colB. - Assume that df contains columns colA and colB and that these are numeric. - ''' - pass diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/__pycache__/__init__.cpython-36.pyc b/src/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..54bf4b942b9bd93b928f791538a41f7c487e8dcc GIT binary patch literal 163 zcmXr!<>g9TPO2TqreYvw004DgD~137 literal 0 HcmV?d00001 diff --git a/src/__pycache__/assessment.cpython-36.pyc b/src/__pycache__/assessment.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7f28aa871f6782cd46d238a2d7936609c2449e67 GIT binary patch literal 2496 zcmZuz&2Aev5GJ`lTFbw2oTN@u!04q>Tf0dbBtU8e&JWN_YP7LYr>cU*X1P|@Uae#< zo!G+aq?}vy-WSMA^g(#-$*+)8zu{W8ta=3wxtt+)=HoX*eLp)}|7U*t_m2T%|FW^i z!FU6$_!2@g$urjEwiiw3M<#`IJ}~JFMbnjhi#6O6*s;x+e80oZ|w+a=vtg*FT>m8dQ4AVT-Vd#?w6h7nqtLL7s zjr6hAK}}wIXx8No3{o}_M-NK=oV{KfIHlNQr6c(eu5~@BKQNGdAleqh60i=%pAt~EN*6G054;iy`Vd^w{1g_a^!5PakYm=ttRS$eKFEsy#muJO=Z1HFi&kNqMPALp_Z^ueB~@J z34TI<3$0j!XtR>No*8hQCLi*@#DTk2WhId{OY(*=V(pGacmm!}_4O<*blmOq9^a?! zXm6kO8)F#0?cX2ug;|;>ppMKwv44k7(<5UUqA=Q@_`0}fr zK~gS*0e1H3z&l#6W>06n9r#EocNwWi6{qBO>|-QKlHM{~Vy9K;PYM`9#GE z9H^(Fyq#RYlD{(iH{+|MILvf)+RKQ=@cl{1u5}`mt)s95!xRS-+Y0;$##LzoQj6lc zv&irB{>m6)mo7U4k3ghm!K2(lXh@8G1Z3|G>qWz@U(yZ0@`PWF~LF)^=B9_;Ds)(8+C l)uPmR_Fsh&dC&OOUki12wD_`JO|V|M`k1P$jTMzb{0B6aJS_kK literal 0 HcmV?d00001 diff --git a/src/alice.txt b/src/alice.txt new file mode 100644 index 0000000..84bf3cc --- /dev/null +++ b/src/alice.txt @@ -0,0 +1,17 @@ +Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?' +So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. +There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge. +In another moment down went Alice after it, never once considering how in the world she was to get out again. +The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. +Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it. +'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything about it, even if I fell off the top of the house!' (Which was very likely true.) +Down, down, down. Would the fall NEVER come to an end! 'I wonder how many miles I've fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think—' (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a VERY good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) '—yes, that's about the right distance—but then I wonder what Latitude or Longitude I've got to?' (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.) +Presently she began again. 'I wonder if I shall fall right THROUGH the earth! How funny it'll seem to come out among the people that walk with their heads downward! The Antipathies, I think—' (she was rather glad there WAS no one listening, this time, as it didn't sound at all the right word) '—but I shall have to ask them what the name of the country is, you know. Please, Ma'am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke—fancy CURTSEYING as you're falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she'll think me for asking! No, it'll never do to ask: perhaps I shall see it written up somewhere.' +Down, down, down. There was nothing else to do, so Alice soon began talking again. 'Dinah'll miss me very much to-night, I should think!' (Dinah was the cat.) 'I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I'm afraid, but you might catch a bat, and that's very like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats eat cats?' for, you see, as she couldn't answer either question, it didn't much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over. +Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, 'Oh my ears and whiskers, how late it's getting!' She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof. +There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. +Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted! +Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head through the doorway; 'and even if my head would go through,' thought poor Alice, 'it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only knew how to begin.' For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible. +There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, ('which certainly was not here before,' said Alice,) and round the neck of the bottle was a paper label, with the words 'DRINK ME' beautifully printed on it in large letters. +It was all very well to say 'Drink me,' but the wise little Alice was not going to do THAT in a hurry. 'No, I'll look first,' she said, 'and see whether it's marked "poison" or not'; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they WOULD not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger VERY deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked 'poison,' it is almost certain to disagree with you, sooner or later. +However, this bottle was NOT marked 'poison,' so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off. diff --git a/src/assessment.py b/src/assessment.py new file mode 100644 index 0000000..7626c0d --- /dev/null +++ b/src/assessment.py @@ -0,0 +1,92 @@ +import numpy as np +import pandas as pd + +class Assessment: + + def __init__(self): + pass + +# PYTHON SECTION + + def count_characters(self,string): + + dict={} + for i in string: + if dict.get(i,'novalue')=='novalue': + dict[i]=1 + + else: + dict[i] +=1 + return dict + + + + def invert_dictionary(self,d): + dict={'a': 2, 'b': 4,'c':2} + dict_new={} + s=set() + for i,j in dict.items(): + print(i,j) + if dict_new.get(j,'novalue')=='novalue': + dict_new[j]=set(i) + else: + s=dict_new.get(j) + s.add(i) + dict_new[j]=s + + return dict_new + + + + + + def word_count(self,filename): + number_lines=0 + words=[] + with open(filename,'r') as readfile: + for line in readfile: + number_lines+=1 + print(line) + words+=line.split(" ") + print(number_lines) + char_count= [ len(i) for i in words] + print("char_count",sum(char_count) ) + print("words count",len(words)) + return (number_lines, len(words), sum(char_count)) + + + def matrix_multiplication(self,X,Y): + result=[[0,0,0],[0,0,0],[0,0,0]] + for i in range(len(X)): + # iterate through columns of Y + for j in range(len(Y[0])): + + # iterate through rows of Y + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] + return result + + + +# # NumPy SECTION + + +#def array_work(rows, cols, scalar, matrixA): + + + def boolean_indexing(self,arr, minimum): + return arr[arr>=minimum] + + + +# # Pandas SECTION + + def make_series(self,start,length, index): + list1=[] + for i in range(start, start+length): + list1.append(i) + return pd.Series(list1,index) + + def data_frame_work(self,df, colA, colB, colC): + df[colC]=colA+colB + return df diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/__pycache__/__init__.cpython-36.pyc b/test/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d09fd8d8d45ea5a952c80a9bdea330f0c873ce0b GIT binary patch literal 164 zcmXr!<>mUk$|ITq2p)q77+?f49Dul(1xTbY1T$zd`mJOr0tq9CUxCh6F+Qn@MR}Qd z=`k+BMh1p41(hWk`FV-O#i_-)sd*((zHVM=Zb7APL1JD?VzF*&Sz=CUVo7FxUQ9`9 iaY;;kd}dx|NqoFsLFFwDo80`A(wtN~kX6M%%m4ranJke2 literal 0 HcmV?d00001 diff --git a/test/__pycache__/test_assessment.cpython-36-PYTEST.pyc b/test/__pycache__/test_assessment.cpython-36-PYTEST.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4ee06b4468ff06fa915d6aa660d39772c4ddb7a0 GIT binary patch literal 6700 zcmb_gTWlOx8J_#hUcI(sJ5HR&O|RQFCU)+qDY-R*5?rd5wrmaC@t*a1o%QbO%(#ui zEJ8S{P=!#05D&;t2vtI=DxUhlBSJg^k7&dbNJxwN#2coleE)xTXEz&{SOQ!7&p&7W znRENU?|kQ+&gIf?6<&Mmv$UrDRU7&<;9tfsXut?f=nbu;^VQfeH>{Ek-)K0SZpqcv zbFY-*=jl>Ln8LcNm9oMX4z4-j3J=%3NQpGAV zs4W-uIDI7uszI<>ZH5&pqdylv55H^p1s}tN+K$#i`#QQXs9ydz;n}-x$B48IJ<@md zjv1Meam(mfkrjLtq7Nb;S!=o&qw+Ol#}Zy>ZP+{7EhqRko;#7bqsw)8E_qEucp{ZV ze2*gxM7+-t@DPFC?Hbcs#}?>WWY=~0PUs;b6*)U-#rH9S9ZP7`%jHteU-j2SrB++> z{ncvMLT9=(>|GtE=*GGq>#MO|iFFa{)mUGP_1d0s>C)cB6Hm9dPZfjtOPA)!T`C5# zBdftyBa9ut8N6GSMI$y5LuM(~_VPYPQidFT2GJ-!Q`BXSD$->h7kP;Mw4?@<3YFGY zGb~rued$-istn@v<@R=14Z^Z7BYt?U*oBn1sPL%_Htx8{r^EAmathbskO4*X}WO=P6H~p|&z1?p3 zO`o0=UFo1*u@i){-mJ+2HF%6lGE}kZ++vAu)Z3@k6LoX;mzsPO(R*)R`{K&YsxO=P z$jbFsmrgCNpj+#$CVhePtapF1xwYBeKH2u0!VgYX-|-t;+>jL-12$Z#%FTuLc09#{ zGdgV4=zs=RGaTL059w*$(=6?6Evw}<`54NRyr!H^@;ZwQ=;t+OHRZE`e+xOS3wvD` z4qA`2OBNA^7}_!L=aibIi&oS&j6obzKzM&H46C!&nL z3(qAF89gTKBx08%G(>#B5%3UUvk!!bOcMD!jzk;eANeUfL}u8x5Lwu@2^nHqOhyi) z#O#AVxSVh-~^xr zFy6`t^ah!ePyNP~e`xA~t?%vbn9zR#yI3XtcF=){=M2jW<6dO;nk6aXob{#ON zD~^kq$mLA+dYS4CWvT-PwV*~wZ_F<DIcx~$(WZ$hTj+W-!)r~`U@j@8LI#gn|kQwwALN~~Wk zIwO?H2q6HSBXdEaXiRYxe`gW;D7M<$i>JDu;jjB|nEF4-`xkkChZ*4M1ym%7W%_uU z+PAF-hE_^J>r3?6%VfAaMR*EIs-5QUcps-OjzaASLv7!t5jzLO^~9@l{O@RK zX4YRT?0pr_6711rC)hKP4#Ug}OcDB^-D}nkP=~Ao=Y@Ur5YzsK)W?hlMQm?4teJ0y z?gkVzFz`A&DCNE)P9mBVL0VkirU>$&3V_)p;vRnkxh{Xk-%wef;b{1LC8d#N{a}S@ zlz^#+GTwmt(Sw_v%jtNL7km;r8!i~pgYucBa#lXM(A!8c zr{Bf%H1Vta5j)=!Z=|-o`V5!26!KMv_Qs2y}7sAmpt_*Ym0p(&puS}ImoZH8e5x9 zKz|`@HR?eK0YoHVq5N8Gh_wfHhYIvpsj<8}9922;Iz3|Qx&-e&5>Gno7bapiQ%qMrpkOFw;M6 zOl~uT3plBBv^#*LvkXOK+lEy7a(;WS`4gX>|WCN?8ANRy5h8UPs< zWx!Aq4mKMGze9jU3?fY2TYNZU^5KjX0Vut#NP(mfph$-_M+n3W$P^Ylj{*5Uo~QVb z<|pvdy+axt0VNS1as=v;A9DmeC9-<5CM$A~ZTTer&lC^wr^~-lJb8%E^Sc0kxCrOveEE1!y>q%2dd8n^ci2oI9WB&K?mRD{-&bzNPmqWi*GsNDED_RLIn4B zyx%&2{JV%qMJe72{eas7A1xfmrm8n8i24ObfkLoh`iP_8BWglq_U|{|`4hcE{lzm5=t!|*1GWj`?tZ?T3JZkz=47jA6#V^URepaxQ80q3;64Hgcrh-QptyJ!vVrJke;o+k4OOur#Z{e~=c zKgC8#u2aAbGB1)zZU>ry7Rr&koUEcSwtXr6?cTZaYOB?#`pt5^DXO<|2pgMd;en|m zQ!?=}#UF%GDaZ^CrqmFfQ52zWF38gq^9-3aGBq+IYri_Y9c|ldhzw{JG#yL4o`(#` zGIyv0tGBhQ;EOEEvfvX{wvK}iaL6sZQ=E*w{((5Fns~OXj?foW%WyilAgk}ndWhrj zq=;sK%Xm;q`9M}UUY#`aD8@D)PV?xN9Cbv^e9Z^S@>x_a>7Ydt@v*dEQsY()^_<7x l1VUo(`OTKtYE)l<)=-CY9$1n3?3rHLOL>lW+{<~X{{Ry@2RHx# literal 0 HcmV?d00001 diff --git a/test/alice.txt b/test/alice.txt new file mode 100644 index 0000000..84bf3cc --- /dev/null +++ b/test/alice.txt @@ -0,0 +1,17 @@ +Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversations?' +So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. +There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge. +In another moment down went Alice after it, never once considering how in the world she was to get out again. +The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. +Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it. +'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs! How brave they'll all think me at home! Why, I wouldn't say anything about it, even if I fell off the top of the house!' (Which was very likely true.) +Down, down, down. Would the fall NEVER come to an end! 'I wonder how many miles I've fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth. Let me see: that would be four thousand miles down, I think—' (for, you see, Alice had learnt several things of this sort in her lessons in the schoolroom, and though this was not a VERY good opportunity for showing off her knowledge, as there was no one to listen to her, still it was good practice to say it over) '—yes, that's about the right distance—but then I wonder what Latitude or Longitude I've got to?' (Alice had no idea what Latitude was, or Longitude either, but thought they were nice grand words to say.) +Presently she began again. 'I wonder if I shall fall right THROUGH the earth! How funny it'll seem to come out among the people that walk with their heads downward! The Antipathies, I think—' (she was rather glad there WAS no one listening, this time, as it didn't sound at all the right word) '—but I shall have to ask them what the name of the country is, you know. Please, Ma'am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke—fancy CURTSEYING as you're falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she'll think me for asking! No, it'll never do to ask: perhaps I shall see it written up somewhere.' +Down, down, down. There was nothing else to do, so Alice soon began talking again. 'Dinah'll miss me very much to-night, I should think!' (Dinah was the cat.) 'I hope they'll remember her saucer of milk at tea-time. Dinah my dear! I wish you were down here with me! There are no mice in the air, I'm afraid, but you might catch a bat, and that's very like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats eat cats?' for, you see, as she couldn't answer either question, it didn't much matter which way she put it. She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump! thump! down she came upon a heap of sticks and dry leaves, and the fall was over. +Alice was not a bit hurt, and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was another long passage, and the White Rabbit was still in sight, hurrying down it. There was not a moment to be lost: away went Alice like the wind, and was just in time to hear it say, as it turned a corner, 'Oh my ears and whiskers, how late it's getting!' She was close behind it when she turned the corner, but the Rabbit was no longer to be seen: she found herself in a long, low hall, which was lit up by a row of lamps hanging from the roof. +There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. +Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted! +Alice opened the door and found that it led into a small passage, not much larger than a rat-hole: she knelt down and looked along the passage into the loveliest garden you ever saw. How she longed to get out of that dark hall, and wander about among those beds of bright flowers and those cool fountains, but she could not even get her head through the doorway; 'and even if my head would go through,' thought poor Alice, 'it would be of very little use without my shoulders. Oh, how I wish I could shut up like a telescope! I think I could, if I only knew how to begin.' For, you see, so many out-of-the-way things had happened lately, that Alice had begun to think that very few things indeed were really impossible. +There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes: this time she found a little bottle on it, ('which certainly was not here before,' said Alice,) and round the neck of the bottle was a paper label, with the words 'DRINK ME' beautifully printed on it in large letters. +It was all very well to say 'Drink me,' but the wise little Alice was not going to do THAT in a hurry. 'No, I'll look first,' she said, 'and see whether it's marked "poison" or not'; for she had read several nice little histories about children who had got burnt, and eaten up by wild beasts and other unpleasant things, all because they WOULD not remember the simple rules their friends had taught them: such as, that a red-hot poker will burn you if you hold it too long; and that if you cut your finger VERY deeply with a knife, it usually bleeds; and she had never forgotten that, if you drink much from a bottle marked 'poison,' it is almost certain to disagree with you, sooner or later. +However, this bottle was NOT marked 'poison,' so Alice ventured to taste it, and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very soon finished it off. diff --git a/test/example.py b/test/example.py new file mode 100644 index 0000000..44661ce --- /dev/null +++ b/test/example.py @@ -0,0 +1,23 @@ +number_lines=0 +words=[] +chars=[] + +with open('alice.txt','r') as readfile: + for line in readfile: + number_lines+=1 + print(line) + words+=line.split(" ") + print(number_lines) + + char_count= [ len(i) for i in words] + for j in char_count: + print(j) + + print("char_count",sum(char_count) ) + + + #print("Char count is :",sum(chars)) + print("words count",len(words)) + + + diff --git a/test/test_assessment.py b/test/test_assessment.py new file mode 100644 index 0000000..2d6fafd --- /dev/null +++ b/test/test_assessment.py @@ -0,0 +1,95 @@ +from src.assessment import Assessment +import numpy as np +import pandas as pd + + +def test_count_characters(): + + a=Assessment() + string = "abafdcggfaabe" + answer = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2} + result = a.count_characters(string) + assert result==answer + #assertEqual(result, answer) + + +def test_invert_dictionary(): + a=Assessment() + d = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2} + result = {4: {'a'}, 2: {'f', 'g', 'b'}, 1: {'c', 'e', 'd'}} + + assert result==a.invert_dictionary(d) + + + +def test_word_count(): + + a=Assessment() + result=a.word_count('alice.txt') + assert result==(17, 1615, 6863) + +def test_matrix_multiplication(): + a=Assessment() + A = [[2, 3, 4], [6, 4, 2], [-1, 2, 0]] + B = [[8, -3, 1], [-7, 3, 2], [0, 3, 3]] + answer = [[-5, 15, 20], [20, 0, 20], [-22, 9, 3]] + assert answer==a.matrix_multiplication(A,B) + + +# def test_array_work(self): +# matrixA = np.array([[-4, -2], +# [0, -3], +# [-4, -1], +# [-1, 1], +# [-3, 0]]) +# answer1 = np.array([[-24, -24, -24], +# [-12, -12, -12], +# [-20, -20, -20], +# [0, 0, 0], +# [-12, -12, -12]]) +# result1 = a.array_work(2, 3, 4, matrixA) +# self.assertTrue(np.all(answer1 == result1)) + +# answer2 = np.array([[-36, -36], +# [-18, -18], +# [-30, -30], +# [0, 0], +# [-18, -18]]) +# result2 = a.array_work(2, 2, 6, matrixA) +# self.assertTrue(np.all(answer2 == result2)) + + +def test_make_series(): + a=Assessment() + result = a.make_series(7, 4, ['a', 'b', 'c', 'd']) + assert isinstance(result, pd.Series) + assert result['a']== 7 + assert result['d']== 10 + + result = a.make_series(22, 5, ['a', 'b', 'c', 'd', 'hi']) + assert result['a']== 22 + assert result['d']== 25 + assert result['hi']== 26 + + +def test_data_frame_work(): + a=Assessment() + df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) + colA, colB, colC = ('a', 'b', 'c') + a.data_frame_work(df, colA, colB, colC) + assert (colC in df.columns.tolist()) + assert (df[colC].tolist(), [5, 7, 9]) + + +def test_boolean_indexing(): + arr = np.array([[-4, -4, -3], + [-1, 16, -4], + [-3, 6, 4]]) + a=Assessment() + result1 = a.boolean_indexing(arr,0) + answer1 = np.array([16, 6, 4]) + assert (np.all(result1 == answer1)) + result2 = a.boolean_indexing(arr, 10) + answer2 = np.array([16]) + assert (np.all(result2 == answer2)) + diff --git a/testing.py b/testing.py deleted file mode 100644 index c68b010..0000000 --- a/testing.py +++ /dev/null @@ -1,77 +0,0 @@ -def test_count_characters(self): - string = "abafdcggfaabe" - answer = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2} - result = a.count_characters(string) - self.assertEqual(result, answer) - - -def test_invert_dictionary(self): - d = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2} - result = {4: {'a'}, 2: {'b', 'f', 'g'}, 1: {'c', 'd', 'e'}} - self.assertEqual(a.invert_dictionary(d), result) - - -def test_word_count(self): - self.assertEqual(a.word_count('data/alice.txt'), (17, 1615, 8449)) - - -def test_matrix_multiplication(self): - A = [[2, 3, 4], [6, 4, 2], [-1, 2, 0]] - B = [[8, -3, 1], [-7, 3, 2], [0, 3, 3]] - answer = [[-5, 15, 20], [20, 0, 20], [-22, 9, 3]] - self.assertEqual(a.matrix_multiplication(A, B), answer) - - -def test_array_work(self): - matrixA = np.array([[-4, -2], - [0, -3], - [-4, -1], - [-1, 1], - [-3, 0]]) - answer1 = np.array([[-24, -24, -24], - [-12, -12, -12], - [-20, -20, -20], - [0, 0, 0], - [-12, -12, -12]]) - result1 = a.array_work(2, 3, 4, matrixA) - self.assertTrue(np.all(answer1 == result1)) - - answer2 = np.array([[-36, -36], - [-18, -18], - [-30, -30], - [0, 0], - [-18, -18]]) - result2 = a.array_work(2, 2, 6, matrixA) - self.assertTrue(np.all(answer2 == result2)) - - -def test_make_series(self): - result = a.make_series(7, 4, ['a', 'b', 'c', 'd']) - self.assertTrue(isinstance(result, pd.Series)) - self.assertEqual(result['a'], 7) - self.assertEqual(result['d'], 10) - - result = a.make_series(22, 5, ['a', 'b', 'c', 'd', 'hi']) - self.assertEqual(result['a'], 22) - self.assertEqual(result['d'], 25) - self.assertEqual(result['hi'], 26) - - -def test_data_frame_work(self): - df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) - colA, colB, colC = ('a', 'b', 'c') - a.data_frame_work(df, colA, colB, colC) - self.assertTrue(colC in df.columns.tolist()) - self.assertEqual(df[colC].tolist(), [5, 7, 9]) - - -def test_boolean_indexing(self): - arr = np.array([[-4, -4, -3], - [-1, 16, -4], - [-3, 6, 4]]) - result1 = a.boolean_indexing(arr, 0) - answer1 = np.array([16, 6, 4]) - self.assertTrue(np.all(result1 == answer1)) - result2 = a.boolean_indexing(arr, 10) - answer2 = np.array([16]) - self.assertTrue(np.all(result2 == answer2)) diff --git a/titanic_survivor_model.ipynb b/titanic_survivor_model.ipynb new file mode 100644 index 0000000..c451ecd --- /dev/null +++ b/titanic_survivor_model.ipynb @@ -0,0 +1,2045 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\statsmodels\\compat\\pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.\n", + " from pandas.core import datetools\n" + ] + } + ], + "source": [ + "import numpy as n\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "import statsmodels.api as sm\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.metrics import r2_score\n", + "from pandas.plotting import scatter_matrix\n", + "from sklearn.linear_model import LogisticRegression\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "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", + "
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
\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", + "\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", + "\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 " + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df=pd.read_csv(\"train.csv\", index_col='PassengerId')\n", + "df.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Int64Index: 891 entries, 1 to 891\n", + "Data columns (total 11 columns):\n", + "Survived 891 non-null int64\n", + "Pclass 891 non-null int64\n", + "Name 891 non-null object\n", + "Sex 891 non-null object\n", + "Age 714 non-null float64\n", + "SibSp 891 non-null int64\n", + "Parch 891 non-null int64\n", + "Ticket 891 non-null object\n", + "Fare 891 non-null float64\n", + "Cabin 204 non-null object\n", + "Embarked 889 non-null object\n", + "dtypes: float64(2), int64(4), object(5)\n", + "memory usage: 83.5+ KB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "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
603Moran, Mr. JamesmaleNaN003308778.4583NaNQ
1812Williams, Mr. Charles EugenemaleNaN0024437313.0000NaNS
2013Masselmani, Mrs. FatimafemaleNaN0026497.2250NaNC
2703Emir, Mr. Farred ChehabmaleNaN0026317.2250NaNC
2913O'Dwyer, Miss. Ellen \"Nellie\"femaleNaN003309597.8792NaNQ
3003Todoroff, Mr. LaliomaleNaN003492167.8958NaNS
3211Spencer, Mrs. William Augustus (Marie Eugenie)femaleNaN10PC 17569146.5208B78C
3313Glynn, Miss. Mary AgathafemaleNaN003356777.7500NaNQ
3713Mamee, Mr. HannamaleNaN0026777.2292NaNC
4303Kraeff, Mr. TheodormaleNaN003492537.8958NaNC
4603Rogers, Mr. William JohnmaleNaN00S.C./A.4. 235678.0500NaNS
4703Lennon, Mr. DenismaleNaN1037037115.5000NaNQ
4813O'Driscoll, Miss. BridgetfemaleNaN00143117.7500NaNQ
4903Samaan, Mr. YoussefmaleNaN20266221.6792NaNC
5611Woolner, Mr. HughmaleNaN001994735.5000C52S
6501Stewart, Mr. Albert AmaleNaN00PC 1760527.7208NaNC
6613Moubarek, Master. GeriosmaleNaN11266115.2458NaNC
7703Staneff, Mr. IvanmaleNaN003492087.8958NaNS
7803Moutal, Mr. Rahamin HaimmaleNaN003747468.0500NaNS
8313McDermott, Miss. Brigdet DeliafemaleNaN003309327.7875NaNQ
8803Slocovski, Mr. Selman FrancismaleNaN00SOTON/OQ 3920868.0500NaNS
9603Shorney, Mr. Charles JosephmaleNaN003749108.0500NaNS
10203Petroff, Mr. Pastcho (\"Pentcho\")maleNaN003492157.8958NaNS
10813Moss, Mr. Albert JohanmaleNaN003129917.7750NaNS
11013Moran, Miss. BerthafemaleNaN1037111024.1500NaNQ
12203Moore, Mr. Leonard CharlesmaleNaN00A4. 545108.0500NaNS
12703McMahon, Mr. MartinmaleNaN003703727.7500NaNQ
12913Peter, Miss. AnnafemaleNaN11266822.3583F E69C
14103Boulos, Mrs. Joseph (Sultana)femaleNaN02267815.2458NaNC
15503Olsen, Mr. Ole MartinmaleNaN00Fa 2653027.3125NaNS
....................................
71903McEvoy, Mr. MichaelmaleNaN003656815.5000NaNQ
72813Mannion, Miss. MargarethfemaleNaN00368667.7375NaNQ
73302Knight, Mr. Robert JmaleNaN002398550.0000NaNS
73903Ivanoff, Mr. KaniomaleNaN003492017.8958NaNS
74003Nankoff, Mr. MinkomaleNaN003492187.8958NaNS
74111Hawksford, Mr. Walter JamesmaleNaN001698830.0000D45S
76103Garfirth, Mr. JohnmaleNaN0035858514.5000NaNS
76701Brewe, Dr. Arthur JacksonmaleNaN0011237939.6000NaNC
76903Moran, Mr. Daniel JmaleNaN1037111024.1500NaNQ
77403Elias, Mr. DibomaleNaN0026747.2250NaNC
77703Tobin, Mr. RogermaleNaN003831217.7500F38Q
77903Kilgannon, Mr. Thomas JmaleNaN00368657.7375NaNQ
78403Johnston, Mr. Andrew GmaleNaN12W./C. 660723.4500NaNS
79103Keane, Mr. Andrew \"Andy\"maleNaN00124607.7500NaNQ
79303Sage, Miss. Stella AnnafemaleNaN82CA. 234369.5500NaNS
79401Hoyt, Mr. William FishermaleNaN00PC 1760030.6958NaNC
81601Fry, Mr. RichardmaleNaN001120580.0000B102S
82603Flynn, Mr. JohnmaleNaN003683236.9500NaNQ
82703Lam, Mr. LenmaleNaN00160156.4958NaNS
82913McCormack, Mr. Thomas JosephmaleNaN003672287.7500NaNQ
83303Saad, Mr. AminmaleNaN0026717.2292NaNC
83803Sirota, Mr. MauricemaleNaN003920928.0500NaNS
84011Marechal, Mr. PierremaleNaN001177429.7000C47C
84703Sage, Mr. Douglas BullenmaleNaN82CA. 234369.5500NaNS
85011Goldenberg, Mrs. Samuel L (Edwiga Grabowska)femaleNaN101745389.1042C92C
86003Razi, Mr. RaihedmaleNaN0026297.2292NaNC
86403Sage, Miss. Dorothy Edith \"Dolly\"femaleNaN82CA. 234369.5500NaNS
86903van Melkebeke, Mr. PhilemonmaleNaN003457779.5000NaNS
87903Laleff, Mr. KristomaleNaN003492177.8958NaNS
88903Johnston, Miss. Catherine Helen \"Carrie\"femaleNaN12W./C. 660723.4500NaNS
\n", + "

177 rows × 11 columns

\n", + "
" + ], + "text/plain": [ + " Survived Pclass Name \\\n", + "PassengerId \n", + "6 0 3 Moran, Mr. James \n", + "18 1 2 Williams, Mr. Charles Eugene \n", + "20 1 3 Masselmani, Mrs. Fatima \n", + "27 0 3 Emir, Mr. Farred Chehab \n", + "29 1 3 O'Dwyer, Miss. Ellen \"Nellie\" \n", + "30 0 3 Todoroff, Mr. Lalio \n", + "32 1 1 Spencer, Mrs. William Augustus (Marie Eugenie) \n", + "33 1 3 Glynn, Miss. Mary Agatha \n", + "37 1 3 Mamee, Mr. Hanna \n", + "43 0 3 Kraeff, Mr. Theodor \n", + "46 0 3 Rogers, Mr. William John \n", + "47 0 3 Lennon, Mr. Denis \n", + "48 1 3 O'Driscoll, Miss. Bridget \n", + "49 0 3 Samaan, Mr. Youssef \n", + "56 1 1 Woolner, Mr. Hugh \n", + "65 0 1 Stewart, Mr. Albert A \n", + "66 1 3 Moubarek, Master. Gerios \n", + "77 0 3 Staneff, Mr. Ivan \n", + "78 0 3 Moutal, Mr. Rahamin Haim \n", + "83 1 3 McDermott, Miss. Brigdet Delia \n", + "88 0 3 Slocovski, Mr. Selman Francis \n", + "96 0 3 Shorney, Mr. Charles Joseph \n", + "102 0 3 Petroff, Mr. Pastcho (\"Pentcho\") \n", + "108 1 3 Moss, Mr. Albert Johan \n", + "110 1 3 Moran, Miss. Bertha \n", + "122 0 3 Moore, Mr. Leonard Charles \n", + "127 0 3 McMahon, Mr. Martin \n", + "129 1 3 Peter, Miss. Anna \n", + "141 0 3 Boulos, Mrs. Joseph (Sultana) \n", + "155 0 3 Olsen, Mr. Ole Martin \n", + "... ... ... ... \n", + "719 0 3 McEvoy, Mr. Michael \n", + "728 1 3 Mannion, Miss. Margareth \n", + "733 0 2 Knight, Mr. Robert J \n", + "739 0 3 Ivanoff, Mr. Kanio \n", + "740 0 3 Nankoff, Mr. Minko \n", + "741 1 1 Hawksford, Mr. Walter James \n", + "761 0 3 Garfirth, Mr. John \n", + "767 0 1 Brewe, Dr. Arthur Jackson \n", + "769 0 3 Moran, Mr. Daniel J \n", + "774 0 3 Elias, Mr. Dibo \n", + "777 0 3 Tobin, Mr. Roger \n", + "779 0 3 Kilgannon, Mr. Thomas J \n", + "784 0 3 Johnston, Mr. Andrew G \n", + "791 0 3 Keane, Mr. Andrew \"Andy\" \n", + "793 0 3 Sage, Miss. Stella Anna \n", + "794 0 1 Hoyt, Mr. William Fisher \n", + "816 0 1 Fry, Mr. Richard \n", + "826 0 3 Flynn, Mr. John \n", + "827 0 3 Lam, Mr. Len \n", + "829 1 3 McCormack, Mr. Thomas Joseph \n", + "833 0 3 Saad, Mr. Amin \n", + "838 0 3 Sirota, Mr. Maurice \n", + "840 1 1 Marechal, Mr. Pierre \n", + "847 0 3 Sage, Mr. Douglas Bullen \n", + "850 1 1 Goldenberg, Mrs. Samuel L (Edwiga Grabowska) \n", + "860 0 3 Razi, Mr. Raihed \n", + "864 0 3 Sage, Miss. Dorothy Edith \"Dolly\" \n", + "869 0 3 van Melkebeke, Mr. Philemon \n", + "879 0 3 Laleff, Mr. Kristo \n", + "889 0 3 Johnston, Miss. Catherine Helen \"Carrie\" \n", + "\n", + " Sex Age SibSp Parch Ticket Fare Cabin \\\n", + "PassengerId \n", + "6 male NaN 0 0 330877 8.4583 NaN \n", + "18 male NaN 0 0 244373 13.0000 NaN \n", + "20 female NaN 0 0 2649 7.2250 NaN \n", + "27 male NaN 0 0 2631 7.2250 NaN \n", + "29 female NaN 0 0 330959 7.8792 NaN \n", + "30 male NaN 0 0 349216 7.8958 NaN \n", + "32 female NaN 1 0 PC 17569 146.5208 B78 \n", + "33 female NaN 0 0 335677 7.7500 NaN \n", + "37 male NaN 0 0 2677 7.2292 NaN \n", + "43 male NaN 0 0 349253 7.8958 NaN \n", + "46 male NaN 0 0 S.C./A.4. 23567 8.0500 NaN \n", + "47 male NaN 1 0 370371 15.5000 NaN \n", + "48 female NaN 0 0 14311 7.7500 NaN \n", + "49 male NaN 2 0 2662 21.6792 NaN \n", + "56 male NaN 0 0 19947 35.5000 C52 \n", + "65 male NaN 0 0 PC 17605 27.7208 NaN \n", + "66 male NaN 1 1 2661 15.2458 NaN \n", + "77 male NaN 0 0 349208 7.8958 NaN \n", + "78 male NaN 0 0 374746 8.0500 NaN \n", + "83 female NaN 0 0 330932 7.7875 NaN \n", + "88 male NaN 0 0 SOTON/OQ 392086 8.0500 NaN \n", + "96 male NaN 0 0 374910 8.0500 NaN \n", + "102 male NaN 0 0 349215 7.8958 NaN \n", + "108 male NaN 0 0 312991 7.7750 NaN \n", + "110 female NaN 1 0 371110 24.1500 NaN \n", + "122 male NaN 0 0 A4. 54510 8.0500 NaN \n", + "127 male NaN 0 0 370372 7.7500 NaN \n", + "129 female NaN 1 1 2668 22.3583 F E69 \n", + "141 female NaN 0 2 2678 15.2458 NaN \n", + "155 male NaN 0 0 Fa 265302 7.3125 NaN \n", + "... ... ... ... ... ... ... ... \n", + "719 male NaN 0 0 36568 15.5000 NaN \n", + "728 female NaN 0 0 36866 7.7375 NaN \n", + "733 male NaN 0 0 239855 0.0000 NaN \n", + "739 male NaN 0 0 349201 7.8958 NaN \n", + "740 male NaN 0 0 349218 7.8958 NaN \n", + "741 male NaN 0 0 16988 30.0000 D45 \n", + "761 male NaN 0 0 358585 14.5000 NaN \n", + "767 male NaN 0 0 112379 39.6000 NaN \n", + "769 male NaN 1 0 371110 24.1500 NaN \n", + "774 male NaN 0 0 2674 7.2250 NaN \n", + "777 male NaN 0 0 383121 7.7500 F38 \n", + "779 male NaN 0 0 36865 7.7375 NaN \n", + "784 male NaN 1 2 W./C. 6607 23.4500 NaN \n", + "791 male NaN 0 0 12460 7.7500 NaN \n", + "793 female NaN 8 2 CA. 2343 69.5500 NaN \n", + "794 male NaN 0 0 PC 17600 30.6958 NaN \n", + "816 male NaN 0 0 112058 0.0000 B102 \n", + "826 male NaN 0 0 368323 6.9500 NaN \n", + "827 male NaN 0 0 1601 56.4958 NaN \n", + "829 male NaN 0 0 367228 7.7500 NaN \n", + "833 male NaN 0 0 2671 7.2292 NaN \n", + "838 male NaN 0 0 392092 8.0500 NaN \n", + "840 male NaN 0 0 11774 29.7000 C47 \n", + "847 male NaN 8 2 CA. 2343 69.5500 NaN \n", + "850 female NaN 1 0 17453 89.1042 C92 \n", + "860 male NaN 0 0 2629 7.2292 NaN \n", + "864 female NaN 8 2 CA. 2343 69.5500 NaN \n", + "869 male NaN 0 0 345777 9.5000 NaN \n", + "879 male NaN 0 0 349217 7.8958 NaN \n", + "889 female NaN 1 2 W./C. 6607 23.4500 NaN \n", + "\n", + " Embarked \n", + "PassengerId \n", + "6 Q \n", + "18 S \n", + "20 C \n", + "27 C \n", + "29 Q \n", + "30 S \n", + "32 C \n", + "33 Q \n", + "37 C \n", + "43 C \n", + "46 S \n", + "47 Q \n", + "48 Q \n", + "49 C \n", + "56 S \n", + "65 C \n", + "66 C \n", + "77 S \n", + "78 S \n", + "83 Q \n", + "88 S \n", + "96 S \n", + "102 S \n", + "108 S \n", + "110 Q \n", + "122 S \n", + "127 Q \n", + "129 C \n", + "141 C \n", + "155 S \n", + "... ... \n", + "719 Q \n", + "728 Q \n", + "733 S \n", + "739 S \n", + "740 S \n", + "741 S \n", + "761 S \n", + "767 C \n", + "769 Q \n", + "774 C \n", + "777 Q \n", + "779 Q \n", + "784 S \n", + "791 Q \n", + "793 S \n", + "794 C \n", + "816 S \n", + "826 Q \n", + "827 S \n", + "829 Q \n", + "833 C \n", + "838 S \n", + "840 C \n", + "847 S \n", + "850 C \n", + "860 C \n", + "864 S \n", + "869 S \n", + "879 S \n", + "889 S \n", + "\n", + "[177 rows x 11 columns]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#df[df.horsepower.isna()]\n", + "df[df.Age.isnull()]" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "29.69911764705882" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Does it make sense to calculate male mean and female mean seperately ? \n", + "age_mean=df.Age.mean()\n", + "age_mean" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "df['Age']=df.Age.fillna(age_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Int64Index: 891 entries, 1 to 891\n", + "Data columns (total 11 columns):\n", + "Survived 891 non-null int64\n", + "Pclass 891 non-null int64\n", + "Name 891 non-null object\n", + "Sex 891 non-null object\n", + "Age 891 non-null float64\n", + "SibSp 891 non-null int64\n", + "Parch 891 non-null int64\n", + "Ticket 891 non-null object\n", + "Fare 891 non-null float64\n", + "Cabin 204 non-null object\n", + "Embarked 889 non-null object\n", + "dtypes: float64(2), int64(4), object(5)\n", + "memory usage: 83.5+ KB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "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", + "
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
\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", + "\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", + "\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 " + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#male=0 female=1\n", + "df.Sex=pd.get_dummies(df.Sex)\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "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", + "
SurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
PassengerId
103Braund, Mr. Owen Harris022.010A/5 211717.2500NaNS
211Cumings, Mrs. John Bradley (Florence Briggs Th...138.010PC 1759971.2833C85C
313Heikkinen, Miss. Laina126.000STON/O2. 31012827.9250NaNS
411Futrelle, Mrs. Jacques Heath (Lily May Peel)135.01011380353.1000C123S
503Allen, Mr. William Henry035.0003734508.0500NaNS
\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", + "\n", + " Name Sex Age \\\n", + "PassengerId \n", + "1 Braund, Mr. Owen Harris 0 22.0 \n", + "2 Cumings, Mrs. John Bradley (Florence Briggs Th... 1 38.0 \n", + "3 Heikkinen, Miss. Laina 1 26.0 \n", + "4 Futrelle, Mrs. Jacques Heath (Lily May Peel) 1 35.0 \n", + "5 Allen, Mr. William Henry 0 35.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 " + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "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", + "
PclassNameSexAgeSibSpParch
PassengerId
13Braund, Mr. Owen Harris022.010
21Cumings, Mrs. John Bradley (Florence Briggs Th...138.010
33Heikkinen, Miss. Laina126.000
41Futrelle, Mrs. Jacques Heath (Lily May Peel)135.010
53Allen, Mr. William Henry035.000
\n", + "
" + ], + "text/plain": [ + " Pclass Name Sex \\\n", + "PassengerId \n", + "1 3 Braund, Mr. Owen Harris 0 \n", + "2 1 Cumings, Mrs. John Bradley (Florence Briggs Th... 1 \n", + "3 3 Heikkinen, Miss. Laina 1 \n", + "4 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 1 \n", + "5 3 Allen, Mr. William Henry 0 \n", + "\n", + " Age SibSp Parch \n", + "PassengerId \n", + "1 22.0 1 0 \n", + "2 38.0 1 0 \n", + "3 26.0 0 0 \n", + "4 35.0 1 0 \n", + "5 35.0 0 0 " + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X = df.drop(['Survived','Cabin', 'Fare','Ticket','Embarked'],axis=1)\n", + "X.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PassengerId\n", + "1 0\n", + "2 1\n", + "3 1\n", + "4 1\n", + "5 0\n", + "Name: Survived, dtype: int64" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "y = df.Survived\n", + "y.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 549\n", + "1 342\n", + "Name: Survived, dtype: int64" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.Survived.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6229508196721312" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "342/549" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(596, 6)" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X_train.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(295, 6)" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X_test.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "could not convert string to float: 'male'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mmodel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[0;32m 1214\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1215\u001b[0m X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype,\n\u001b[1;32m-> 1216\u001b[1;33m order=\"C\")\n\u001b[0m\u001b[0;32m 1217\u001b[0m \u001b[0mcheck_classification_targets\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1218\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclasses_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munique\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_X_y\u001b[1;34m(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 571\u001b[0m X = check_array(X, accept_sparse, dtype, order, copy, force_all_finite,\n\u001b[0;32m 572\u001b[0m \u001b[0mensure_2d\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mallow_nd\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mensure_min_samples\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 573\u001b[1;33m ensure_min_features, warn_on_dtype, estimator)\n\u001b[0m\u001b[0;32m 574\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmulti_output\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 575\u001b[0m y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,\n", + "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[1;34m(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 431\u001b[0m force_all_finite)\n\u001b[0;32m 432\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 433\u001b[1;33m \u001b[0marray\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 434\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 435\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mensure_2d\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: could not convert string to float: 'male'" + ] + } + ], + "source": [ + "model = LogisticRegression()\n", + "model.fit(X_train, y_train)" + ] + }, + { + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 8e07450c6cd5446269cab1479797bd5795a48e6d Mon Sep 17 00:00:00 2001 From: Chidella Date: Mon, 23 Jul 2018 12:28:42 -0400 Subject: [PATCH 2/2] ContinueLearning, second version, removed hard coded value from invert_dictionary method --- .cache/v/cache/lastfailed | 3 +- src/__pycache__/assessment.cpython-36.pyc | Bin 2496 -> 2456 bytes src/assessment.py | 4 +- titanic_survivor_model.ipynb | 293 ++++++++++------------ 4 files changed, 134 insertions(+), 166 deletions(-) diff --git a/.cache/v/cache/lastfailed b/.cache/v/cache/lastfailed index ba39895..956c931 100644 --- a/.cache/v/cache/lastfailed +++ b/.cache/v/cache/lastfailed @@ -1,4 +1,3 @@ { - "test/test_assessment.py::test_array_work": true, - "test/test_assessment.py::test_invert_dictionary": true + "test/test_assessment.py::test_array_work": true } \ No newline at end of file diff --git a/src/__pycache__/assessment.cpython-36.pyc b/src/__pycache__/assessment.cpython-36.pyc index 7f28aa871f6782cd46d238a2d7936609c2449e67..0ca1d5461e0cc9a64d8e7c273a7df08bcde8a82e 100644 GIT binary patch delta 288 zcmX>gJVTh%n3tF99%EQ^_eRbTrg}C81_l-&b_U|&3?PxoP|H-p(9BTFToF;jn8n!4 z;KC5=6T?)?Qp;MxRKrrk+RVhrP{WkPT*I2e*vyo|n9Wq=Qo>Nf(#%-HRKse+P$&YC zZDy=xu3^q%0m%S$FvDcSfx3ekG@1O0*cm4OWm4i~D+0OT7Gug}U1l3L5g?m^X>%d- zVn!hWkT`2`K~84LE#~6V+#-p|YOGd_(wh@m1sD}1fU=tGP|Xpy7$a}76{QxJ=9Coi v0A-3qHcw=8WMov{e3{*!QA!jfqy!=~K!g^EFa!~1lWjNy7u%)mxGo`R(GZh7tFx0R% zGu8mbY#0g^AhOMjwJbF(Su7wKpbi$8tXw!ydoY70tKUl|pye+?PSIq(#h7@DG3gd# z^5mOLs(kE4AkkZlDMj2sdNMn+4Tl(z!NADFxY?6=F{6+uNSd{{ASbir7ISfFZjtQd ze=Jsv3Y#ri1sEA+CwsBUF-mUEWOHO>)Y!b5-JelP3aFz<9YpAY2z?M?1|qB{i*N=o K8ct5-GzI`YAVGfs diff --git a/src/assessment.py b/src/assessment.py index 7626c0d..ef79404 100644 --- a/src/assessment.py +++ b/src/assessment.py @@ -22,10 +22,10 @@ def count_characters(self,string): def invert_dictionary(self,d): - dict={'a': 2, 'b': 4,'c':2} + dict_new={} s=set() - for i,j in dict.items(): + for i,j in d.items(): print(i,j) if dict_new.get(j,'novalue')=='novalue': dict_new[j]=set(i) diff --git a/titanic_survivor_model.ipynb b/titanic_survivor_model.ipynb index c451ecd..7e3e41b 100644 --- a/titanic_survivor_model.ipynb +++ b/titanic_survivor_model.ipynb @@ -1343,7 +1343,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 82, "metadata": {}, "outputs": [ { @@ -1352,7 +1352,7 @@ "29.69911764705882" ] }, - "execution_count": 29, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -1365,7 +1365,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 83, "metadata": { "collapsed": true }, @@ -1376,7 +1376,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 84, "metadata": {}, "outputs": [ { @@ -1389,7 +1389,7 @@ "Survived 891 non-null int64\n", "Pclass 891 non-null int64\n", "Name 891 non-null object\n", - "Sex 891 non-null object\n", + "Sex 891 non-null uint8\n", "Age 891 non-null float64\n", "SibSp 891 non-null int64\n", "Parch 891 non-null int64\n", @@ -1397,8 +1397,8 @@ "Fare 891 non-null float64\n", "Cabin 204 non-null object\n", "Embarked 889 non-null object\n", - "dtypes: float64(2), int64(4), object(5)\n", - "memory usage: 83.5+ KB\n" + "dtypes: float64(2), int64(4), object(4), uint8(1)\n", + "memory usage: 117.4+ KB\n" ] } ], @@ -1408,7 +1408,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 85, "metadata": {}, "outputs": [ { @@ -1465,7 +1465,7 @@ " 0\n", " 3\n", " Braund, Mr. Owen Harris\n", - " male\n", + " 1\n", " 22.0\n", " 1\n", " 0\n", @@ -1479,7 +1479,7 @@ " 1\n", " 1\n", " Cumings, Mrs. John Bradley (Florence Briggs Th...\n", - " female\n", + " 0\n", " 38.0\n", " 1\n", " 0\n", @@ -1493,7 +1493,7 @@ " 1\n", " 3\n", " Heikkinen, Miss. Laina\n", - " female\n", + " 0\n", " 26.0\n", " 0\n", " 0\n", @@ -1507,7 +1507,7 @@ " 1\n", " 1\n", " Futrelle, Mrs. Jacques Heath (Lily May Peel)\n", - " female\n", + " 0\n", " 35.0\n", " 1\n", " 0\n", @@ -1521,7 +1521,7 @@ " 0\n", " 3\n", " Allen, Mr. William Henry\n", - " male\n", + " 1\n", " 35.0\n", " 0\n", " 0\n", @@ -1543,13 +1543,13 @@ "4 1 1 \n", "5 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", + " Name Sex Age \\\n", + "PassengerId \n", + "1 Braund, Mr. Owen Harris 1 22.0 \n", + "2 Cumings, Mrs. John Bradley (Florence Briggs Th... 0 38.0 \n", + "3 Heikkinen, Miss. Laina 0 26.0 \n", + "4 Futrelle, Mrs. Jacques Heath (Lily May Peel) 0 35.0 \n", + "5 Allen, Mr. William Henry 1 35.0 \n", "\n", " SibSp Parch Ticket Fare Cabin Embarked \n", "PassengerId \n", @@ -1560,7 +1560,7 @@ "5 0 0 373450 8.0500 NaN S " ] }, - "execution_count": 32, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -1571,15 +1571,26 @@ }, { "cell_type": "code", - "execution_count": 66, - "metadata": { - "collapsed": true - }, - "outputs": [], + "execution_count": 86, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 577\n", + "1 314\n", + "Name: Sex, dtype: int64" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#male=0 female=1\n", "df.Sex=pd.get_dummies(df.Sex)\n", - "df" + "df.Sex.value_counts()" ] }, { @@ -1747,128 +1758,35 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 87, "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", - "
PclassNameSexAgeSibSpParch
PassengerId
13Braund, Mr. Owen Harris022.010
21Cumings, Mrs. John Bradley (Florence Briggs Th...138.010
33Heikkinen, Miss. Laina126.000
41Futrelle, Mrs. Jacques Heath (Lily May Peel)135.010
53Allen, Mr. William Henry035.000
\n", - "
" - ], - "text/plain": [ - " Pclass Name Sex \\\n", - "PassengerId \n", - "1 3 Braund, Mr. Owen Harris 0 \n", - "2 1 Cumings, Mrs. John Bradley (Florence Briggs Th... 1 \n", - "3 3 Heikkinen, Miss. Laina 1 \n", - "4 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) 1 \n", - "5 3 Allen, Mr. William Henry 0 \n", - "\n", - " Age SibSp Parch \n", - "PassengerId \n", - "1 22.0 1 0 \n", - "2 38.0 1 0 \n", - "3 26.0 0 0 \n", - "4 35.0 1 0 \n", - "5 35.0 0 0 " - ] - }, - "execution_count": 68, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Int64Index: 891 entries, 1 to 891\n", + "Data columns (total 5 columns):\n", + "Pclass 891 non-null int64\n", + "Sex 891 non-null uint8\n", + "Age 891 non-null float64\n", + "SibSp 891 non-null int64\n", + "Parch 891 non-null int64\n", + "dtypes: float64(1), int64(3), uint8(1)\n", + "memory usage: 75.7 KB\n" + ] } ], "source": [ - "X = df.drop(['Survived','Cabin', 'Fare','Ticket','Embarked'],axis=1)\n", - "X.head()" + "X = df.drop(['Survived','Name','Cabin', 'Fare','Ticket','Embarked'],axis=1)\n", + "X.head()\n", + "X.info()" ] }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 88, "metadata": {}, "outputs": [ { @@ -1883,7 +1801,7 @@ "Name: Survived, dtype: int64" ] }, - "execution_count": 69, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } @@ -1895,7 +1813,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 89, "metadata": {}, "outputs": [ { @@ -1906,7 +1824,7 @@ "Name: Survived, dtype: int64" ] }, - "execution_count": 70, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -1937,7 +1855,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 90, "metadata": { "collapsed": true }, @@ -1948,16 +1866,16 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(596, 6)" + "(596, 5)" ] }, - "execution_count": 72, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -1968,16 +1886,16 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(295, 6)" + "(295, 5)" ] }, - "execution_count": 73, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } @@ -1988,22 +1906,21 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 94, "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "could not convert string to float: 'male'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mmodel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, X, y, sample_weight)\u001b[0m\n\u001b[0;32m 1214\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1215\u001b[0m X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype,\n\u001b[1;32m-> 1216\u001b[1;33m order=\"C\")\n\u001b[0m\u001b[0;32m 1217\u001b[0m \u001b[0mcheck_classification_targets\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1218\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclasses_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munique\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_X_y\u001b[1;34m(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 571\u001b[0m X = check_array(X, accept_sparse, dtype, order, copy, force_all_finite,\n\u001b[0;32m 572\u001b[0m \u001b[0mensure_2d\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mallow_nd\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mensure_min_samples\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 573\u001b[1;33m ensure_min_features, warn_on_dtype, estimator)\n\u001b[0m\u001b[0;32m 574\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmulti_output\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 575\u001b[0m y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,\n", - "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[1;34m(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[0;32m 431\u001b[0m force_all_finite)\n\u001b[0;32m 432\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 433\u001b[1;33m \u001b[0marray\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0morder\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0morder\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 434\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 435\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mensure_2d\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mValueError\u001b[0m: could not convert string to float: 'male'" - ] + "data": { + "text/plain": [ + "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n", + " intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n", + " penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n", + " verbose=0, warm_start=False)" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -2011,6 +1928,58 @@ "model.fit(X_train, y_train)" ] }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1,\n", + " 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0,\n", + " 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0,\n", + " 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0,\n", + " 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,\n", + " 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0,\n", + " 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0,\n", + " 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,\n", + " 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0,\n", + " 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1,\n", + " 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,\n", + " 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0,\n", + " 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0], dtype=int64)" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.predict(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.8203389830508474" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.score(X_test, y_test)" + ] + }, { "cell_type": "code", "execution_count": null,