def main():
    # load data from csv file
    full_data, features, labels = tse.DataLoad()
    # Test the 'accuracy_score' function
    predictions = pd.Series(np.ones(5, dtype=int))
    print(tse.Accuracy_score(labels[:5], predictions))
    # Make the predictions
    predictions = tse.Predicton_0(features)
    # whether the feature Sex has any indication of survival rates
    vs.survival_stats(features, labels, 'Sex')
    # Make the predictions
    predictions = tse.Prediction_1(features)
    print(tse.Accuracy_score(labels, predictions))

    vs.survival_stats(features, labels, 'Age', ["Sex == 'male'"])
    # Make the predictions
    predictions = tse.Prediction_2(features)
    print(tse.Accuracy_score(labels, predictions))

    vs.survival_stats(features, labels, 'Age', ["Sex == 'male'", "Age <= 18"])
    # Make the predictions
    predictions = tse.Prediction_2(features)
    print(tse.Accuracy_score(labels, predictions))
predictions = predictions_0(data)

# ### Question 1
#
# * Using the RMS Titanic data, how accurate would a prediction be that none of the passengers survived?
#

print(accuracy_score(outcomes, predictions))

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[19]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[39]:


def predictions_1(data):
    """ Model with one feature:
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
# *Using the RMS Titanic data, how accurate would a prediction be that none of the passengers survived?*
# **Hint:** Run the code cell below to see the accuracy of this prediction.

# In[5]:

print accuracy_score(outcomes, predictions)

# **Answer:** *61.62%*

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[6]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[7]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
# In[ ]:


print(accuracy_score(outcomes, predictions))


# 61.62%

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.  
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[ ]:


vs.survival_stats(data, outcomes, 'Sex')


# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.  
# Fill in the missing code below so that the function will make this prediction.  
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[ ]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 5
0
# *Using the RMS Titanic data, how accurate would a prediction be that none of the passengers survived?*
# **Hint:** Run the code cell below to see the accuracy of this prediction.

# In[33]:

print(accuracy_score(outcomes, predictions))

# Predictions have an accuracy of 61.62%.

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[16]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[5]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 6
0
# In[6]:


print(accuracy_score(outcomes, predictions))


# **Answer:** 61.62%

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.  
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[207]:


vs.survival_stats(data, outcomes, 'Sex')


# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.  
# Fill in the missing code below so that the function will make this prediction.  
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[8]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 7
0
    predictions = []
    for _, passenger in data.iterrows():
        
        # Predict the survival of 'passenger'
        predictions.append(0)
    
    # Return our predictions
    return pd.Series(predictions)

# Make the predictions
predictions = predictions_0(data)
print accuracy_score(outcomes, predictions)

#See the survival stats for gender
vs.survival_stats(data, outcomes, 'Sex')

#Predictions1 - If you're a female, then you survive
def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
        
        #print(passenger['Sex']=='female');
        #If female, then survived; else, did not survived
        if passenger['Sex']=='female':
            predictions.append(1)
        else: 
            predictions.append(0)
Esempio n. 8
0
    """ Model with no features. Always predicts a passenger did not survive. """

    predictions = []
    for _, passenger in data.iterrows():
        
        # Predict the survival of 'passenger'
        predictions.append(0)
    
    # Return our predictions
    return pd.Series(predictions)

# Make the predictions
predictions = predictions_0(data)
print(accuracy_score(outcomes, predictions))

vs.survival_stats(data, outcomes, 'Sex')
def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
        
        # Remove the 'pass' statement below 
        # and write your prediction conditions here
        #pass
     predictions.append(passenger['Sex']=="female")
    
    # Return our predictions
    return pd.Series(predictions)
Esempio n. 9
0
# In[5]:


print(accuracy_score(outcomes, predictions))


# **Answer:** * 61.62%*

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.  
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[6]:


vs.survival_stats(data, outcomes, 'Sex')


# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.  
# Fill in the missing code below so that the function will make this prediction.  
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[7]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 10
0
            predictions.append(1)
        else:
            if passenger['Age'] < 10:
                predictions.append(1)
            else:
                predictions.append(0)
    
    # Return our predictions
    return pd.Series(predictions)

# Make the predictions
predictions = predictions_2(data)

print(accuracy_score(outcomes, predictions))

vs.survival_stats(data, outcomes,'SibSp', ["Sex == 'female'"])

def predictions_3(data):
    """ Model with multiple features. Makes a prediction with an accuracy of at least 80%. """
    
    predictions = []
    for _, passenger in data.iterrows():
        
        # Remove the 'pass' statement below 
        # and write your prediction conditions here
        # Remove the 'pass' statement below 
        # and write your prediction conditions here
        if passenger['Sex'] == 'female':
            if passenger['SibSp'] > 2:
                predictions.append(0)
            else:
Esempio n. 11
0
# *Using the RMS Titanic data, how accurate would a prediction be that none of the passengers survived?*
# **Hint:** Run the code cell below to see the accuracy of this prediction.

# In[6]:

print accuracy_score(outcomes, predictions)

# **Answer:** *61.62%*

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `titanic_visualizations.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[7]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[8]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
    
def predictions_0(data):
    """ Model with no features. Always predicts a passenger did not survive. """

    predictions = []
    for _, passenger in data.iterrows():
        
        # Predict the survival of 'passenger'
        predictions.append(0)
    
    # Return our predictions
    return pd.Series(predictions)

predictions = predictions_0(data)
print(accuracy_score(Output, predictions))#if all predictions are 0 the accuracy is 61.62%
vs.survival_stats(data, Output, 'Pclass')
#Predict that all womans are survived
def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """
    
    predictions = []
    for _, passenger in data.iterrows():
        if passenger['Sex']=="female":
            predictions.append(1)
        else:
            predictions.append(0)
    
    # Return our predictions
    return pd.Series(predictions)
#
# **Hint:** Run the code cell below to see the accuracy of this prediction.

# In[5]:

print(accuracy_score(outcomes, predictions))

# **Answer:** Predictions have an accuracy of 61.62%

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[6]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[10]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 14
0
prediction = pd.Series(np.ones(5, dtype=int))
print(accuracy_score(outcome[:5], prediction))


def prediction_0(data):
    predictions = []
    for _, passenger in data.iterrows():
        predictions.append(1)
    return pd.Series(predictions)


predictions = prediction_0(data)

print(accuracy_score(outcome[:5], predictions[:5]))

vs.survival_stats(data, outcome, 'Sex')


def predictions_1(data):

    predictions = []
    for _, passenger in data.iterrows():
        if passenger['Sex'] == "male" and passenger['Pclass'] == 3:
            predictions.append(0)
        elif passenger['Sex'] == "female":
            if passenger['Pclass'] == 3 and passenger[
                    'Fare'] < 60 and passenger['Age'] < 50:
                predictions.append(0)
            else:
                predictions.append(1)
        else:
#
# **提示:**运行以下代码单元格,看看该预测的准确率是多少。

# In[7]:

print(accuracy_score(outcomes, predictions))

# **答案:** *61.62%*
#
# ***
# 我们使用 `survival_stats` 函数看看特征 **Sex** 是否对乘客的存活率有任何影响。该函数在此项目所包含的 `visuals.py` Python 脚本中进行了定义。传递给该函数的前两个参数分别是泰坦尼克号数据和乘客存活结果。第三个参数表示我们希望根据哪个特征绘制存活统计信息图表。
# 运行以下代码单元格以根据他们的性别绘制乘客存活结果图表。

# In[13]:

vs.survival_stats(data, outcomes, 'Sex')

# 查看存活统计数据后发现,大部分男性在沉船后没有存活下来。但是,大部分女性*的确*存活了。我们以之前的预测模型为基础重新预测:如果乘客是女性,则预测存活了,否则没有存活。
# 请将下面缺失的代码补充完整,以便该函数能够做出这种预测。
# **提示:**你可以像字典一样访问乘客的每个特征值。例如,`passenger['Sex']` 是乘客的性别。

# In[18]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():
Esempio n. 16
0
# *Using the RMS Titanic data, how accurate would a prediction be that none of the passengers survived?*
# **Hint:** Run the code cell below to see the accuracy of this prediction.

# In[5]:

print accuracy_score(outcomes, predictions)

# **Answer:** *That's about 61.62% of the prediction is right.*

# ***
# Let's take a look at whether the feature **Sex** has any indication of survival rates among passengers using the `survival_stats` function. This function is defined in the `visuals.py` Python script included with this project. The first two parameters passed to the function are the RMS Titanic data and passenger survival outcomes, respectively. The third parameter indicates which feature we want to plot survival statistics across.
# Run the code cell below to plot the survival outcomes of passengers based on their sex.

# In[6]:

vs.survival_stats(data, outcomes, 'Sex')

# Examining the survival statistics, a large majority of males did not survive the ship sinking. However, a majority of females *did* survive the ship sinking. Let's build on our previous prediction: If a passenger was female, then we will predict that they survived. Otherwise, we will predict the passenger did not survive.
# Fill in the missing code below so that the function will make this prediction.
# **Hint:** You can access the values of each feature for a passenger like a dictionary. For example, `passenger['Sex']` is the sex of the passenger.

# In[7]:


def predictions_1(data):
    """ Model with one feature: 
            - Predict a passenger survived if they are female. """

    predictions = []
    for _, passenger in data.iterrows():