Increasing NYC Taxi Drivers Earnings
Problem Description
Opportunity
Taxi drivers could increase their earnings by changing their strategy.
Questions to solve
- How much can a taxi driver increase their monthly earnings just by skipping trips under defined conditions?
- How much can a taxi driver increase their monthly earnings just by changing their initial zone and time?
Business success criteria
Develop a strategy to increase NYC taxi driversβ monthly earnings by 20%.
Project scope
This project will be limited to Juno, Uber, Via and Lyft taxi drivers who work in New York City in trips that take place between any zone of Manhattan, Brooklyn or Queens (the more active ones).
Results Highlight
π€ Modeling for Decision Support
To ensure the model supports realβworld driver decisions, we framed the problem as a sequential decision task rather than a pure prediction exercise. The goal is to maximize net hourly earnings, not just classification accuracy.
- From probabilistic predictions to profitβdriven thresholds: We selected the Brier score as the primary evaluation metric because it measures both discrimination and calibrationβessential when probabilities inform acceptance decisions. To translate predicted probabilities into actionable trip recommendations, we performed a threshold optimization that accounts for asymmetric misclassification costs: rejecting a lucrative trip (false negative) is far costlier than accepting a mediocre one (false positive). By simulating driver earnings across 5βfold crossβvalidation, we identified an optimal decision threshold of 0.22βwell below the default 0.5. This lower threshold reflects the fact that drivers should be slightly more willing to accept trips, as the opportunity cost of waiting for a βperfectβ fare outweighs the risk of a lowβvalue ride.
- Robustness and generalisation: The final XGBoost model was evaluated on a heldβout test set, achieving a Brier score of 0.146 (matching crossβvalidation) and delivering a net benefit of $0.35 per trip compared to a βtakeβallβ baseline. This represents a 51.5% improvement in expected cost, confirming that the costβbenefit tradeβoff remains stable on unseen data.


π― Sequential Decision Framework & Business Logic
The core of this project is not a simple classification task; it is a Sequential Decision Analytics problem. I transformed raw observational taxi data into a decision-making tool by addressing two major challenges:
- The Target Variable Dilemma: The original dataset lacked a βground truthβ for whether a trip was optimal. I engineered the target variable
take_current_tripby calculating the Opportunity Cost of each trip. This involved simulating the potential earnings of waiting for a high-value fare versus accepting the immediate request, creating a decision-centric label from scratch. - The Baseline Paradox: I established a βTake-All Policyβ (accepting every trip) as the baseline. While the ML model shows strong predictive performance (AUC and Brier Score), I have framed the project to acknowledge that predictive accuracy does not automatically equate to policy superiority. The model is designed to optimize a threshold that maximizes net hourly earnings, not just βhits and misses.β
πΎ Engineering for Big Data & Software Reliability (Out-of-Core Processing)
I architected a robust, production-grade pipeline designed to handle datasets exceeding available RAM while maintaining strict software engineering standards:
Custom Tidymodels Extensions: To integrate geospatial features seamlessly into the machine learning pipeline, I developed a custom
recipesstep. This allows for the automated preprocessing of coordinates and spatial joins within a unified workflow, ensuring that feature engineering is consistent during both training and inference.Production-Grade R Development: To ensure reliability, the project is structured as a formal R package, moving beyond simple scripts to a maintainable codebase.
Unit Testing: I implemented a comprehensive suite of tests using
testthatto validate custom logic, specifically for the simulation functions and the customrecipessteps.Rigorous Documentation: All core functions are fully documented using
roxygen2, providing clear API definitions, parameter requirements, and usage examples.
Hybrid Analytical Engine: I utilized DuckDB as an out-of-core engine to perform heavy aggregations and joins directly on disk. Once filtered, I leveraged data.table in R for ultra-efficient in-memory manipulation, combining SQLβs disk performance with Rβs functional programming power.
Reproducible Environments: The entire stack is managed via Nix and Docker, ensuring the environmentβincluding complex geospatial system dependenciesβis 100% reproducible across any machine.
πΊοΈ High-Dimensional Feature Engineering & Spatial Intelligence
- Conceptual Clustering (NLP): To navigate the βCurse of Dimensionalityβ presented by 160,000+ US Census variables, I didnβt use arbitrary selection. I applied NLP (Jaccard Distance) and Edge-Betweenness clustering to group variables into conceptual themes (e.g., βCommuting Habits,β βWealth Distributionβ), allowing for a data-driven prioritization of features.
- Geospatial Intersections: Integrated OpenStreetMap (OSM) data by performing complex spatial intersections. I mapped road lengths and amenity densities (restaurants, transit hubs) to specific taxi zones to capture the geographic βDNAβ of NYC.
Methodology
To find the optimal solution for those questions, we will follow the methodology proposed by Warren B. Powell (2022) in Sequential Decision Analytics and Modeling: Modeling with Python and combine it with the Cross-Industry Standard Process for Data Mining (CRISP-DM) to define a machine learning model that will power the sequential decision to optimize.


Following the steps of both methodologies, we have organized the articles created in this portfolio website:
| Sequential Decision Analytics | CRISP-DM | Article Name |
|---|---|---|
| Core Elements of the Problem | Business Understanding | 1. Business Understanding Overview |
| Data Understanding | 2. Data Collection Process | |
| From Defining Mathematical Model to Evaluating Policy | Business Understanding | 3. Defining Base Line |
| Data Understanding | 4. Data Sampling 5. Initial Exploration |
|
| Data Preparation | 6. Expanding Geospatial Information 7. Expanding Transportation and Socioeconomic Patterns |
|
| Modeling and Evaluation | 8. Training and Selecting Model To Implement | |
| From Defining Mathematical Model to Evaluating Policy | 9. Implementing ML Model To Sequential Problem (Pending) | |
| Deployment | 10. Wrap Decision Model into REST API (Pending) 11. Serving Model by a Shiny Web App (Pending) |
Data to Use
In this project, we will use a subset of the data available in the TLC Trip Record Data from 2022 to 2023 for High Volume For-Hire Vehicle β which covers the Juno, Uber, Via and Lyft trips within our project scope β with the columns described in its data dictionary.
Disclaimer
This project was completed under strong assumptions given that the data used in the analysis does not provide any unique identifier for taxi drivers, which limits the realism of some results.
Additionally, this project aims to increase taxi driver earnings at the individual level. However, if applied extensively, it could also produce the following unintended consequences:
Reduced service quality: Drivers focusing solely on maximizing earnings may avoid less profitable areas or times, potentially leaving some passengers underserved.
Increased congestion: Drivers congregating in high-profit areas could worsen traffic in already busy parts of the city.
This project is intended as a demonstration of data science methodology rather than a prescriptive business recommendation, and these considerations should be carefully weighed before any real-world implementation.
Roadmap & Future Developments
Sequential Decision Analytics (Warren Powell Framework)
The next stage involves moving beyond static evaluation to a dynamic environment. I am integrating the ML model into the framework established by Warren B. Powell (2022) in Sequential Decision Analytics and Modeling.
- Policy Function Approximation (PFA): Using the ML modelβs calibrated probabilities to define a decision policy.
- Four Elements Modeling: Formally defining the State (driver location, time), Decision (Accept/Reject), Exogenous Information (new trip requests), and the Objective Function (Maximizing total daily revenue).
Deployment & Accessibility
To transition this from a local research project to a production-grade tool, I will implement:
- REST API: A R/Plumber API to serve real-time trip recommendations based on the trained XGBoost model.
- Shiny Dashboard: An interactive web application built in Shiny to visualize the driverβs predicted earnings, optimal decision thresholds, and spatial demand heatmaps in real-time.

Try the app in your browser: NYC Taxi Zone Selector on Hugging Face Spaces
Source code: https://github.com/AngelFelizR/nyc-taxi-zone-selector
Project Structure and Tooling
Reproducibility and long-term maintainability were core priorities from the start, which shaped every tooling decision in this project. The following tools were used to achieve this:
- We use
gitto manage changes in the code and provide an interface to share the project on GitHub. DockerandNixare used to build a reproducible dev-container based ondefault.nix. The container can be connected via SSH using a public and private key pair as defined insetup.sh, and the.envrcsets the Nix environment to use in the Positron console.- For modeling, we used the
tidymodelsframework to ensure we are following good modeling practices. - Since the project follows the basic structure of an R package, we were able to document and create unit tests for custom functions using
testthat,roxygen2anddevtools. This was especially important to ensure that the simulation function and the custom step function (which extends therecipespackage) work correctly. - The project also follows the structure of a Quarto project and renders all articles into the
docsfolder, giving us full control over the format used to present each article. Results are hosted on GitHub Pages, so they can be shared at no cost. - The
.Rprofileoverridesinstall.packages,update.packagesandremove.packagesto make clear that R packages must be defined indefault.nixto ensure reproducibility. - To manage data larger than RAM, we use
duckdband keep large files in a separate folder namedNycTaxiBigFilesunder the same parent directory as this repo. - To cache results generated during the investigation process, we use
.qs2files and track them withpins, stored under the folderNycTaxiPinsin the same parent directory as this repo. - We use the air extension to ensure consistent code formatting across the project.
The result is a hybrid structure that combines an R package (with documented functions and unit tests) and a Quarto website (with rendered articles and hosted results), which was one of the most challenging aspects of the project to set up correctly:
tree -L 3
.
βββ about.qmd
βββ air.toml
βββ default.nix
βββ DESCRIPTION
βββ docker-compose.yml
βββ Dockerfile
βββ docs
β βββ about.html
β βββ figures
β β βββ CRISP-DM_Process_Diagram.png
β β βββ htop_parallel_process.png
β β βββ logo-generated.jpeg
β β βββ model_benefit_curve.png
β β βββ model-benefit.jpg
β β βββ nyc-taxi-navbar-logo.png
β β βββ nyc-taxi-navbar-logo.xcf
β β βββ Sequential-Decision-Modeling-Framework.png
β βββ index.html
β βββ investigation-phases
β β βββ 01-business-understanding.html
β β βββ 02-data-collection-process.html
β β βββ 03-base-line_files
β β βββ 03-base-line.html
β β βββ 04-data-sampling.html
β β βββ 05-initial-exploration_files
β β βββ 05-initial-exploration.html
β β βββ 06-expanding-geospatial-data_files
β β βββ 06-expanding-geospatial-data.html
β β βββ 07-expanding-transportation-socioeconomic_files
β β βββ 07-expanding-transportation-socioeconomic.html
β β βββ 08-model-selection_files
β β βββ 08-model-selection.html
β βββ man
β β βββ figures
β βββ search.json
β βββ site_libs
β βββ bootstrap
β βββ clipboard
β βββ DiagrammeR-styles-0.2
β βββ ggiraphjs-0.9.2
β βββ girafe-binding-0.9.2
β βββ grViz-binding-1.0.11
β βββ htmltools-fill-0.5.8.1
β βββ htmlwidgets-1.6.4
β βββ jquery-3.6.0
β βββ leaflet-1.3.1
β βββ leaflet-binding-2.2.3
β βββ leafletfix-1.0.0
β βββ Leaflet.glify-3.2.0
β βββ leaflet-providers-2.0.0
β βββ leaflet-providers-plugin-2.2.3
β βββ proj4-2.6.2
β βββ Proj4Leaflet-1.0.1
β βββ quarto-html
β βββ quarto-nav
β βββ quarto-search
β βββ rstudio_leaflet-1.3.1
β βββ viz-1.8.2
βββ figures
β βββ CRISP-DM_Process_Diagram.png
β βββ htop_parallel_process.png
β βββ logo-generated.jpeg
β βββ model_benefit_curve.png
β βββ model-benefit.jpg
β βββ nyc-taxi-navbar-logo.png
β βββ nyc-taxi-navbar-logo.xcf
β βββ Sequential-Decision-Modeling-Framework.png
βββ generate_env.R
βββ index.qmd
βββ investigation-phases
β βββ 01-business-understanding.qmd
β βββ 02-data-collection-process.qmd
β βββ 03-base-line.qmd
β βββ 04-data-sampling.qmd
β βββ 05-initial-exploration.qmd
β βββ 06-expanding-geospatial-data.qmd
β βββ 07-expanding-transportation-socioeconomic.qmd
β βββ 08-model-selection.qmd
βββ man
β βββ add_performance_variables.Rd
β βββ add_pred_class.Rd
β βββ add_take_current_trip.Rd
β βββ calculate_costs.Rd
β βββ collect_predictions_best_config.Rd
β βββ compare_model_predictions.Rd
β βββ figures
β β βββ logo.hex
β β βββ logo-image.png
β β βββ logo.png
β β βββ Logo-source.txt
β βββ NycTaxi-package.Rd
β βββ plot_bar.Rd
β βββ plot_box.Rd
β βββ plot_heap_map.Rd
β βββ plot_num_distribution.Rd
β βββ required_pkgs.step_join_geospatial_features.Rd
β βββ simulate_trips.Rd
β βββ step_join_geospatial_features.Rd
βββ multicore-scripts
β βββ 01-fine-tune-future-process.R
β βββ 02-add-target.R
β βββ 02-run_add_target.sh
β βββ 03a-tuning-simple-models.R
β βββ 03b-tuning-dimreduction-models.R
β βββ 03c-tuning-tree-models.R
βββ NAMESPACE
βββ params.yml
βββ _quarto.yml
βββ R
β βββ add_take_current_trip.R
β βββ calculate_costs.R
β βββ compare_model_predictions.R
β βββ NycTaxi-package.R
β βββ plot_bar.R
β βββ plot_box.R
β βββ plot_heap_map.R
β βββ plot_num_distribution.R
β βββ simulate_trips.R
β βββ step_join_geospatial_features.R
β βββ utils.R
βββ README.md
βββ result -> /nix/store/63jxvg9zwnwab3jmv74pdsp6pmr2hbww-nix-shell
βββ setup.sh
βββ tests
βββ testthat
β βββ fixtures
β βββ test-add_take_current_trip.R
β βββ test-calculate_costs.R
β βββ test-plot_box.R
β βββ test-simulate_trips.R
β βββ test-step_join_geospatial_features.R
βββ testthat.R
43 directories, 90 filesDefining Development Environment
To reproduce the results of this project, follow these steps to set up the same environment using Docker and Nix.
1. Install Docker and Docker Compose
You need Docker and Docker Compose. Choose the appropriate installation method for your operating system:
- Windows or macOS: Install Docker Desktop (includes Docker Compose).
- Linux: Install the Docker Engine and then Docker Compose.
For Debian 13 (as an example), run the following as root:
apt update
apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian trixie stable"
apt update
apt install -y docker-ce docker-compose-plugin
systemctl enable docker && systemctl start docker
usermod -aG docker <YOUR-USER>
su - <YOUR-USER>Note: Replace <YOUR-USER> with your actual username.
2. Clone the Repository and Prepare Directories
Navigate to the parent directory where you want to store the project and the data folders. Then run:
cd <parent-dir-path>
mkdir NycTaxiBigFiles
mkdir NycTaxiPins
git clone https://github.com/AngelFelizR/NycTaxiYour directory structure should look like:
<parent-dir-path>/
βββ NycTaxi/ # cloned repository
βββ NycTaxiBigFiles/ # large data files (mounted into container)
βββ NycTaxiPins/ # pin board storage (mounted into container)3. Run the Setup Script
The repository includes a setup.sh script that automates all remaining steps: pulling the image, starting the container, and configuring SSH key-based authentication using your existing ~/.ssh/id_rsa.pub.
From inside the NycTaxi folder, run:
cd NycTaxi
chmod +x setup.sh
./setup.shThe script will:
- Pull the pre-built image
angelfelizr/nyc-taxi:4.5.2from Docker Hub. - Start the container in detached mode, mapping port
2222for SSH and mounting the three directories under/root/. - Register your public key (
~/.ssh/id_rsa.pub) inside the container so you can connect without a password.
#!/bin/bash
docker compose pull
docker compose up -d
docker compose cp ~/.ssh/id_rsa.pub nyc-taxi:/root/.ssh/authorized_keys
docker compose exec nyc-taxi chown root:root /root/.ssh/authorized_keys
docker compose exec nyc-taxi chmod 600 /root/.ssh/authorized_keys
echo "Listo! Conectate con: ssh NycTaxi"You can verify the container is running with docker compose ps.
4. Configure SSH
Add the following to your ~/.ssh/config so you can connect with a simple alias:
Host NycTaxi
HostName 127.0.0.1
User root
Port 2222
IdentityFile ~/.ssh/id_rsa
Then connect with:
ssh NycTaxi5. Using Positron (or VS Code) with direnv
Since direnv is configured via the .envrc file in the repository, you can use Positron with the SSH remote development feature to work directly inside the container.
- In Positron, select βConnect to Hostβ¦β (or use the Remote Explorer).
- Enter
root@localhost:2222and authenticate using your SSH key (configured in Step 3). - Once connected, open the folder
/root/NycTaxi. - Install the direnv extension by mkhl from the Open VSX Registry. This extension automatically activates direnv when you open a folder containing an
.envrcfile.
After the extension loads, you should see a notification confirming that direnv is active. At that point, any terminal you open inside Positron will have the Nix environment loaded automatically.
To make the R interactive console use the Nix environment instead of the system default, open the Positron command palette and switch the active R interpreter to the one provided by the Nix shell. Once selected, the console will have access to all the R packages defined in default.nix.
6. Remote Pin Board (Optional)
If you need to use the shared pin board, create a cache directory on your host (outside the container) and then, inside R, set up the board as follows:
# On your host (in <parent-dir-path>)
mkdir NycTaxiBoardCacheIn your R session (inside the Nix shell), use:
BoardRemote <- board_url(
"https://raw.githubusercontent.com/AngelFelizR/NycTaxiPins/refs/heads/main/Board/",
cache = here::here("../NycTaxiBoardCache")
)The cache directory is mounted into the container at /root/NycTaxiBoardCache, so pins will be stored on your host and persist between container restarts.