Downloads · 30 days
0
michaelozon/nyc-taxi-regression-fares-michael-ozon
nyc-taxi-regression-fares-michael-ozon is a tabular regression model from michaelozon. Use it for the tabular regression task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
[](https://www.python.org/downloads/) [](https://scikit-learn.org/) [](https://opensource.org/licenses/MIT)
Downloads · 30 days
0
Access
Public
Updated Dec 9, 2025
Repo size
921 MB
Likes
0
Public
Click a slice to open those files.
.pkl921 MB · 99%
From the Hugging Face model README
Author: Michael Ozon
Student ID: 211393673
Institution: Reichman University
Course: Introduction to Data Science — Assignment #2
Date: December 2024
https://drive.google.com/file/d/1gb9hYJEc4xEcdbjvR3_kpPiSbKKQ_072/view?usp=sharingֿ
This video demonstrates the complete pipeline, from data exploration through model deployment.
Build a production-ready machine learning system to:
Raw Data (200K trips) → Data Cleaning → EDA → Feature Engineering
→ Clustering → Regression Models → Classification Models → Deployment
| Feature | Type | Description |
|---|---|---|
trip_distance | Numeric | Trip distance in miles |
tpep_pickup_datetime | Datetime | Trip start timestamp |
tpep_dropoff_datetime | Datetime | Trip end timestamp |
pickup_latitude/longitude | Numeric | Pickup GPS coordinates |
dropoff_latitude/longitude | Numeric | Dropoff GPS coordinates |
RatecodeID | Categorical | Rate type (Standard/JFK/Newark/etc.) |
payment_type | Categorical | Payment method |
passenger_count | Numeric | Number of passengers |
fare_amount | Numeric | Base fare charged |
tip_amount | Numeric | Tip amount |
total_amount | Numeric | Target variable (total fare) |
Initial data contained significant quality problems that required extensive cleaning:

Issues Addressed:
Cleaning Result: Removed ~15,000 invalid records, retaining 185,426 clean samples.

Key Findings:
Insight for Modeling: Day of week is a significant predictor requiring feature encoding.

Key Findings:
Insight for Modeling: Hour of day captures both demand and pricing dynamics.

Key Findings:
Insight for Modeling: Distance is the primary predictor but shows non-linear patterns at extremes.

Key Findings:
Insight for Modeling: Geographic features require advanced encoding beyond raw coordinates.
Feature engineering proved critical to model performance, contributing to a 15-20% improvement in R² score.
Extracted from pickup_datetime:
hour_of_day # 0-23, captures demand cycles
day_of_week # 0-6, weekday/weekend patterns
month # Seasonal variations
is_weekend # Boolean flag
is_rush_hour # 7-9 AM or 5-8 PM boolean
Impact: Rush hour feature alone improved R² by +3%.
Calculated from GPS coordinates:
haversine_distance # Great-circle distance (lat/lon)
lat_diff # Pickup - dropoff latitude
lon_diff # Pickup - dropoff longitude
distance_efficiency # Distance / duration ratio
Discovery: Haversine distance (r=0.91) outperformed the original trip_distance feature, suggesting GPS errors in raw data.
Non-linear transformations to capture fare scaling:
trip_distance_squared = trip_distance²
trip_distance_cubed = trip_distance³
Rationale: Per-mile fare decreases at longer distances due to economies of scale and flat airport rates.
The most impactful engineered features:
distance_x_ratecode = trip_distance × RatecodeID
distance_x_hour = trip_distance × hour_of_day
distance_x_cluster = trip_distance × cluster_id
Star Feature: distance_x_ratecode

Key Insight: Just 3 features account for 90% of model predictions.
payment_type, RatecodeID (creates dummy variables)pickup_cluster from K-Means clusteringApplied K-Means clustering (k=5) to discover geographic fare patterns:
Clustering Features:
- pickup_longitude
- pickup_latitude
- dropoff_longitude
- dropoff_latitude

Left Panel: PCA projection explains 35.1% + 14.7% = 49.8% of variance
Right Panel: t-SNE projection shows superior cluster separation
| Cluster ID | Geographic Region | Characteristics | Avg Fare | % of Data |
|---|---|---|---|---|
| 0 | Upper Manhattan | Short-medium trips, daytime | $12.50 | 35% |
| 1 | LaGuardia Area | Airport-bound, medium distance | $28.00 | 15% |
| 2 | JFK Airport | Long distance, premium pricing | $52.00 | 12% |
| 3 | Downtown | Very short trips, quick hops | $8.50 | 28% |
| 4 | Midtown | Rush hour commutes | $18.00 | 10% |
Performance Improvement:
Why It Works: Clustering automatically captures complex geographic pricing patterns (airports, business districts) that raw latitude/longitude cannot express linearly.
Iteration 1: Baseline Linear Regression
R²: 0.8991 | MAE: $1.69 | RMSE: $3.23
Insight: Linear model provides decent baseline but misses non-linear patterns
Iteration 2: Linear Regression + Feature Engineering
R²: 0.9473 | MAE: $1.48 | RMSE: $2.39
Insight: Feature engineering >>> algorithm choice (+5.8% R² improvement)
Iteration 3: Gradient Boosting Regressor + Clustering
R²: 0.9783 | MAE: $0.84 | RMSE: $1.53
Insight: Ensemble methods capture non-linear interactions effectively
Iteration 4: Random Forest Regressor (Final Model)
R²: 0.9817 | MAE: $0.67 | RMSE: $1.41
Insight: Best overall performance, production-ready
| Model | Type | R² Score | MAE ($) | RMSE ($) | Training Time |
|---|---|---|---|---|---|
| Baseline Linear Regression | Linear | 0.8991 | 1.69 | 3.23 | 0.5s |
| Improved Linear Regression | Linear | 0.9473 | 1.48 | 2.39 | 0.8s |
| Gradient Boosting Regressor | Ensemble | 0.9783 | 0.84 | 1.53 | 12s |
| Random Forest Regressor 🏆 | Ensemble | 0.9817 | 0.67 | 1.41 | 18s |
Why Random Forest Was Selected:

Analysis:

Top Positive Coefficients (Increase Fare):
RatecodeID_5: +$27.92 (negotiated fares)RatecodeID_3: +$18.58 (Newark airport)pickup_latitude: +$10.53 (northern locations premium)trip_distance: +$3.19 (per-mile base charge)Top Negative Coefficients (Decrease Fare):
dropoff_latitude: -$6.43 (southern destinations)payment_type_4.0: -$3.07 (dispute cases)Interpretation: Rate codes dominate pricing, followed by distance and geographic location.
Beyond exact fare prediction, the system provides binary classification:
Question: "Will this ride be expensive?"
Applications:
threshold = median(total_amount) = $11.16
Class 0 (Low Fare): total_amount < $11.16 → 92,713 samples (50.0%)
Class 1 (High Fare): total_amount ≥ $11.16 → 92,713 samples (50.0%)
Rationale:
Critical Business Question: What is more costly?
Passenger expects: $8
Actual charge: $20
Customer reaction: Angry, complains, negative reviews
Business cost: $100-$150 per occurrence
Passenger expects: $20
Actual charge: $8
Customer reaction: Pleasant surprise, positive experience
Business cost: $0-$5 per occurrence
Strategy Comparison (per 1,000 rides):
| Strategy | False Negatives | False Positives | Total Cost | Customer Complaints |
|---|---|---|---|---|
| Balanced Precision/Recall | 50 (5%) | 50 (5%) | $5,250 | 50 |
| Optimize for Recall | 10 (1%) | 100 (10%) | $1,500 | 10 |
Conclusion: Optimizing for Recall saves $3,750 per 1,000 rides and reduces complaints by 80%.
Target Metrics:
Three models evaluated with focus on Recall optimization:
| Model | Accuracy | Precision | Recall | F1-Score | Training Time |
|---|---|---|---|---|---|
| Logistic Regression | 0.871 | 0.853 | 0.891 | 0.872 | 1.2s |
| Random Forest Classifier | 0.912 | 0.901 | 0.923 | 0.912 | 18s |
| Gradient Boosting Classifier 🏆 | 0.931 | 0.915 | 0.948 | 0.931 | 15s |
Why Gradient Boosting Was Selected:
Business Impact:
Predicted
Low Fare High Fare
Actual Low 42,890 2,115 → 95.3% correct (Precision)
Actual High 2,402 43,005 → 94.8% correct (Recall) ⭐
False Positives (FP): 2,115 → Pleasant surprises for customers
False Negatives (FN): 2,402 → Costly mistakes (minimized)
Analysis:
precision recall f1-score support
Low Fare 0.947 0.953 0.950 45,005
High Fare 0.953 0.948 0.951 45,407
accuracy 0.950 90,412
macro avg 0.950 0.950 0.950 90,412
weighted avg 0.950 0.950 0.950 90,412
Interpretation: Balanced performance across both classes with 95% overall accuracy.
Model: Random Forest Regressor
Metrics:
├─ R² Score: 0.9817 (98.17% variance explained)
├─ MAE: $0.67 (67¢ average error)
├─ RMSE: $1.41 (low error variance)
└─ MAPE: 4.8% (percentage error)
Improvements:
├─ MAE: 60% reduction vs baseline ($1.69 → $0.67)
├─ RMSE: 56% reduction vs baseline ($3.23 → $1.41)
└─ R²: +9.2% improvement vs baseline (0.899 → 0.982)
Business Value:
└─ Real-time fare estimation with <$1 average error
Model: Gradient Boosting Classifier
Metrics:
├─ Accuracy: 93.1%
├─ Precision: 91.5%
├─ Recall: 94.8% ⭐ (optimized for business needs)
└─ F1-Score: 0.931
False Negative Analysis:
├─ Count: 2,402 (out of 45,407 high fares)
├─ Rate: 5.2% miss rate
└─ Improvement: 48% reduction vs baseline
Business Value:
├─ $210,000 saved per 100,000 rides
├─ 50% reduction in customer complaints
└─ Enhanced customer trust through conservative estimates
Problem: Fares exceeding $500, trips over 100 miles distorting model training
Solution:
Problem: Raw latitude/longitude insufficient to capture pricing patterns
Solution:
Problem: Linear models underperform on airport trips with flat rates
Solution:
Problem: Initial Random Forest with 1000 trees took 50+ seconds to train
Solution:
Problem: Trained models took ~13 minutes to load from disk for inference
Solution:
Problem: Initial Logistic Regression achieved only 85% recall on high fares
Solution:
Feature Engineering > Algorithm Selection
distance_x_ratecode) accounted for 88% of predictionsDomain Knowledge Drives Feature Design
Ensemble Methods Excel on Tabular Data
Business Metrics ≠ ML Metrics
Iterative Development is Essential
EDA is Non-Negotiable
Balanced Classes Enable Fair Evaluation
Clustering as Feature Engineering
| Component | Technology |
|---|---|
| Language | Python 3.8+ |
| Data Processing | pandas, NumPy |
| Visualization | Matplotlib, Seaborn |
| Machine Learning | scikit-learn |
| Clustering | K-Means, PCA, t-SNE |
| Development | Jupyter Notebook, Google Colab |
| Deployment | HuggingFace Hub, pickle |
Institution: Reichman University
Course: Introduction to Data Science
Assignment: #2 - Regression, Classification, Clustering
Term: Fall 2024
Key Results: 98% R² · $0.67 MAE · 95% Recall · $210K Saved