Skip to content

rautaditya2606/FastAPI_NYC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NYC Taxi Fare Prediction API

Project Overview: This project provides a RESTful API for predicting NYC taxi fares using a pre-trained LightGBM regression model. The API is built with FastAPI, allowing quick and scalable predictions for single or batch requests.


Features

  • Predict taxi fares based on pickup/dropoff locations, datetime, passenger count, and distances to major airports & landmarks.
  • FastAPI-powered with automatic Swagger docs (/docs endpoint).
  • Handles input validation using Pydantic models.
  • Easy integration for web or mobile applications.

Input Features

The model expects the following inputs:

Feature Type Description
pickup_longitude float Pickup location longitude
pickup_latitude float Pickup location latitude
dropoff_longitude float Dropoff location longitude
dropoff_latitude float Dropoff location latitude
passenger_count int Number of passengers
pickup_datetime_year int Pickup year
pickup_datetime_month int Pickup month
pickup_datetime_day int Pickup day
pickup_datetime_weekday int Day of the week (1–7)
pickup_datetime_hour int Pickup hour (0–23)
trip_distance float Distance traveled by the taxi
jfk_drop_distance float Distance to JFK airport
lga_drop_distance float Distance to LGA airport
ewr_drop_distance float Distance to EWR airport
met_drop_distance float Distance to Metropolitan Museum
wtc_drop_distance float Distance to World Trade Center

Installation

git clone <repo_url>
cd FastAPI_NYC

python -m venv venv
source venv/bin/activate  # Linux/macOS
venv\Scripts\activate     # Windows

pip install -r requirements.txt

Running the API

uvicorn app:app --reload --port 8000

Example Request

cURL single prediction:

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{
    "pickup_longitude": -73.985,
    "pickup_latitude": 40.758,
    "dropoff_longitude": -73.985,
    "dropoff_latitude": 40.748,
    "passenger_count": 1,
    "pickup_datetime_year": 2016,
    "pickup_datetime_month": 6,
    "pickup_datetime_day": 15,
    "pickup_datetime_weekday": 3,
    "pickup_datetime_hour": 9,
    "trip_distance": 2.1,
    "jfk_drop_distance": 20.0,
    "lga_drop_distance": 10.0,
    "ewr_drop_distance": 25.0,
    "met_drop_distance": 5.0,
    "wtc_drop_distance": 6.0
  }'

Response:

{
  "Prediction": 15.026287725871494
}

Project Structure

FastAPI_NYC/
├── app.py                  # FastAPI application
├── model/
│   └── nyctaxi.joblib      # Pre-trained LightGBM model
├── requirements.txt        # Python dependencies
├── README.md               # Project documentation
└── __pycache__/            # Python cache files

Notes

  • The model currently does not use feature scaling or encoding. Ensure inputs are provided in raw format.
  • Consider adding input validation to avoid unrealistic predictions (e.g., 100 passengers).
  • Can be easily extended to batch predictions, logging, or deployed via Docker.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages