{"id":22984365,"url":"https://github.com/krzysikd/uber_fare_prediction","last_synced_at":"2025-04-02T10:44:11.305Z","repository":{"id":268096834,"uuid":"895987018","full_name":"krzysikd/Uber_Fare_Prediction","owner":"krzysikd","description":"Predicting uber fares using advanced machine learning models and feature engineering techniques","archived":false,"fork":false,"pushed_at":"2024-12-14T09:00:06.000Z","size":36171,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T01:51:29.506Z","etag":null,"topics":["data-analysis","data-processing","eda","hyperparameter-tuning","jupyter","machine-learning","regression-models"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krzysikd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T10:16:28.000Z","updated_at":"2024-12-14T09:00:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"051bb235-8ac5-4486-b6bf-9086ae6a9106","html_url":"https://github.com/krzysikd/Uber_Fare_Prediction","commit_stats":null,"previous_names":["krzysikd/uber_fare_prediction"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysikd%2FUber_Fare_Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysikd%2FUber_Fare_Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysikd%2FUber_Fare_Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysikd%2FUber_Fare_Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krzysikd","download_url":"https://codeload.github.com/krzysikd/Uber_Fare_Prediction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246802596,"owners_count":20836368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-analysis","data-processing","eda","hyperparameter-tuning","jupyter","machine-learning","regression-models"],"created_at":"2024-12-15T03:15:47.798Z","updated_at":"2025-04-02T10:44:11.296Z","avatar_url":"https://github.com/krzysikd.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Uber ride fare prediction\nFor a more detailed explanation of the project and the code, please refer to the [Jupyter Notebook](./Uber_Fares_Prediction.ipynb) or the [PDF report](./Uber_Fares_Prediction.pdf).\n\n## Problem description\nThis project focuses on analyzing Uber ride fares, including exploratory data analysis (EDA) with hypothesis testing, and building a model to predict future ride costs. The data is sourced from Kaggle: [Uber Fares Dataset](https://www.kaggle.com/datasets/yasserh/uber-fares-dataset/data).\n\n## Exploratory data analysis (EDA)\nEDA revealed key insights, such as the strong relationship between trip distance and fare, and guided the removal of anomalies (e.g., negative or excessively high fares).\n\n![Fare Distribution](exports/EDA/Distribution%20of%20fare%20amount.png)\n\n## Data processing\nData preparation steps included:\n- Removing outliers and ensuring geographic coordinates were realistic.\n- Deriving new features from `pickup_datetime` (Year, Month, Day, DayOfWeek, Hour).\n- Calculating `distance_km` between pickup and dropoff points.\n- Computing distances to landmarks (Times Square, JFK Airport, etc.) to capture location-based effects.\n- Splitting the data into training, validation, and test sets:\n  - **Training set:** 117,057 samples\n  - **Validation set:** 39,020 samples\n  - **Test set:** 39,020 samples\n- Normalizing numerical features using MinMaxScaler to ensure all values are within the same range.\n\n## Modeling and comparison\nMultiple models were tested:\n- **Linear \u0026 Ridge Regression**: baseline performance (RMSE ~5.0 on validation).\n- **ElasticNet**: underperformed compared to the baseline.\n- **Decision Tree \u0026 Random Forest**: improved results (RMSE ~3.85+ on validation).\n- **Gradient Boosting:** further improvement, with RMSE ~3.78 initially.\n\n**Comparison table (validation set)**:\n| Model             | val_rmse | val_r2  |\n|-------------------|----------|---------|\n| Linear Regression  | ~5.01    | ~0.72   |\n| Ridge Regression   | ~5.03    | ~0.72   |\n| ElasticNet         | ~9.48    | -0.00   |\n| Decision Tree      | ~4.22    | ~0.80   |\n| Random Forest      | ~3.85    | ~0.83   |\n| Gradient Boosting  | ~3.78    | ~0.84   |\n\nXGBoost, as the top-performing model, was chosen for final testing and hyperparameter tuning.\n\n## Hyperparameter tuning\nSystematic hyperparameter tuning involved:\n- Manual adjustments and visualization-based insights for parameters like `learning_rate`, `n_estimators`, and `max_depth`.\n- Automated searches using GridSearchCV and RandomizedSearchCV to find optimal configurations.\n\n**Final parameters**:\n```python\n{\n  'random_state': 42,\n  'n_jobs': 1,\n  'objective': 'reg:squarederror',\n  'learning_rate': 0.05,\n  'n_estimators': 100,\n  'max_depth': 6,\n  'subsample': 0.8,\n  'colsample_bytree': 1,\n  'gamma': 0,\n  'reg_lambda': 1,\n  'reg_alpha': 0.1\n}\n``` \n\n| Model             | val_rmse | val_r2  |\n|-------------------|----------|---------|\n| XGBoost Tuning     | ~3.74    | ~0.84   |\n| GridSearchCV (XGB) | ~3.64    | ~0.85   |\n\n## Test set prediction\n\nThe final XGBoost model, after tuning and validation, was tested on the unseen test dataset. The results demonstrate that the model generalizes well and maintains strong predictive performance on the test set:\n\n- **Test RMSE**: **3.8053**  \n- **Test R²**: **0.8446**  \n\nThese metrics indicate that the model effectively captures the underlying patterns in the data and is well-suited for predicting fare amounts in this use case.\n\n## Conclusion and insights\n\nFollowing a clear, step-by-step workflow ensured a systematic approach to the project, reducing errors and maintaining focus on incremental improvements at each stage. The process highlighted the importance of thorough data preprocessing and feature engineering, which provided the foundation for building an accurate predictive model.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzysikd%2Fuber_fare_prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrzysikd%2Fuber_fare_prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzysikd%2Fuber_fare_prediction/lists"}