{"id":51338774,"url":"https://github.com/coderuni/gpp-xgboost-regression","last_synced_at":"2026-07-02T05:31:16.044Z","repository":{"id":309927898,"uuid":"1038050888","full_name":"CoderUni/gpp-xgboost-regression","owner":"CoderUni","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-14T15:01:37.000Z","size":8712,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-15T18:14:48.231Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/CoderUni.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,"zenodo":null}},"created_at":"2025-08-14T14:38:41.000Z","updated_at":"2025-08-14T15:01:42.000Z","dependencies_parsed_at":"2025-08-14T17:24:43.078Z","dependency_job_id":null,"html_url":"https://github.com/CoderUni/gpp-xgboost-regression","commit_stats":null,"previous_names":["coderuni/gpp-xgboost-regression"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CoderUni/gpp-xgboost-regression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderUni%2Fgpp-xgboost-regression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderUni%2Fgpp-xgboost-regression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderUni%2Fgpp-xgboost-regression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderUni%2Fgpp-xgboost-regression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderUni","download_url":"https://codeload.github.com/CoderUni/gpp-xgboost-regression/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderUni%2Fgpp-xgboost-regression/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35034984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-07-02T05:31:15.417Z","updated_at":"2026-07-02T05:31:16.037Z","avatar_url":"https://github.com/CoderUni.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# XGBoost Quick Reference (Regression \u0026 Classification)\n\n## Overview\n\nXGBoost is a fast, regularized gradient boosting library for tabular data. It supports regression, classification, and ranking tasks, with strong performance and flexible tuning.\n\n---\n\n## XGBRegressor vs XGBClassifier\n\n| Feature         | XGBRegressor                        | XGBClassifier                       |\n|-----------------|-------------------------------------|-------------------------------------|\n| Task            | Regression (predict continuous)     | Classification (predict classes)    |\n| Objective       | `\"reg:squarederror\"` (default)      | `\"binary:logistic\"`, `\"multi:softmax\"`, etc. |\n| Metrics         | `\"rmse\"`, `\"mae\"`, `\"r2\"`           | `\"logloss\"`, `\"error\"`, `\"auc\"`, etc. |\n| Target values   | Real numbers                        | Class labels (int or str)           |\n| Example use     | Predict GPP, house prices, etc.     | Predict species, churn, etc.        |\n\n---\n\n## Core Parameters\n\n- `n_estimators`: Max number of boosting rounds. Set high, use early stopping.\n- `learning_rate`: Step size shrinkage. Lower = more trees, less overfit. (0.01–0.1 typical)\n- `booster`: `\"gbtree\"` (default), `\"dart\"` (dropout), `\"gblinear\"` (linear).\n- `max_depth`: Tree depth (4–10 typical).\n- `min_child_weight`: Min sum Hessian in a leaf (1–10).\n- `subsample`: Row sampling per tree (0.6–1.0).\n- `colsample_bytree`: Feature sampling per tree (0.6–1.0).\n- `reg_alpha`/`reg_lambda`: L1/L2 regularization.\n- `gamma`: Min loss reduction to split.\n- `tree_method`: `\"hist\"` (fast CPU), `\"gpu_hist\"` (GPU).\n- `random_state`: For reproducibility.\n- `n_jobs`: Parallel threads.\n\n### DART-specific\n- `rate_drop`, `skip_drop`, `one_drop`: Dropout regularization for trees.\n\n---\n\n## Best Practices for Regression (fit for GPP/data.csv)\n\n1. **Data Prep**: Drop nulls, split into train/val/test.\n2. **Start Simple**: Use `gbtree` with `\"hist\"` and early stopping.\n3. **Tune**: Focus on `max_depth`, `min_child_weight`, `learning_rate`, `subsample`, `colsample_bytree`, `reg_alpha`, `reg_lambda`.\n4. **Early Stopping**: Set `n_estimators` high (e.g., 10000), use `early_stopping_rounds` with a validation set.\n5. **RandomizedSearchCV**: Use for hyperparameter search. Use `scipy.stats.uniform` for continuous params, lists for discrete.\n6. **DART**: Try if overfitting persists. Only tune DART-specific params after core tree params.\n7. **Final Model**: Retrain with best params and early stopping on full train+val, test on untouched test set.\n\n---\n\n## Hyperparameter Tuning Tips\n\n- **Continuous params**: Use `scipy.stats.uniform` (e.g., `\"learning_rate\": scipy.stats.uniform(0.01, 0.2)`).\n- **Discrete/integer params**: Use `np.arange`, `np.linspace`, or lists (e.g., `\"max_depth\": [4, 6, 8]`).\n- **Reduce search time**: Limit parameter ranges, use fewer `n_iter`, and lower `n_estimators` during search.\n- **Early stopping**: Only use in final `.fit()`, not during CV search.\n\n---\n\n## Model Saving\n\n- `.bin`: Fastest, smallest, best for production (XGBoost only).\n- `.json`: Human-readable, cross-language, good for debugging.\n- `.txt`: Most readable, not lossless, for inspection/education.\n\n---\n\n## Regularization\n\n- **L1 (`reg_alpha`)**: Drives weights to zero (feature selection).\n- **L2 (`reg_lambda`)**: Smooths weights (reduces variance).\n- **Tree structure**: Lower `max_depth`, higher `min_child_weight`, higher `gamma` = more regularization.\n- **Stochasticity**: Lower `subsample`/`colsample_bytree` = more regularization.\n- **DART**: Adds dropout to trees for extra regularization.\n\n---\n\n## Example: Regression Workflow (matches `main.ipynb`)\n\n```python\nfrom xgboost import XGBRegressor\nfrom sklearn.model_selection import train_test_split, RandomizedSearchCV\n\n# Data prep\ndf = pd.read_csv(\"data.csv\").dropna()\nX = df.drop(columns=[\"GPP\"])\ny = df[\"GPP\"]\nX_train, X_test, y_train, y_test = train_test_split(X, y)\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train)\n\n# Simple model with early stopping\nmodel = XGBRegressor(n_estimators=10000, early_stopping_rounds=50, tree_method=\"hist\", random_state=42)\nmodel.fit(X_train, y_train, eval_set=[(X_val, y_val)], verbose=False)\n\n# Hyperparameter search (example)\nparam_dist = {\n    \"learning_rate\": [0.03, 0.05, 0.07],\n    \"max_depth\": [6, 8, 10],\n    \"min_child_weight\": [2, 3, 4],\n    \"subsample\": [0.8],\n    \"colsample_bytree\": [0.8],\n    \"reg_lambda\": [5, 10, 15],\n    \"reg_alpha\": [0, 0.05],\n    \"gamma\": [0, 0.05],\n}\nsearch = RandomizedSearchCV(\n    XGBRegressor(n_estimators=1000, tree_method=\"hist\", random_state=42),\n    param_distributions=param_dist,\n    n_iter=10,\n    cv=3,\n    scoring=\"r2\",\n    n_jobs=-1,\n    random_state=42\n)\nsearch.fit(X_train, y_train)\n\n# Final model with early stopping\nbest = XGBRegressor(**search.best_params_, n_estimators=10000, tree_method=\"hist\", random_state=42)\nbest.fit(X_train, y_train, eval_set=[(X_val, y_val)], early_stopping_rounds=50, verbose=False)\n```\n\n---\n\n## Quick Reference Table\n\n| Parameter Type         | Grid Type                | Example                                      |\n|------------------------|--------------------------|----------------------------------------------|\n| Continuous             | `scipy.stats.uniform`    | `\"learning_rate\": scipy.stats.uniform(0.01, 0.2)` |\n| Integer/Discrete       | `np.arange`/list         | `\"max_depth\": [4, 6, 8]`                     |\n\n---\n\n## Notes\n\n- For GPP regression, use `reg:squarederror` and `rmse`/`r2` metrics.\n- Never use the test set for early stopping or hyperparameter search.\n- Use DART only if gbtree overfits.\n- Save models in `.bin` for deployment, `.json` for sharing/debugging.\n\n---\n```# XGBoost Quick Reference (Regression \u0026 Classification)\n\n## Overview\n\nXGBoost is a fast, regularized gradient boosting library for tabular data. It supports regression, classification, and ranking tasks, with strong performance and flexible tuning.\n\n---\n\n## XGBRegressor vs XGBClassifier\n\n| Feature         | XGBRegressor                        | XGBClassifier                       |\n|-----------------|-------------------------------------|-------------------------------------|\n| Task            | Regression (predict continuous)     | Classification (predict classes)    |\n| Objective       | `\"reg:squarederror\"` (default)      | `\"binary:logistic\"`, `\"multi:softmax\"`, etc. |\n| Metrics         | `\"rmse\"`, `\"mae\"`, `\"r2\"`           | `\"logloss\"`, `\"error\"`, `\"auc\"`, etc. |\n| Target values   | Real numbers                        | Class labels (int or str)           |\n| Example use     | Predict GPP, house prices, etc.     | Predict species, churn, etc.        |\n\n---\n\n## Core Parameters\n\n- `n_estimators`: Max number of boosting rounds. Set high, use early stopping.\n- `learning_rate`: Step size shrinkage. Lower = more trees, less overfit. (0.01–0.1 typical)\n- `booster`: `\"gbtree\"` (default), `\"dart\"` (dropout), `\"gblinear\"` (linear).\n- `max_depth`: Tree depth (4–10 typical).\n- `min_child_weight`: Min sum Hessian in a leaf (1–10).\n- `subsample`: Row sampling per tree (0.6–1.0).\n- `colsample_bytree`: Feature sampling per tree (0.6–1.0).\n- `reg_alpha`/`reg_lambda`: L1/L2 regularization.\n- `gamma`: Min loss reduction to split.\n- `tree_method`: `\"hist\"` (fast CPU), `\"gpu_hist\"` (GPU).\n- `random_state`: For reproducibility.\n- `n_jobs`: Parallel threads.\n\n### DART-specific\n- `rate_drop`, `skip_drop`, `one_drop`: Dropout regularization for trees.\n\n---\n\n## Best Practices for Regression (fit for GPP/data.csv)\n\n1. **Data Prep**: Drop nulls, split into train/val/test.\n2. **Start Simple**: Use `gbtree` with `\"hist\"` and early stopping.\n3. **Tune**: Focus on `max_depth`, `min_child_weight`, `learning_rate`, `subsample`, `colsample_bytree`, `reg_alpha`, `reg_lambda`.\n4. **Early Stopping**: Set `n_estimators` high (e.g., 10000), use `early_stopping_rounds` with a validation set.\n5. **RandomizedSearchCV**: Use for hyperparameter search. Use `scipy.stats.uniform` for continuous params, lists for discrete.\n6. **DART**: Try if overfitting persists. Only tune DART-specific params after core tree params.\n7. **Final Model**: Retrain with best params and early stopping on full train+val, test on untouched test set.\n\n---\n\n## Hyperparameter Tuning Tips\n\n- **Continuous params**: Use `scipy.stats.uniform` (e.g., `\"learning_rate\": scipy.stats.uniform(0.01, 0.2)`).\n- **Discrete/integer params**: Use `np.arange`, `np.linspace`, or lists (e.g., `\"max_depth\": [4, 6, 8]`).\n- **Reduce search time**: Limit parameter ranges, use fewer `n_iter`, and lower `n_estimators` during search.\n- **Early stopping**: Only use in final `.fit()`, not during CV search.\n\n---\n\n## Model Saving\n\n- `.bin`: Fastest, smallest, best for production (XGBoost only).\n- `.json`: Human-readable, cross-language, good for debugging.\n- `.txt`: Most readable, not lossless, for inspection/education.\n\n---\n\n## Regularization\n\n- **L1 (`reg_alpha`)**: Drives weights to zero (feature selection).\n- **L2 (`reg_lambda`)**: Smooths weights (reduces variance).\n- **Tree structure**: Lower `max_depth`, higher `min_child_weight`, higher `gamma` = more regularization.\n- **Stochasticity**: Lower `subsample`/`colsample_bytree` = more regularization.\n- **DART**: Adds dropout to trees for extra regularization.\n\n---\n\n## Example: Regression Workflow (matches `main.ipynb`)\n\n```python\nfrom xgboost import XGBRegressor\nfrom sklearn.model_selection import train_test_split, RandomizedSearchCV\n\n# Data prep\ndf = pd.read_csv(\"data.csv\").dropna()\nX = df.drop(columns=[\"GPP\"])\ny = df[\"GPP\"]\nX_train, X_test, y_train, y_test = train_test_split(X, y)\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train)\n\n# Simple model with early stopping\nmodel = XGBRegressor(n_estimators=10000, early_stopping_rounds=50, tree_method=\"hist\", random_state=42)\nmodel.fit(X_train, y_train, eval_set=[(X_val, y_val)], verbose=False)\n\n# Hyperparameter search (example)\nparam_dist = {\n    \"learning_rate\": [0.03, 0.05, 0.07],\n    \"max_depth\": [6, 8, 10],\n    \"min_child_weight\": [2, 3, 4],\n    \"subsample\": [0.8],\n    \"colsample_bytree\": [0.8],\n    \"reg_lambda\": [5, 10, 15],\n    \"reg_alpha\": [0, 0.05],\n    \"gamma\": [0, 0.05],\n}\nsearch = RandomizedSearchCV(\n    XGBRegressor(n_estimators=1000, tree_method=\"hist\", random_state=42),\n    param_distributions=param_dist,\n    n_iter=10,\n    cv=3,\n    scoring=\"r2\",\n    n_jobs=-1,\n    random_state=42\n)\nsearch.fit(X_train, y_train)\n\n# Final model with early stopping\nbest = XGBRegressor(**search.best_params_, n_estimators=10000, tree_method=\"hist\", random_state=42)\nbest.fit(X_train, y_train, eval_set=[(X_val, y_val)], early_stopping_rounds=50, verbose=False)\n```\n\n---\n\n## Quick Reference Table\n\n| Parameter Type         | Grid Type                | Example                                      |\n|------------------------|--------------------------|----------------------------------------------|\n| Continuous             | `scipy.stats.uniform`    | `\"learning_rate\": scipy.stats.uniform(0.01, 0.2)` |\n| Integer/Discrete       | `np.arange`/`np.nplist`         | `\"max_depth\": [4, 6, 8]`                     |\n\n---\n\n## Notes\n\n- For GPP regression, use `reg:squarederror` and `rmse`/`r2` metrics.\n- Never use the test set for early stopping or hyperparameter search.\n- Use DART only if gbtree overfits.\n- Save models in `.bin` for deployment,","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderuni%2Fgpp-xgboost-regression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderuni%2Fgpp-xgboost-regression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderuni%2Fgpp-xgboost-regression/lists"}