- Introduction
- Project Overview
- Repository Structure
- Data Collection
- Dataset Description
- Installation & Setup
- Usage
- Exploratory Analysis
- Interactive Aircraft Usage Dashboard
- Machine Learning Model Performance
Hi! Welcome to our Data 400 capstone project! π
This project aims to address the question: Can we predict flight prices?
Using machine learning and automated data collection from the Amadeus Flight API, We've built a project that gathers real-time flight data for major cross-country flight patterns and develops predictive models to forecast ticket prices.
Why does this matter?
Airlines use complex algorithms to dynamically price tickets based on demand, seasonality, route popularity, and countless other factors. By analyzing these patterns, we can help travelers make more informed decisions about when to book their flights! π°
- Robust Data Workflow: GitHub Actions run our workflow 2x daily to collect up-to-date flight data
- Real-Time API Integration: Uses Amadeus Flight Offers Search API
- Large-Scale Dataset: ~700,000 observations collected
- Machine Learning Models: Multiple ML approaches to predict flight prices
- Quality Data Visualizations: Many visualizations showing the capabilities of our data
- Python 3.8+ for data processing, visualizing, and modeling
- Amadeus API for data collection
- GitHub Actions for automated workflows
- Pandas & NumPy for data manipulation
- Scikit-learn for machine learning
- Matplotlib/Seaborn for visualization
- Dash & Plotly for interactive dashboard
- ExchangeRate-API for live currency conversion
Data400_Final_Project/
β
βββ .github/workflows/ # GitHub Actions automation
β βββ collect_flights.yml # Scheduled workflow for daily data collection
β
βββ code/ # Analysis and modeling scripts
β βββ EDA.ipynb # EDA & data visualization
β βββ data_concatenation.ipynb # Data concatenation (for saving example dataset)
β βββ feature_engineering.ipynb # Feature engineering and modeling preparation
β βββ modeling.ipynb # Machine learning models
β βββ aircraft_dashboard.ipynb # Interactive aircraft usage dashboard
β
βββ data/ # Flight data storage
β βββ final_flight_data.csv # Example dataset (first ~500,000 observations collected)
β
βββ collect_flights.py # Main data collection script
βββ requirements.txt # Python package dependencies
βββ .gitignore # Git ignore rules
βββ README.md # You are here
This script:
- Connects to the Amadeus API using secure credentials
- Queries flight offers for major airport routes
- Handles pagination and rate limiting
- Stores data in structured CSV format
- Uploads data directly to Dropbox
- Includes error handling and logging
Contains the GitHub Actions configuration that automatically runs collect_flights.py on a schedule. This ensures we're constantly gathering fresh data without manual intervention. The workflow runs twice daily at 12:00 AM and 12:00 PM UTC.
Houses all analysis and modeling scripts:
- Exploratory Data Analysis: Understanding price distributions, seasonal patterns, route popularity, and much more!
- Feature Engineering: Creating meaningful predictors from raw data
- Modeling: Building and evaluating machine learning models
Stores a sample of the data for our project. Note: Large data files are gitignored to avoid file size issues.
Lists all Python packages needed to run the project. Install with:
pip install -r requirements.txtThe automated data collection pipeline follows these steps:
-
GitHub Actions Trigger π
- Workflow runs twice daily
- Can also be triggered manually
-
API Authentication π
- Authenticates Amadeus API credentials
-
Flight Search π
- Queries major US airport pairs (e.g., JFKβLAX)
- Searches for flights across multiple departure dates
- Collects various cabin classes and booking options
-
Data Storage πΎ
- New data is saved to Dropbox as a .csv with a date and time label
-
Error Handling
β οΈ - Logs API errors and rate limit issues
- Implements retry logic for failed requests
- Sends notifications for critical failures
- The Amadeus API has very strict usage limits
- Multiple API keys are used in each data collection run
Each flight observation includes the following variables:
| Variable Name | Type | Description | Source/Notes |
|---|---|---|---|
flight_id |
string | Unique identifier for the specific flight | Engineered |
origin |
string | Origin airport code (e.g., 'JFK', 'LAX') | API |
destination |
string | Destination airport code | API |
departure_date |
datetime | Scheduled departure date and time | API |
arrival_date |
datetime | Scheduled arrival date and time | API |
price |
float | Target variable - Flight price in Euros | API |
currency |
string | Currency of the price (EUR, transformed to USD) | API |
airline |
string | Operating airline carrier code | API |
airline_name |
string | Full airline name mapped from carrier code | Engineered - Dashboard |
aircraft_type |
string | Aircraft model codes (e.g., '32Q', '73H') | API - Dashboard |
stops |
integer | Number of stops (0 = nonstop, etc.) | API |
duration |
string | Total flight duration (e.g., 'PT5H30M') | API |
cabin_class |
string | Booking class (ECONOMY, PREMIUM_ECONOMY, BUSINESS, FIRST) | API |
seats_available |
integer | Number of seats remaining at this price | API |
booking_class |
string | Fare booking code | API |
days_until_departure |
integer | Days between search date and departure | Engineered |
search_date |
datetime | When the price was recorded | API |
route |
string | Route identifier (e.g., 'JFK β LAX') | Engineered - Dashboard* |
*Dashboard-exclusive variables are used in the interactive aircraft usage dashboard for filtering and visualization.
Features used for Modeling:
-
Historical Prices
- lagged price features
- rolling window statistics
-
Route Features
- route competition features
- route durations
- route volatility
-
Temporal Features
- red-eye indicators
- time of day indicators
- flight durations
- departure day features
-
Airline Features
- airline volatility
- premium vs lowcost carrier
-
Bookable Seats Features
- distance from 4 bookable seats (see EDA)
- scarcity indicators
- Python 3.8 or higher
- pip package manager
- Amadeus API credentials (Get them here)
-
Clone the repository
git clone https://github.com/wbartlett1/Data400_Final_Project.git cd Data400_Final_Project -
Install dependencies
pip install -r requirements.txt
-
Set up API credentials
Create a
.envfile in the root directory:AMADEUS_API_KEY=your_api_key_here AMADEUS_API_SECRET=your_api_secret_here -
Verify setup
python collect_flights.py --test
Run manual data collection:
python collect_flights.pyOpen notebooks in Jupyter:
jupyter notebook code/EDA.ipynb
jupyter notebook code/feature_engineering.ipynb
jupyter notebook code/modeling.ipynb
jupyter notebook code/aircraft_dashboard.ipynb
We can see which airlines are higher-end and which are low-cost carriers. We can use this to improve our model's predictive power through engineering related features.
We can see which routes are more expensive than others.
We can see the pricing trends by how many days before departure the flight's price is observed. There is a clear drop-off at 7 days out, which can help us with modeling and feature engineering.
Price by day of week and time of day.
Price by how many seats are left bookable. We can see the drop-off at 4 bookable seats, which can help us with modeling and feature engineering.
We've built an interactive dashboard to analyze aircraft usage patterns across our flight data.
12 Interactive Filters:
- Basic Filters: Airline, Route, Origin, Destination
- Aircraft Filters: Aircraft Family, Aircraft Brand
- Flight Characteristics: Number of Stops (checkboxes), Cabin Class (checkboxes), Red-eye flights
- Advanced Filters:
- Currency toggle (EUR/USD with live exchange rates)
- Days Until Departure slider (0-14 days)
- Departure Hour slider (24-hour)
- Price Range slider (with currency conversion)
- Flight Duration slider (in hours)
- Bookable Seats slider
Visualization:
- Interactive donut chart showing aircraft type distribution
- Aircraft sorted by manufacturer (Airbus β Boeing β Bombardier β Embraer)
- Labels shown only for aircraft types representing β₯5% of usage
- Hover tooltips display aircraft family, brand, count, and percentage
Live Features:
- Real-time EUR to USD exchange rate via ExchangeRate-API
- Dynamic currency conversion for price filters
- Responsive filter panel with organized sections
jupyter notebook code/aircraft_dashboard.ipynbRun all cells, then access the dashboard at http://127.0.0.1:8050/ (or http://localhost:8050/ works too!)
Machine learning models tackle the question: Can we predict a tomorrow's price for a cross-country flight?
Modeling Approach:
- 80/20 temporal split
- Hyperparameter tuning via GridSearchCV & RandomizedSearchCV
- 3-fold cross-validation
- Evaluation Metric: Mean Absolute Error (MAE)
Models Tested:
- Linear Regression
- Decision Tree
- Random Forest
- XGBoost
With our best model, Random Forest, we can predict the price of a cross-country flight tomorrow within $15 on average! This model has an RΒ² of 0.991, explaining over 99% of the variation in tomorrow's price.
Price history and trends explain ~91.7% of the model's predictive power. Other important features are related to airline and route volatility, competition indicators, and more.
The superiority of the tree models indicate a non-linear relationship between features and the target. We have highly predictive models, which can help us understand pricing strategies and tendencies. Using this model, we could help people save money on flights! This project is for academic purposes only.
Have any questions? Contact us at our email below or open an issue!
- π§ Email: bartletw@dickinson.edu | tranqu@dickinson.edu
- π¬ Open an Issue
- π This project was completed for the Data Analytics Capstone at Dickinson College
- Professor Bilen
- Dickinson College
- Amadeus for providing API access
Made by Will Bartlett & Kevin Tran
Dickinson College
Data Analytics Department
Last Updated: December 2025