By Samarth Poddar
INTRODUCTION
• The Titanic dataset contains information about 100 passengers.
• Objective:
o Perform Exploratory Data Analysis (EDA)
o Implement K-Nearest Neighbors (KNN) for survival
prediction
o Apply K-Means clustering to group passengers
• Using those predict survival of passengers aboard TITANIC
using available passenger info (gender, age etc.)
• Identify the key factors that influenced survival
• Tools used:
o Spreadsheet
o Methods: Data cleaning, Predictive modelling,Visualization
DATASET OVERVIEW
Columns:
• Passenger ID: Unique ID
• Age: Age of passenger
• Gender: Male/Female
• P class: Passenger class (1=Upper,2=Middle,3=Lower)
• Survived: 1=Yes, 0=No
• Embarked: C,Q,S
• Traveling Alone: 1=Yes, 0=No
Rows:
oAll the above information of 100 passengers
SECTION 1: EDA (FINDINGS)
• Average age of passengers was 39.6 ~ 40 years implying most
passengers were middle-aged
• Most passengers travelled in first class showing social and economic
influence
• Only 39% of passengers survived
• 53 passengers travelled alone which is more than half implying less
no. of families were aboard
• Females had the highest survival rate showing gender highly
influenced chances of survival
• 34 passengers embarked from Southampton, making it the most
common embarking port
• Best combination of survivors was Female + First class
• Among passengers aged below 18, those travelling in Second Class
had the best chances of survival
FORMULAS USED IN EDA
Average Age: =AVERAGE(B2:B101)
Count by Class: =COUNTIF(D2:D101,1)
Traveling Alone: =COUNTIF(G2:G101,1)
Survival %: =COUNTIF(E2:E101,1)/COUNTA(A2:A101)
Gender Survival:
=COUNTIFS(C2:C101,"Female",E2:E101,1)/COUNTIF(C2:C101,"Femal
e")*100
Embarked Count: =COUNTIF(F2:F101,"S")
Survival rate of U18 passengers for each class:
=COUNTIFS(B2:B101,"<18",D2:D101,1,E2:E101,1)/COUNTIFS(B2:B10
1,"<18",D2:D101,1)*100
• This is just a generalized formula used, the formulas for Q2,Q5,Q7
were altered slightly by changing class to 2 and 3, changing gender to
male and changing class to 2 and 3 in the questions respectively. (pos.
of changes marked in the above formulas.
GRAPHS
SECTION 2: K-NEAREST NEIGHBORS (KNN)
Steps:
1. Encode categorical columns (Gender: M=0,F=1;Embarked:
C=0,Q=1,S=2)
2. Use Euclidean Distance Formula: =SQRT((B2-61)^2 + (H2-
0)^2 + (D2-2)^2 + (I2-2)^2 + (G2-1)^2)
3. Sort distances using Sort function of data, pick K nearest
4. Predict survival of Passenger 101 by majority vote
Results:
• Top 3 Neighbours: IDs 80, 71, 26
• K=5 → Did Not Survive
• K=9 → 2 survivors among neighbours
FORMULAS USED
• Euclidean dist.= =SQRT((B2-61)^2 + (H2-0)^2 + (D2-
2)^2 + (I2-2)^2 + (G2-1)^2)
• Embarked Encoding= IF(F2="C",0,IF(F2="Q",1,2))
• Gender Encoding= IF(C2="Male",0,1)
SORTED EUCLIDEAN DISTANCE
SECTION 3: K-MEANS CLUSTERING
Steps:
1. Encode categorical columns
2. Normalize Age
3. Choose initial centers: PIDs 4 & 46
4. Distance to Cluster Centers
5. Assign passengers to nearest cluster
Process:
• Encoding was done (already done in KNN)
• Normalized age was calculated using the given
formula
• Initial centres were chosen C1= PassengerID 4 , C2=
PassengerID 46
• Dist. to each cluster was calculated using formula
FORMULA USED IN SPREADSHEET
• Norm Age=(B2-MIN(B2:B101)/(MAX(B2:B101)-
MIN(B2:B101))
• Dist. from cluster (C1)=SQRT((K2 - 1)^2 + (H2 -
0)^2 + (D2 - 3)^2 + (I2 - 1)^2 + (G2 - 0)^2)
• Dist. from cluster (C2)=SQRT((K2 - 0)^2 + (H2 -
1)^2 + (D2 - 3)^2 + (I2 - 2)^2 + (G2 - 1)^2)
• Cluster assignment=IF(L2<M2,"Cluster 1","Cluster 2")
• Count of C1=COUNTIF(N2:N101,"Cluster 1")
• Count of C2=COUNTIF(N2:N101,"Cluster 2")
Results:
• Groups passengers into clusters based on similarities in their
features like Age, Gender, Passenger class etc.
• Passenger 99 was assigned to Cluster 2 with dist. From cluster
being 2
• Cluster 1 contained most passengers i.e. 65 meaning most
passengers were similar to passenger 4
• Cluster 2 contained 35 passengers meaning only 35% of
passengers were like passenger 46
DIST. OF PASSENGERS FROM C1 AND
C2
CLUSTER ASSIGNMENT TO
PASSENGERS
NO. OF PASSENGERS IN C1 AND
C2
INSIGHTS FROM THE PROJECT
• Survival Patterns (EDA)
Females had a much higher survival rate (~77.5%) compared to males
(~13.3%).
1st Class passengers had the best chances of survival, while 3rd Class had the worst.
Passengers traveling with family had better survival compared to those traveling
alone.
The majority of passengers embarked from Southampton (S), but survival was better
among those from Cherbourg (C).
• KNN Predictions
By encoding data and calculating distances, we could predict survival for new
passengers.
Example: A 61-year-old male, Class 2, traveling alone was predicted NOT to survive.
Shows how classification can be applied using historical patterns.
• K-Means Clustering
Passengers were grouped into two natural clusters (65 vs 35).
Cluster 1: Mostly males, lower class, traveling alone → lower survival profile.
Cluster 2: More females, upper class → higher survival profile.
Even without using the “Survived” column, the clusters reflected real survival trends.
CONCLUSION
• The purpose of this project was to analyse a simplified Titanic
dataset to discover survival patterns, apply machine learning
for prediction, and use clustering techniques to identify natural
groupings among passengers. Through this, I was able to
combine exploratory data analysis (EDA), supervised learning
(KNN classification), and unsupervised learning (K-Means
clustering) in a practical way.
• From the analysis, I found that survival on the Titanic was
strongly influenced by gender, passenger class, and
whether passengers travelled alone. Women and children,
especially those in first class, had the highest chances of
survival, while men in lower classes traveling alone faced the
lowest chances. This highlighted how social and economic
factors played a role in life-and-death situations.
LEARNING
• By applying KNN classification, I learned how past data can
be used to predict the survival of a new passenger based on
their similarities to others. With K-Means clustering, I saw
how passengers could be grouped into clusters that naturally
reflected survival patterns — even without using the
“survived” label.
• On a personal level, this project taught me how to clean and
analyse real data, use formulas to calculate insights, and apply
machine learning techniques step by step. More importantly, I
understood how machine learning can be used to solve real-
life problems: from predicting outcomes to discovering
hidden patterns in data.
REFERENCES
Software/Tools used:
Microsoft Excel/Spreadsheet
ChatGPT
Titanic Dataset (reference)