Making Predictions with All Three Models
End-to-End Machine Learning: Titanic Survival Prediction
2 min read
Published Nov 18 2025, updated Aug 17 2026
Guide Sections
Guide Comments
Once the models are trained and evaluated, a common final step is to use them for real predictions.
We will prepare an example passenger (or multiple passengers) and run them through:
- Logistic Regression
- Random Forest
- Keras Neural Network
This demonstrates how to make new, real-world predictions using your pipelines and transformed data.
Create a Sample Passenger to Predict
We’ll create a small dataframe with one or more new passengers.
Here’s an example with two fictional passengers:
# Example passengers to predictsample_passengers = pd.DataFrame([ { "pclass": 1, "sex": "female", "age": 25, "sibsp": 0, "parch": 0, "fare": 100, "embarked": "S", "class": "First", "who": "woman", "alone": True }, { "pclass": 3, "sex": "male", "age": 35, "sibsp": 1, "parch": 3, "fare": 12, "embarked": "S", "class": "Third", "who": "man", "alone": False }])sample_passengersIn tabular form:
pclass sex age sibsp parch fare embarked class who alone0 1 female 25 0 0 100 S First woman True1 3 male 35 1 3 12 S Third man FalsePassenger A:
- First class young woman travelling alone
Passenger B:
- Third class adult man with family
We expect dramatically different survival probabilities.
Predictions with Logistic Regression
pred_lr = log_reg.predict(sample_passengers)prob_lr = log_reg.predict_proba(sample_passengers)[:, 1]print("Logistic Regression Predictions:", pred_lr)print("Logistic Regression Probabilities:", prob_lr)Output:
Logistic Regression Predictions: [1 0]Logistic Regression Probabilities: [0.94124233 0.0275436 ]The output gives:
0= predicted death1= predicted survival- Probability = model’s confidence the passenger survives
Predictions with Random Forest
pred_rf = rf.predict(sample_passengers)prob_rf = rf.predict_proba(sample_passengers)[:, 1]print("Random Forest Predictions:", pred_rf)print("Random Forest Probabilities:", prob_rf)Output:
Random Forest Predictions: [1 0]Random Forest Probabilities: [0.995 0.015]Random Forest typically gives:
- Stronger confidence for clear “rules”
- Slightly noisier for edge cases
Predictions with the Keras Neural Network
The Keras model requires preprocessed numeric arrays, so we must transform using the fitted preprocessor:
sample_processed = preprocessor.transform(sample_passengers)# Convert sparse matrix if neededif hasattr(sample_processed, "toarray"): sample_processed = sample_processed.toarray()prob_keras = model.predict(sample_processed).ravel()pred_keras = (prob_keras >= 0.5).astype(int)print("Keras Predictions:", pred_keras)print("Keras Probabilities:", prob_keras)Output:
Keras Predictions: [1 0]Keras Probabilities: [0.94335914 0.07789665]Final Combined Output
results = pd.DataFrame({ "Passenger": ["A (1st class woman)", "B (3rd class man)"], "LR_Prob": prob_lr, "LR_Pred": pred_lr, "RF_Prob": prob_rf, "RF_Pred": pred_rf, "Keras_Prob": prob_keras, "Keras_Pred": pred_keras})print(results)
Passenger A (1st-class woman travelling alone)
- All three models give a very high survival probability (> 94%).
- Random Forest is almost certain (99.5%).
- Logistic Regression and Keras also strongly agree.
- This aligns with:
- “Women first” evacuation procedures
- First-class passengers having better access to lifeboats
- Historical survival rates (≈97% for 1st-class females)
All models predict survival confidently.
Passenger B (3rd-class man with family)
- All three models give a very low survival probability (< 8%).
- Random Forest gives near-zero chance (1.5%).
- Logistic Regression agrees (≈2.7%).
- Keras is slightly less certain but still low (7.8%).
- This matches historical data:
- Only ~14% of 3rd-class males survived
- Men were deprioritised
- Family groups in 3rd class were often delayed or blocked from access
All models predict he does not survive.