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/
- 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).
The easiest way to run the application (UI + API) is via Docker.
docker build -t flight-price-app .docker run -p 8000:8000 flight-price-appOpen your browser to: http://localhost:8000
Detailed analysis can be found in notebooks/notebook_v2.ipynb.
- Source: Kaggle Flight Price Prediction Dataset.
- Cleaning: Handled missing values, outliers, and categorical encoding.
- Target Transformation: Applied
log1ptransformation to the 'Price' variable to address skewness (1.06). While not extremely high, the log transform improved model convergence and residual distribution.
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.
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
If you want to modify the code or run without Docker, follow these steps.
This project uses uv for fast Python package management.
# Create virtual environment
uv venv
# Install dependencies from pyproject.toml
uv syncActivate the environment (optional if using uv run):
source .venv/bin/activateStart the FastAPI backend with hot-reloading:
uv run uvicorn src.predict:app --host 0.0.0.0 --port 8000 --reloadAPI 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
}'Open a new terminal:
cd frontend
# Install Node dependencies
npm install
# Run the Next.js development server
npm run devUI is running at http://localhost:3000 (proxies API requests to port 8000)
- Push code to GitHub
- Go to https://render.com → Sign in
- New → Web Service → Connect repository
- Render auto-detects
render.yamlconfiguration - Click "Create Web Service"
- Wait 3-5 minutes for build
Live URL: https://flight-price-oracle-1.onrender.com/
To retrain the model with new data:
uv run python src/train.py --data-path data/Your_Data.csvFor faster training without hyperparameter tuning:
uv run python src/train.py --no-tuneOriginal definition by Dannycesp
