Skip to content

Instantly share code, notes, and snippets.

@gabrielrojasnyc
Created February 12, 2017 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielrojasnyc/7d8282237d1c19eb583134110846005f to your computer and use it in GitHub Desktop.
Save gabrielrojasnyc/7d8282237d1c19eb583134110846005f to your computer and use it in GitHub Desktop.
gender_submission_2
# coding: utf-8
# In[44]:
import csv
import numpy as np
fh = open('train.csv')
csv_reader = csv.reader(fh)
passanger_list = list(csv_reader)
male_age = []
female_age = []
# First thing to do is find the meadium and mean for two groups Male Female
for row in passanger_list:
if row[5] != '' and row[4] == 'male':
male_age.append(float(row[5]))
elif row[5] != '' and row[4] == 'female':
female_age.append(float(row[5]))
# Two different list have been created. Now to find the mediun
female_np = np.array(female_age)
male_np = np.array(male_age)
female_me_age = np.median(female_np)
male_me_age = np.median(male_np)
# I will add the data to missing fields
for row in passanger_list:
if row[5] == '' and row[4] == 'male':
row[5] = male_me_age
elif row[5] == '' and row[4] == 'female':
row[5] = female_me_age
for row in passanger_list:
print(row)
print(male_me_age)
# In[51]:
# Now I want to find out how many male and female die based on the medium
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male <= 27 and row[1] == '0':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male <= 27 and row[1] == '1':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '0':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '1':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female less than 27 dead {}'.format(count_f_dead))
print('Female less than 27 alive {}'.format(count_f_alive))
print('Total Male less than {}'.format(count_m_alive + count_m_dead))
print('Male less than 29 dead {}'.format(count_m_dead))
print('Males less tnan 29 alive {}'.format(count_m_alive))
# In[54]:
55/186
# In[56]:
# Similar code as above but now i am going to compare first class
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male <= 27 and row[1] == '0' and row[2] == '1':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male <= 27 and row[1] == '1' and row[2] == '1':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '0' and row[2] == '1':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '1'and row[2] == '1':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female less than 27 dead 1st class {}'.format(count_f_dead))
print('Female less than 27 alive 1st class {}'.format(count_f_alive))
print('Total Male less than {}'.format(count_m_alive + count_m_dead))
print('Male less than 29 dead 1st class {}'.format(count_m_dead))
print('Males less tnan 29 alive 1st class {}'.format(count_m_alive))
# In[57]:
# Woot Bing if you were Female and !st class you changes of survival are Great 95.5 %
# Same with secon class
# Similar code as above but now i am going to compare first class
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male <= 27 and row[1] == '0' and row[2] == '2':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male <= 27 and row[1] == '1' and row[2] == '2':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '0' and row[2] == '2':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '1'and row[2] == '2':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female less than 27 dead 2nd class {}'.format(count_f_dead))
print('Female less than 27 alive 2nd class {}'.format(count_f_alive))
print('Total Male less than {}'.format(count_m_alive + count_m_dead))
print('Male less than 29 dead 2nd class {}'.format(count_m_dead))
print('Males less tnan 29 alive 2nd class {}'.format(count_m_alive))
# In[58]:
# another finding on top 96% change if you are Women to be alive
# now lets do third class
# In[63]:
# Woot Bingo if you were Female and !st class you changes of survival are Great 95.5 %
# Same with secon class
# Similar code as above but now i am going to compare first class
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male <= 27 and row[1] == '0' and row[2] == '3':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male <= 27 and row[1] == '1' and row[2] == '3':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '0' and row[2] == '3':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '1'and row[2] == '3':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female less than 27 dead 3rd class {}'.format(count_f_dead))
print('Female less than 27 alive 3rd class {}'.format(count_f_alive))
print('Total Male less than {}'.format(count_m_alive + count_m_dead))
print('Male less than 29 dead 3rd class {}'.format(count_m_dead))
print('Males less tnan 29 alive 3rd class {}'.format(count_m_alive))
# In[76]:
# Ok so if you were male 3rd class 85% probability you died.
# I am going to narrow down with the family column did not change the data much
# i am going to start trying ports now
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
siblings = int(row[6])
if row[4] == 'female' and age_female_male <= 27 and row[1] == '0' and row[2] == '3' and row[11] == 'Q':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male <= 27 and row[1] == '1' and row[2] == '3' and row[11] == 'Q':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '0' and row[2] == '3' and row[11] == 'Q':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male <= 29 and row[1] == '1'and row[2] == '3' and row[11] == 'Q':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female less than 27 dead 3rd class {}'.format(count_f_dead))
print('Female less than 27 alive 3rd class {}'.format(count_f_alive))
print('Total Male less than {}'.format(count_m_alive + count_m_dead))
print('Male less than 29 dead 3rd class {}'.format(count_m_dead))
print('Males less tnan 29 alive 3rd class {}'.format(count_m_alive))
# In[80]:
# This is good finding if you embark in Q and male 91% you died
# If you are female and embark in Q 80% you survive
# In[83]:
# Now i am goin to start focusing above medium
# Now I want to find out how many male and female die based on the medium
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male > 27 and row[1] == '0':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male > 27 and row[1] == '1':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '0':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '1':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
# In[95]:
# Lets get first class passangers
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male > 27 and row[1] == '0' and row[2] == '1':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male > 27 and row[1] == '1' and row[2] == '1':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '0' and row[2] == '1':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '1' and row[2] == '1':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
print(np.percentile(count_f_alive, 56))
# In[87]:
# so Female above 29 1st class survived 98
100- (1/56 *100)
# In[97]:
# Lets get second class passangers
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male > 27 and row[1] == '0' and row[2] == '2':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male > 27 and row[1] == '1' and row[2] == '2':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '0' and row[2] == '2':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '1' and row[2] == '2':
count_m_alive = count_m_alive + 1
print('Total Female less than {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
# In[101]:
# if you are a female 93% change of suvirval
# if yuo are a men 90% of being alive
# In[107]:
# Lets get third class class passangers
# Not much to tell I willl add port
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male > 27 and row[1] == '0' and row[2] == '3' and row[11] == 'Q':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male > 27 and row[1] == '1' and row[2] == '3' and row[11] == 'Q':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '0' and row[2] == '3' and row[11] == 'Q':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '1' and row[2] == '3' and row[11] == 'Q':
count_m_alive = count_m_alive + 1
print('Total Female {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
# In[110]:
# Here if you embar in Q third class you died
# In[109]:
# Lets get third class class passangers
# Not much to tell I willl add port a different port C
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and age_female_male > 27 and row[1] == '0' and row[2] == '3' and row[11] == 'C':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and age_female_male > 27 and row[1] == '1' and row[2] == '3' and row[11] == 'C':
count_f_alive = count_f_alive + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '0' and row[2] == '3' and row[11] == 'C':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and age_female_male > 29 and row[1] == '1' and row[2] == '3' and row[11] == 'C':
count_m_alive = count_m_alive + 1
print('Total Female {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
# In[114]:
count_f_alive = 0
count_m_alive = 0
count_f_dead = 0
count_m_dead = 0
for row in passanger_list[1:]:
age_female_male = float(row[5])
if row[4] == 'female' and row[1] == '0' and row[2] == '3':
count_f_dead = count_f_dead + 1
elif row[4] == 'female' and row[1] == '1' and row[2] == '3':
count_f_alive = count_f_alive + 1
elif row[4] == 'male'and row[1] == '0' and row[2] == '3':
count_m_dead = count_m_dead + 1
elif row[4] == 'male' and row[1] == '1'and row[2] == '3':
count_m_alive = count_m_alive + 1
print('Total Female {}'.format(count_f_alive + count_f_dead))
print('Female greate 27 dead {}'.format(count_f_dead))
print('Female greater 27 alive {}'.format(count_f_alive))
print('Total Male greater than {}'.format(count_m_alive + count_m_dead))
print('Male greater than 29 dead {}'.format(count_m_dead))
print('Males greater tnan 29 alive {}'.format(count_m_alive))
# Male and 3rd class boarded on port C 100% dead
# I will start input this informatiom on Excel
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment