1

I'm currently trying to refer to a value from an excel spreadsheet that is full of passenger data for the titanic disaster. Here is the part I'm stuck on.

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.

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
        if passenger['Sex'] == 'female':
            survived == 1
        else survived == 0

    # Return our predictions
    return pd.Series(predictions)
​
# Make the predictions
predictions = predictions_1(data)


  File "<ipython-input-75-6b2fca23446d>", line 12
    else survived == 0
                ^

SyntaxError: invalid syntax

I input the if else statement and I'm positive there are many errors in my attempt, I'd appreciate some clarity to how to fix this, the data from the excel sheet is the survived and sex data. Here is the github link to the project I'm working on. https://github.com/udacity/machine-learning/tree/master/projects/titanic_survival_exploration

1 Answer 1

3

Your syntax is not correct with that else missing a :, and you're mixing the equality operator == with the assignment operator =:

    if passenger['Sex'] == 'female':
        survived = 1 # bind int value 1 to the name 'survived'
    else: 
        survived = 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.