Making predictions
The trained network from your previous coding exercise is now stored as model
. New data to make predictions is stored in a NumPy array as pred_data
. Use model
to make predictions on your new data.
In this exercise, your predictions will be probabilities, which is the most common way for data scientists to communicate their predictions to colleagues.
This exercise is part of the course
Introduction to Deep Learning in Python
Exercise instructions
- Create your predictions using the model's
.predict()
method onpred_data
. - Use NumPy indexing to find the column corresponding to predicted probabilities of survival being True. This is the second column (index
1
) ofpredictions
. Store the result inpredicted_prob_true
and print it.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Specify, compile, and fit the model
model = Sequential()
model.add(Dense(32, activation='relu', input_shape = (n_cols,)))
model.add(Dense(2, activation='softmax'))
model.compile(optimizer='sgd',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(predictors, target)
# Calculate predictions: predictions
predictions = ____
# Calculate predicted probability of survival: predicted_prob_true
predicted_prob_true = ____
# Print predicted_prob_true
print(predicted_prob_true)