Your First End-to-End Machine Learning Project (Step-by-Step in Python)
Put it all together. Build your first complete machine learning project from scratch — load data, preprocess it, train a model, evaluate it, and make predictions — using the classic Titanic dataset and scikit-learn.
Over the last several lessons you've learned the pieces one at a time — Python, algorithms, evaluation, and preprocessing. Now it's time to snap them all together into your first complete machine learning project, start to finish.
We'll use the most famous beginner dataset in the world: the Titanic dataset. The goal is a classic binary classification — given a passenger's details (age, sex, ticket class…), predict whether they survived. It's perfect for a first project because it's small, real, and messy enough to practice everything you've learned.
Every ML project, no matter how large, follows the same six steps:
Step 1: Load the data
We'll use pandas to load the Titanic data. Seaborn ships with a copy, which makes this a one-liner — no download needed.
import pandas as pd
import seaborn as sns
# load the built-in Titanic dataset
df = sns.load_dataset("titanic")
print(df.shape) # (891, 15) → 891 passengers, 15 columns
print(df.head()) # peek at the first 5 rows
Step 2: Explore the data
Before touching a model, look at your data. This step — often called EDA (Exploratory Data Analysis) — tells you what you're working with and what needs fixing.
print(df.info()) # column types & non-null counts
print(df.isnull().sum()) # how many blanks per column
print(df["survived"].value_counts()) # how many lived vs died
Running this reveals the problems we need to solve: age has many missing values, deck is mostly empty, and columns like sex and embarked are text the model can't read yet. This is exactly the mess Lesson 13 prepared us for.
Step 3: Preprocess
Now we clean it up. We'll keep a handful of useful columns, fill missing values, and encode the text — the preprocessing playbook in action.
# 1. pick the features we'll use + the target
cols = ["survived", "pclass", "sex", "age", "sibsp", "parch", "fare", "embarked"]
df = df[cols]
# 2. fill missing values
df["age"] = df["age"].fillna(df["age"].median())
df["embarked"] = df["embarked"].fillna(df["embarked"].mode()[0])
# 3. encode text columns into numbers (one-hot)
df = pd.get_dummies(df, columns=["sex", "embarked"], drop_first=True)
Notice we filled age with the median (robust to outliers) and embarked with the mode (most common value) — exactly as the preprocessing lesson recommended.
Step 4: Split into features (X) and target (y), then train/test
We separate what we use to predict (X = all the passenger details) from what we want to predict (y = survived or not), then hold back 20% for honest testing.
from sklearn.model_selection import train_test_split
X = df.drop(columns=["survived"]) # features
y = df["survived"] # target (0 or 1)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)
Step 5: Train the model
Now the part everyone thinks is "the machine learning" — and it's just two lines. We'll use a Random Forest, our reliable default.
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train) # the model learns from training data
That's it — the model has learned the patterns linking passenger details to survival. Everything before this (steps 1–4) was preparation; everything after (step 6) is checking our work.
Step 6: Evaluate and predict
Finally, we measure the model on the test set it has never seen, using the metrics from Lesson 11.
from sklearn.metrics import accuracy_score, classification_report
predictions = model.predict(X_test)
print("Accuracy:", accuracy_score(y_test, predictions))
print(classification_report(y_test, predictions))
# typically ~80% accuracy — a solid first result!
And predicting for a brand-new passenger is the same .predict() call — feed it a row of features and it returns 0 (did not survive) or 1 (survived). You've now built a model that makes real predictions on data it has never seen.
The whole project in one place
Here's every step stitched together — this is a complete, runnable machine learning project in about 20 lines:
import pandas as pd, seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
# 1. load
df = sns.load_dataset("titanic")
# 2-3. select + preprocess
df = df[["survived","pclass","sex","age","sibsp","parch","fare","embarked"]]
df["age"] = df["age"].fillna(df["age"].median())
df["embarked"] = df["embarked"].fillna(df["embarked"].mode()[0])
df = pd.get_dummies(df, columns=["sex","embarked"], drop_first=True)
# 4. split
X, y = df.drop(columns=["survived"]), df["survived"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 5. train
model = RandomForestClassifier(n_estimators=100, random_state=42).fit(X_train, y_train)
# 6. evaluate
print(classification_report(y_test, model.predict(X_test)))
Run that in a Jupyter notebook or any Python environment and you have a working model. That's a genuine end-to-end project — the same shape as ones running in production, just smaller.
The first time the whole pipeline ran clean and printed a real accuracy score, it finally clicked for me that machine learning isn't magic — it's just these six steps done carefully, and the model is only ever as good as the data and prep you feed it.
Key takeaways
- Every ML project follows the same six steps: load → explore → preprocess → split → train → evaluate.
- The "machine learning" part (
.fit()) is tiny — most of the work is preparing the data. - Always explore first (missing values, types, class balance) so you know what to fix.
- Judge the model on the held-out test set, never on training data.
- A complete, useful first project can be under 20 lines of Python.
Congratulations — you've built your first real model and completed the foundations of machine learning. Next we step into the field that powers modern AI — image recognition, ChatGPT, self-driving cars — and answer the big question: what exactly is a neural network, and how does deep learning work?
Continue the series: ← Lesson 13: Data Preprocessing · Next: Lesson 15 — What is a Neural Network? →
Frequently Asked Questions
What are the steps in a machine learning project?
Every machine learning project follows the same six steps: load the data, explore it (EDA), preprocess it (clean, fill missing values, encode text), split it into training and test sets, train a model, and finally evaluate the model and make predictions.
What is a good first machine learning project for beginners?
The Titanic survival prediction is the classic first project. Using the Titanic dataset, you predict whether a passenger survived based on details like age, sex, and ticket class. It is small, real, and messy enough to practice the full workflow including handling missing values and encoding.
How much code does a basic ML project need?
A complete, working machine learning project can be written in under 20 lines of Python using pandas and scikit-learn. Most of those lines are for preparing the data; the actual model training is often just a single .fit() call.
Which model should I use for my first project?
Random Forest is an excellent choice for a first project. It works well on most tabular data out of the box, needs little tuning, resists overfitting, and often reaches around 80% accuracy on the Titanic dataset, making it a reliable default before trying anything more advanced.