End-to-end machine learning project that predicts NYC yellow taxi fare amounts using a 100k-row sample from the BigQuery public dataset (tlc_yellow_trips_2022).
Authors: Gabriele Cola · Swann Etro
- Project Structure
- Prerequisites
- Google Cloud Authentication
- Environment Setup
- Running the Notebook
- MLflow Tracking
- Models
NYC_Taxi/
├── NYC_Taxi2.ipynb # Main notebook (orchestrator)
├── Functions/
│ ├── config.py # All constants: BQ project, columns, hyperparameters
│ ├── data_loader.py # BigQuery loading logic
│ ├── pre_processing.py # Type conversion, NA imputation, outlier removal
│ ├── feature_engineering.py # Temporal features, label encoding, train/test split
│ ├── modelling.py # Model building, training, evaluation
│ └── mlflow_tracking.py # MLflow logging helpers
├── Data/ # Local data files (if any)
├── mlruns/ # MLflow run artifacts (auto-generated)
├── requirements.txt
└── README.md
- Anaconda / Miniconda
- Google Cloud SDK (
gcloud) - A Google Cloud project with the BigQuery API enabled
The notebook reads data directly from BigQuery. You need to authenticate your local machine before running it.
Follow the official guide for your OS: https://cloud.google.com/sdk/docs/install
Verify the installation:
gcloud --versiongcloud auth loginA browser window will open. Sign in with the Google account that has access to the BigQuery project.
This is what the Python BigQuery client uses internally:
gcloud auth application-default loginAgain, a browser window will open. After completing this step, credentials are saved locally and the notebook will pick them up automatically — no service account key needed.
gcloud config set project nyc-taxi-project-455608bq ls bigquery-public-data:new_york_taxi_tripsYou should see a list of tables including tlc_yellow_trips_2022.
Common error:
google.auth.exceptions.DefaultCredentialsError→ You skipped step 3. Rungcloud auth application-default loginand retry.
conda create -n NYC_Taxi python=3.11 -y
conda activate NYC_Taxipip install -r requirements.txtpip install db_dtypes mlflow xgboost lightgbm
db_dtypesis required by the BigQuery client to parse certain column types into pandas.
python -m ipykernel install --user --name NYC_Taxi --display-name "Python (NYC_Taxi)"Cmd+Shift+P → Python: Select Interpreter → pick NYC_Taxi
Open NYC_Taxi2.ipynb and run all cells top to bottom. The notebook is organised into six sections:
| Section | What happens |
|---|---|
| 0. Libraries | Imports and loads all custom modules from Functions/ |
| 1. Importing | Pulls 100k random rows from BigQuery |
| 2. Pre-Processing | Type conversion → NA imputation → outlier removal |
| 3. EDA | Distributions, peak hours, seasonality, anomaly detection, correlation heatmap |
| 4. Feature Engineering | Temporal features, label encoding, train/test split, StandardScaler |
| 5. Model Training | Trains 7 models + VotingRegressor, prints RMSE / MAE / R² summary |
| 6. Model Tracking | Logs all runs, metrics, plots and serialised models to MLflow |
After running section 6, launch the MLflow UI to compare runs:
mlflow uiThen open http://localhost:5000 in your browser.
Each run logs:
- Metrics: RMSE, MAE, R²
- Parameters: model hyperparameters
- Artifacts: True-vs-Predicted scatter plots, serialised model files
- Parent run: surfaces the best model name and its RMSE at a glance
To clean up old MLflow runs:
bash cleanup_mlruns.sh| Model | Library |
|---|---|
| Linear Regression | scikit-learn |
| Ridge Regression | scikit-learn |
| Lasso Regression | scikit-learn |
| Random Forest | scikit-learn |
| Gradient Boosting | scikit-learn |
| MLP Neural Network | scikit-learn |
| XGBoost | xgboost |
| VotingRegressor (ensemble) | scikit-learn |
The best single model from the initial runs is Gradient Boosting, with the VotingRegressor ensemble close behind.
Section 5.2 also performs a RandomizedSearchCV hyperparameter search on Ridge Regression specifically, and saves the best estimator to ridge_best_model.pkl.