Skip to content

Dannycesp/flight-price-oracle

Repository files navigation

Flight Price Prediction - End-to-End ML Project

Project Status Python Next.js Docker

✈️ Overview

This project is a complete Machine Learning application that predicts flight ticket prices based on various parameters like airline, route, timing, and class.

It features a High-Performance XGBoost Model wrapped in a FastAPI backend, coupled with a premium Modern Web UI (Next.js/React) that allows users to explore "What-If" scenarios with interactive sliders and real-time feedback.

🌐 Live Demo: https://flight-price-oracle-1.onrender.com/

UI Demo


✨ Key Features

  • Accurate Predictions: Trained on 300k+ records using XGBoost with hyperparameter tuning.
  • Interactive UI: A "Command Center" dashboard with moving bars and instant price updates.
  • Full Stack: Python Backend + TypeScript Frontend served from a single container.
  • Production Ready: Multi-stage Docker build optimized for cloud deployment (e.g., Render).

🚀 Quick Start (Docker)

The easiest way to run the application (UI + API) is via Docker.

1. Build the Image

docker build -t flight-price-app .

2. Run the Container

docker run -p 8000:8000 flight-price-app

3. Access the App

Open your browser to: http://localhost:8000


📊 EDA & Model Development

Detailed analysis can be found in notebooks/notebook_v2.ipynb.

Data preparation

  • Source: Kaggle Flight Price Prediction Dataset.
  • Cleaning: Handled missing values, outliers, and categorical encoding.
  • Target Transformation: Applied log1p transformation to the 'Price' variable to address skewness (1.06). While not extremely high, the log transform improved model convergence and residual distribution.

Model Selection

We evaluated multiple models to find the best balance of accuracy and inference speed:

  • Linear Regression / Ridge: Baseline models.
  • Random Forest: Good accuracy but slow inference.
  • XGBoost: Selected. Best performance (RMSE) and efficient size/speed.

Final Model Performance

The XGBoost Regressor (tuned) achieved the following results on the test set:

  • R² Score: 0.972 (Explains 97% of variance)
  • MAE: ₹2,044 (Average error per ticket)
  • RMSE: ₹3,784

👨‍💻 Local Development & Environment Setup

If you want to modify the code or run without Docker, follow these steps.

1. Environment Setup (uv)

This project uses uv for fast Python package management.

# Create virtual environment
uv venv

# Install dependencies from pyproject.toml
uv sync

Activate the environment (optional if using uv run):

source .venv/bin/activate

2. Run the API Locally

Start the FastAPI backend with hot-reloading:

uv run uvicorn src.predict:app --host 0.0.0.0 --port 8000 --reload

API is now running at http://localhost:8000

Test with cURL:

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{
    "airline": "Vistara",
    "source_city": "Delhi",
    "departure_time": "Early_Morning",
    "stops": "one",
    "arrival_time": "Morning",
    "destination_city": "Mumbai",
    "class": "Economy",
    "duration": 2.5,
    "days_left": 10
  }'

3. Run the Frontend Locally

Open a new terminal:

cd frontend

# Install Node dependencies
npm install

# Run the Next.js development server
npm run dev

UI is running at http://localhost:3000 (proxies API requests to port 8000)


☁️ Cloud Deployment (Render)

Deploy to Render

  1. Push code to GitHub
  2. Go to https://render.com → Sign in
  3. New → Web Service → Connect repository
  4. Render auto-detects render.yaml configuration
  5. Click "Create Web Service"
  6. Wait 3-5 minutes for build

Live URL: https://flight-price-oracle-1.onrender.com/


📝 Training the Model

To retrain the model with new data:

uv run python src/train.py --data-path data/Your_Data.csv

For faster training without hyperparameter tuning:

uv run python src/train.py --no-tune

Original definition by Dannycesp

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors