Skip to content

Repository files navigation

British Airways Logo

British Airways Data Science Virtual Experience

A comprehensive data analysis project focusing on lounge demand forecasting and customer booking prediction.

Python Version Libraries TensorFlow Jupyter

---

Table of Contents


Project Overview

This repository contains the completed data science tasks from the British Airways Virtual Experience. The project is split into two main analyses, both contained within the main.ipynb notebook:

  1. Lounge Demand Forecasting: Analyzing flight schedule data to build a scalable lookup table for estimating lounge passenger eligibility at Heathrow Terminal 3.
  2. Customer Booking Prediction: Developing and comparing machine learning and deep learning models to predict the likelihood of a customer completing a booking, and identifying the key drivers behind their decisions.

Overall Project Workflow

This project consists of two independent tasks derived from the initial project brief.

graph TD
    A[Start: Project Initiation] --> B[Task 1: Lounge Demand Analysis];
    A --> C[Task 2: Booking Prediction Modeling];
    B --> D[Deliverable 1: Lounge Eligibility Lookup Table];
    C --> E[Deliverable 2: Predictive Model & Insights Report];
    D --> F[Project Complete];
    E --> F;
Loading

Task 1: Modeling Lounge Eligibility

Business Case

To maintain high service standards and optimize resources, British Airways needs to accurately forecast lounge demand. This model provides a flexible way to estimate demand based on broad flight categories, even without exact future schedules.

Task 1 Workflow

The process for this task involved data verification, aggregation, and formatting to produce the final lookup table.

graph TD
    T1_A["Load Schedule Data (.xlsx)"] --> T1_B[Explore Data: HAUL, TIME_OF_DAY];
    T1_B --> T1_C[Verification: Correlate HAUL with FIRST_CLASS_SEATS];
    T1_C -- Finding: SHORT HAUL has 0 First Class --> T1_D[Aggregate Data: Group by HAUL & TIME_OF_DAY];
    T1_D --> T1_E[Calculate Tier 1/2/3 Passenger Percentages];
    T1_D --> T1_F[Extract Unique Destinations per Group];
    T1_E & T1_F --> T1_G[Compile Final Lookup Table];
    T1_G --> T1_H[Output: Lounge Eligibility Lookup Template];
Loading

Methodology & Key Findings

The primary goal was to create a Lookup Table grouping flights to estimate the percentage of passengers eligible for Tier 1 (Concorde Room), Tier 2 (First Lounge), and Tier 3 (Club Lounge).

A key insight was discovered during data verification. By analyzing the FIRST_CLASS_SEATS column against the HAUL category, we programmatically confirmed with 100% certainty that SHORT HAUL flights have 0 First Class seats.

This is a critical finding, as it definitively proves that all Tier 1 passengers on Short Haul routes are eligible purely due to elite status (e.g., Premier/Gold Guest List), not their ticket class. This fundamentally changes the demand profile for Tier 1 lounges on these routes.

Final Output: Lounge Eligibility Lookup Table

This table summarizes the findings, validated with data-driven notes.

Grouping Example Destinations Tier 1 % Tier 2 % Tier 3 % Notes (Validated by Data)
LONG - Afternoon LAX, ORD, DXB, JFK, HND, DFW 1.47% 20.51% 78.02% Has First Class Cabin. Tier 1 from tickets + status.
LONG - Evening JFK, ORD, DXB, HND, LAX, DFW 1.61% 20.34% 78.05% Has First Class Cabin. Tier 1 from tickets + status.
LONG - Lunchtime ORD, JFK, DFW, DXB, LAX, HND 1.33% 20.42% 78.24% Has First Class Cabin. Tier 1 from tickets + status.
LONG - Morning LAX, HND, JFK, ORD, DXB, DFW 1.51% 20.47% 78.03% Has First Class Cabin. Tier 1 from tickets + status.
SHORT - Afternoon FRA, VIE, CDG, IST, MUC, AMS... 1.61% 20.31% 78.09% No First Class Cabin. 100% of Tier 1 is from elite status.
SHORT - Evening IST, FRA, VIE, AMS, CDG, MUC... 1.51% 20.44% 78.05% No First Class Cabin. 100% of Tier 1 is from elite status.
SHORT - Lunchtime FRA, CDG, AMS, ZRH, BCN, IST... 1.77% 20.47% 77.75% No First Class Cabin. Highest concentration of elite status.
SHORT - Morning IST, AMS, MUC, ZRH, MAD, FRA... 1.59% 20.33% 78.09% No First Class Cabin. 100% of Tier 1 is from elite status.

Task 2: Predicting Customer Buying Behaviour

Business Case

The modern customer buying cycle is complex. The airline must shift from being reactive to proactive by identifying customers with high booking intent before they finalize their travel plans. This allows for targeted marketing interventions to secure the booking.

Task 2 Workflow

This task involved a comprehensive model comparison, from preprocessing two distinct data pipelines (scaled vs. unscaled) to a rigorous evaluation that uncovered the true business-ready model.

graph TD
    T2_A["Load Booking Data (.csv)"] --> T2_B["Clean Data (Drop Nulls)"]
    T2_B --> T2_C["EDA: Analyze Target 'booking_complete'"]
    T2_C --> T2_D["Finding: Highly Imbalanced<br/>(85% No / 15% Yes)"]
    T2_D --> T2_E["Preprocessing: One-Hot Encoding"]
    T2_E --> T2_F["Split Data (Train/Test)<br/>with Stratification"]
    
    T2_F --> T2_G_ML["ML Pipeline:<br/>Use Unscaled Data"]
    T2_F --> T2_G_DL["DL Pipeline:<br/>Apply StandardScaler"]
    
    T2_G_ML --> T2_H1["Train Model 1:<br/>Random Forest"]
    T2_G_ML --> T2_H2["Train Model 2:<br/>LightGBM"]
    T2_G_DL --> T2_H3["Train Model 3:<br/>Simple MLP"]
    T2_G_DL --> T2_H4["Train Model 4:<br/>Deeper MLP"]
    
    T2_H1 --> T2_I["Generate Predictions<br/>on Test Set"]
    T2_H2 --> T2_I
    T2_H3 --> T2_I
    T2_H4 --> T2_I
    
    T2_I --> T2_J["Evaluate All Models:<br/>Compare F1-Scores"]
    T2_J --> T2_K["Analysis: RF Fails on Class 1<br/>LightGBM Wins"]
    T2_K --> T2_L["Select Best Model:<br/>LightGBM"]
    T2_L --> T2_M["Run Permutation Importance<br/>on LGBM"]
    T2_M --> T2_N["Output: Insights &<br/>Recommendations Report"]
    
    style T2_D fill:#fff3cd
    style T2_K fill:#d4edda
    style T2_L fill:#d1ecf1
    style T2_N fill:#e2e3e5
Loading

Methodology: A 4-Model Comparison

To find the most robust predictive model, we trained and compared four distinct architectures to predict booking_complete = 1 on the highly imbalanced dataset.

  • Machine Learning (Trees):
    1. Random Forest (RF)
    2. LightGBM (LGBM)
  • Deep Learning (Neural Nets): 3. Simple MLP (2-Layer) 4. Deeper MLP (4-Layer)

Imbalance was handled with class_weight (RF/Keras) and is_unbalance=True (LGBM).

Key Finding: The "Metric Trap" Analysis

A simple evaluation of the Weighted F1-Score is highly misleading. The Random Forest model appeared to be the best (0.79), but its Classification Report revealed it had failed at the business task: it had an F1-Score of only 0.08 for Class 1 (Bookings).

The LightGBM model was the clear winner, as it provided the best F1-Score (0.35) for the actual business target (Class 1) and successfully identified 62% (Recall) of all customers who will complete a booking.

Model F1-Score Comparison

Model Performance Comparison (Test Set)

Model Weighted F1-Score Class 1 (Booking) F1-Score Recall (Class 1)
Random Forest 0.79 (Misleading) 0.08 (Failure) 0.05
LightGBM 0.70 0.35 (Winner) 0.62
Deeper MLP (DL) 0.68 0.33 0.61
Simple MLP (DL) 0.66 0.32 0.63

Key Drivers & Recommendations

Permutation Importance was run on the winning LightGBM model to identify the top predictive features.

Top 15 Features (LightGBM)

Feature Importance
length_of_stay 0.043660
flight_duration 0.038120
wants_extra_baggage 0.024360
sales_channel_Mobile 0.006560
wants_in_flight_meals 0.005860
wants_preferred_seat 0.005780
flight_hour 0.003820
purchase_lead 0.003600
flight_day_Wed 0.000660
flight_day_Mon 0.000180
flight_day_Tue -0.000020
trip_type_RoundTrip -0.000120
flight_day_Thu -0.000200
num_passengers -0.000300
flight_day_Sat -0.000520
Permutation Importance for RF and LGBM

Actionable Insights & Recommendations

  1. Trip Characteristics (The "Commitment"): length_of_stay and flight_duration are the top predictors. This shows that customers planning high-commitment trips (e.g., major holidays, international travel) are not just casually browsing. Their intent to book is high.

    • Recommendation: For these users, focus on reassurance to close the deal. Promote "Flexible Booking Options" or "Price Guarantees" rather than small, transactional discounts.
  2. Ancillary Purchases (The "Micro-Commitment"): wants_extra_baggage is the #3 predictor. The act of adding any ancillary (meals, seats) is a powerful "micro-commitment." It signals a customer has mentally moved from browsing to planning their specific trip.

    • Recommendation: This is the perfect moment for a proactive nudge. For users with a high booking score who haven't yet added a bag, trigger a pop-up: "Get 10% off your first checked bag if you book in the next 15 minutes!"
  3. Platform (The "Channel"): sales_channel_Mobile is a top-5 driver. This confirms that customers booking on the mobile app/site behave as a distinct, targetable segment with a different conversion pattern than desktop users.

    • Recommendation: Optimize the mobile funnel. Since this channel is so predictive, we must ensure the process of adding anciliaries and completing payment is absolutely seamless on mobile.
Dashboard of Actionable Insights

Project Structure

D:.
│   structure.txt
│   
├───Code
│       main.ipynb
│       
├───Dataset
│       British Airways Summer Schedule Dataset - Forage Data Science Task 1.xlsx
│       customer_booking.csv
│       
└───Task
        Lounge Eligibility Lookup Template - Task 1.xlsx

How to Run

  1. Clone the repository:

    git clone [https://github.com/your-username/ba-data-science.git](https://github.com/your-username/ba-data-science.git)
    cd ba-data-science
  2. Create a virtual environment (Recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  3. Install the required libraries:

    pip install pandas numpy matplotlib seaborn jupyterlab scikit-learn lightgbm tensorflow openpyxl
  4. Launch Jupyter Lab:

    jupyter lab
  5. Open and run the notebook:

    • Navigate to Code/main.ipynb.
    • Run the cells sequentially from top to bottom.

Technology Stack

  • Python 3.9+
  • Data Analysis: Pandas, NumPy
  • Data Visualization: Matplotlib, Seaborn
  • File Handling: openpyxl (for .xlsx files)
  • Machine Learning: Scikit-Learn, LightGBM
  • Deep Learning: TensorFlow (Keras)
  • IDE: Jupyter Lab

About

Repository for the BA Data Science Virtual Experience. Includes lounge eligibility analysis (Task 1) and a comparative study (RF, LGBM, MLP) to predict customer booking, with full model evaluation and insight reporting.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages