Discord

4Classical Machine Learning 4.9Problem Walkthroughs

4.9.1 Titanic Walkthrough

Approach a complete tabular classification problem like a contestant: inspect, question, validate, improve and submit.

This is not a page to read passively. It is a small contest problem to solve in order. At each checkpoint, stop, answer the question in your own notebook, and only then open the suggested answer. Each answer includes one short insight explaining why that step matters.

The goal is not to squeeze every possible leaderboard point from Titanic. The goal is to practise the routine a careful AI olympiad participant should be able to repeat under time pressure, using only ideas already introduced in this guide.

Get the data

Open the official Titanic competition data page, join the competition if Kaggle asks you to, and download:

  • train.csv labelled passengers used for training and validation;
  • test.csv unlabelled passengers for the final predictions; and
  • gender_submission.csv an example showing the required submission format.

Put all three files beside a new notebook. Do not use gender_submission.csv as hidden test labels: it is only a sample submission.

You should already be comfortable with Pandas, Scikit-learn Basics and Approaching a Typical Classical Machine Learning Problem. Every model and technique below has appeared earlier in the guide.

1. Read the task before touching the data

A contestant should extract four facts immediately: the target, problem type, metric and submission format.

2. Load the files

3. Inspect before deciding

4. Ask small questions of the data

Exploration should answer a modelling question. Do not produce dozens of plots without deciding what each one is meant to reveal.

5. Set up honest validation

The Kaggle test labels are hidden, so use part of train.csv as a local validation set. Keep Kaggle submissions for occasional confirmation, not for deciding every small change.

6. Build preprocessing into the model

The first real model needs numbers with no missing values. Numerical and categorical columns need different treatment, so keep both paths inside one pipeline.

7. Train the first useful model

8. Compare familiar models fairly

Keep the same features, split and metric. Only the estimator changes.

9. Make one controlled improvement

Do not start a large blind search. First identify one model worth tuning and a small number of meaningful settings.

10. Choose and refit the final model

Use the cross-validation evidence rather than assuming the tuned forest must win. The code below selects the strongest untuned candidate by mean cross-validation accuracy; you may instead use search.best_estimator_ if its cross-validation score is clearly better.

11. Build the submission file

The last stage is part of the problem, not paperwork. A perfect prediction array in the wrong format still earns no score.

12. Final contest check

Before uploading solution.csv, restart the notebook kernel and run every cell from the top. Then answer each question with yes:

  • Did the notebook load only the files that will be available during the task?
  • Is the target absent from every feature matrix?
  • Were PassengerId and the sample predictions excluded from training?
  • Is every learned preprocessing step inside the pipeline?
  • Were models compared using the same metric and validation procedure?
  • Are all randomised steps given a fixed random_state?
  • Was the chosen model refitted on all labelled rows?
  • Does solution.csv have exactly the required columns, row count and order?
  • Does the notebook recreate the file without relying on hidden state?

If every answer is yes, upload solution.csv on the Titanic competition page. Record the public score beside your local cross-validation result, but keep the local procedure as the basis for future changes.

Where to go after the first submission

Only after the complete pipeline works should you try one change at a time. With the topics covered so far, sensible experiments include removing FamilySize, changing the logistic-regression regularisation, adjusting tree depth, or comparing a small number of random-forest settings. Keep a short table of the change and its cross-validation score so that every decision has evidence behind it.

Resources

SourceTitleWhy read it
KaggleTitanic competition dataDownload train.csv, test.csv and gender_submission.csv before starting the walkthrough.
KaggleTitanic competition overviewRead the task description and evaluation rules before opening the data.

Practice problems

SolvedSourceProblemDifficultyTags
Kaggle Titanic - Machine Learning from Disaster Easy tabular, classification, submission file

Finished this module? Mark it done.

Comments

Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.

Loading comments