Elena' s AI Blog

Machine Learning Tests using the Titanic dataset

10 Feb 2023 (updated: 24 Aug 2026) / 55 minutes to read

Elena Daehnhardt


Jasper AI-generated art, January 2023


TL;DR:
  • Machine learning comparison using Titanic dataset: evaluating Logistic Regression, Decision Tree, Random Forest (scikit-learn), and Neural Networks (TensorFlow) - Random Forest performed best.

Previous: Part 15 — Data exploration and analysis with Python Pandas

Next: Part 17 — Machine-Learning Process

Comparing Machine Learning Models on the Titanic Dataset: Introduction

In my “Data exploration and analysis with Python Pandas” post, I described how to use Pandas Python library to analyse, explore and visualise the Titanic dataset. As promised, I will perform Machine Learning tests using this data. I will follow the general steps that it is good to start with when performing ML experiments. I will briefly explain the main ideas of how to start with ML while coding and testing several classification models for predicting the survival of Titanic passengers. I will use Logistic Regression, Decision Tree and Random Forest from Python’s library scikit-learn and a Neural Network created with TensorFlow. That will be a breeze!

What is Machine Learning?

Machine learning is a branch of AI, and it is often at the heart of data analysis. Machine Learning can be used for various tasks, such as classification, regression, clustering, and natural language processing. Today we cannot imagine our lives without automatic grammar checks such as those provided by Grammarly and its friends, intelligent chatbots such as chatGPT that are good in poetry, language translators, virtual assistants like Siri, DALL-E creating fantastic images, robots doing high-precision manufacture and self-driving cars, which I have not had the chance to ride in yet :)

Machine learning is a branch of artificial intelligence that teaches computers to learn patterns from data without being explicitly programmed. It involves using algorithms to analyse data, learn from it, and make predictions or decisions without human intervention. We can imagine that the ML program is a black box accepting our data, crunching it, and finally giving the result, for instance, recognising a person given a photo.

We need loads of data to train our magic ML black boxes. However, we can also use relatively small datasets. It all depends on what we are doing and how helpful our data elements (called “features”) are for solving our problems. For instance, in my bird species detection tests, I have used quite a large dataset and still needed to build on top of the pre-trained model to achieve reasonable results. Interested? You can read about transfer learning, data augmentation and experimental setup with TensorFlow in my post “TensorFlow: Transfer Learning (Fine-Tuning) in Image Classification” later.

However, that post is a bit challenging to start. We should begin with a simpler task, everyone learning ML knows about the Titanic dataset, which is as famous as George Clooney for ML guys :) No joke, I like coffee and good movies too!

The Titanic dataset, while relatively small, contains a good amount of information, and it’s considered an excellent dataset to start learning ML. It’s often used as a beginner’s dataset for classification and feature engineering tasks because of its simplicity, size and the fact that it’s publicly available. More complex or advanced applications will, of course, need more data. In short, machine learning is a specific technique used in data analysis, but not all data analysis tasks require ML.

ML techniques are employed to create intelligent AI systems, which we can make ourselves when we know how. It all sounds exciting. We must learn some math and stats, how to use existing libraries, and coding. Knowing which technique is appropriate and for what task, and how the algorithms behind ML techniques work would be beneficial. There is plenty to learn, but we can start in baby steps by gradually learning everything we like to know.

Supervised Machine Learning

🔒 Subscribe to keep reading.

Machine Learning Techniques to Start

🔒 Subscribe to keep reading.

Machine Learning Steps

🔒 Subscribe to keep reading.

Installing the libraries

🔒 Subscribe to keep reading.

Data preprocessing with Pandas

🔒 Subscribe to keep reading.

Evaluating the prediction accuracy

🔒 Subscribe to keep reading.

Predicting the survival of Titanic Passengers

🔒 Subscribe to keep reading.

Conclusion

🔒 Subscribe to keep reading.

References

🔒 Subscribe to keep reading.

Subscribe to unlock the full article ❤️

I keep most of the site completely open. A few unusually detailed tutorials need a free subscriber login so I can keep publishing this kind of work.

The form below signs you up for the newsletter. It does not log you into the app — log in afterwards (same email) to unlock this article and download your subscriber gifts. New subscribers get an inbox mail: Set a password to unlock articles.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2023) 'Machine Learning Tests using the Titanic dataset', daehnhardt.com, 10 February 2023. Available at: https://daehnhardt.com/blog/2023/02/10/machine-learning-using-titanic-dataset-prepared-with-pandas/
All Posts