Skip to content

Repository files navigation

NYC Taxi Tip Prediction Based on Neighborhood Median Income

Ashley Kim & John Park

big-city-1265055_640

Description

Tipping behavior in urban transportation is shaped by a complex mix of social, economic, and temporal factors. This project explores tipping patterns in New York City's taxi and for-hire vehicle services using 2023 trip data provided by the Taxi & Limousine Commission (TLC), supplemented with neighborhood-level median income data.

Our goal is to understand whether and how tipping is influenced by the socioeconomic context of pickup and dropoff neighborhoods. We examine trip-level attributes and geographic income disparities across NYC to predict tip amounts and uncover patterns of urban mobility compensation.

  • Dependent variable: Tip amount or tip percentage.\
  • Independent variables: Trip distance, fare, tip percentage, hour, day of week, season, pickup and dropoff locations, neighborhood median income, taxi type.

Data Retrieval

Primary Dataset: NYC Taxi & Limousine Commission Trip Record Data

  • Covers yellow taxi, green taxi, for hire vehicles trips across New York City during 2023.\
  • Publicly available through the NYC Open Data platform.\
  • Each row represents a single trip with details including pickup/dropoff times and locations, fare amount, tip amount, and payment type.

Secondary Dataset: American Community Survey (ACS)

  • Table: B19001 -- Household Income in the Past 12 Months (2023)\
  • Retrieved from the U.S. Census Bureau's ACS 1-Year Estimates\
  • Used to extract median income at the neighborhood (PUMA) level.\
  • Income data was spatially joined to pickup/dropoff zones based on TLC taxi zones.

Data Overview

After cleaning and preprocessing, we used trip data from four months in 2023 (as specified in our code). Each processed dataset contains:

  • Approximately 21 columns, including engineered features such as tip percentage and time-of-day variables.\
  • The datasets vary in size depending on the month but each contains hundreds of thousands of rows.\
  • Trips with zero fare, zero tip, or missing location data were excluded.\
  • Geographic income data was merged using spatial joins to match taxi zones to median income estimates.

Libraries

The following Python libraries are required to run the analysis and modeling process:

import numpy as np  
import pandas as pd  
import statsmodels.api as sm  
from sklearn.model_selection import train_test_split  
import matplotlib.pyplot as plt  
import seaborn as sns  
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score  
from sklearn.linear_model import LinearRegression  
from sklearn.ensemble import RandomForestRegressor  
import geopandas as gpd  

Model Specification

To predict tipping behavior in NYC taxi rides, we implemented supervised machine learning models---specifically, Linear Regression and Random Forest Regression. Linear Regression provides a straightforward and interpretable baseline for understanding the relationship between tipping and variables like fare, distance, and neighborhood income. It helps identify whether a linear relationship exists between predictors and the tip amount or percentage.

Random Forest is a more flexible, non-linear model that can capture complex interactions between features. It is particularly well-suited for our dataset, which includes both numerical and categorical variables, and helps address potential overfitting through ensemble learning. Using both models allows us to compare performance and better understand the underlying patterns in tipping behavior.

We evaluate model performance using Root Mean Squared Error (RMSE) and R² Score to assess accuracy and explanatory power. These metrics help determine how well the models predict tipping based on socioeconomic and trip-related features.

Feature Overview

Feature Description Type
Distance Total distance of the trip (in miles) Numerical
Fare Total fare amount for the trip Numerical
Tip Percentage Tip as a percentage of the fare Numerical
Hour Hour of the day when the trip started Categorical
Day of Week Day of the week (e.g., Monday, Tuesday) Categorical
Pickup Location TLC taxi zone where the trip started Categorical
Dropoff Location TLC taxi zone where the trip ended Categorical
Neighborhood Income Median household income of the pickup/dropoff neighborhood Numerical
Taxi Type Type of taxi (Yellow, Green, Uber, Lyft) Categorical

Methodology & Tools

To associate socioeconomic context with taxi trips, income data was merged with trip records by matching location identifiers to neighborhood-level income estimates. After cleaning and filtering the data to remove outliers and missing values, models were trained on a subset of trip data. Exploratory Data Analysis (EDA) was conducted using visualization libraries such as Matplotlib and Seaborn, allowing the team to identify trends, detect anomalies, and better understand the relationships between variables.


Citations

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages