Skip to content

Add examples for GWLinearRegression and GWLogisticRegression#87

Open
aman-coder03 wants to merge 4 commits intopysal:mainfrom
aman-coder03:add-gw-examples
Open

Add examples for GWLinearRegression and GWLogisticRegression#87
aman-coder03 wants to merge 4 commits intopysal:mainfrom
aman-coder03:add-gw-examples

Conversation

@aman-coder03
Copy link
Copy Markdown

@aman-coder03 aman-coder03 commented Feb 19, 2026

Summary

Closes #85

This PR adds two new example notebooks to the User Guide demonstrating complete workflows for GWLinearRegression and GWLogisticRegression.

Changes

  • docs/source/gw_linear_regression_example.ipynb - new example notebook
  • docs/source/gw_logistic_regression_example.ipynb - new example notebook
  • docs/source/index.md - added both notebooks to the User Guide toctree

What the examples cover

GWLinearRegression example:

  • Real-world dataset: US per-capita income by state, 1929-2009 (libpysal us_income)
  • Research question: does the income convergence effect vary spatially across US states?
  • Global OLS baseline for comparison
  • Spatially varying coefficients (local_coef_) mapped and interpreted by region
  • Local R² (local_r2_) and residual (resid_) analysis

GWLogisticRegression example:

  • Creating a binary target from a continuous variable
  • Fitting the model and checking prediction_rate_
  • Focal accuracy and pooled metrics (y_pooled_, pred_pooled_)
  • Per-model metrics via local_metric
  • Mapping local log-odds coefficients (local_coef_)

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.01%. Comparing base (5b8382d) to head (aed1f6d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   91.36%   92.01%   +0.65%     
==========================================
  Files           6        6              
  Lines         799      814      +15     
==========================================
+ Hits          730      749      +19     
+ Misses         69       65       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martinfleis
Copy link
Copy Markdown
Member

I was anticipating something else. This is mirroring what is already in the user guide, just reshuffled. I was more hoping for an example on how to use gwlearn on a real-world case, something like we have in momepy. This still uses the default example dataset and does not add anything on top of what the documentation already covers.

@aman-coder03
Copy link
Copy Markdown
Author

Thank you for the feedback @martinfleis
Could you point me toward the kind of real-world dataset and question you had in mind? For example,
A publicly available spatial dataset(from census, OpenStreetMap, or maybe a PySAL dataset)
A meaningful research question(predicting house prices, exploring income inequality spatially)
This would help me write an example that demonstrates gwlearn solving a genuine analytical problem rather than repeating the tutorial dataset

@martinfleis
Copy link
Copy Markdown
Member

No. If you want to contribute an example I would expect it comes from you. It takes time to come up with a good example, I don't know what is going to work well.

@aman-coder03
Copy link
Copy Markdown
Author

@martinfleis i have replaced the linear regression example with a real world case study using US state income data(1929-2009) investigating the income convergence hypothesis. I will work on coming up with a similarly meaningful real world case for the logistic regression example as well

@aman-coder03
Copy link
Copy Markdown
Author

I explored the Tokyo mortality dataset from libpysal - 262 municipalities with socioeconomic variables(unemployment, home ownership, elderly population, technical occupations) and observed vs expected deaths for ages 25-64. I am planning to use it to classify municipalities as high/low mortality(observed > expected, 40/60 split) and examine whether the socioeconomic predictors of high mortality risk vary spatially across the city

@aman-coder03
Copy link
Copy Markdown
Author

@martinfleis can you please have a look and suggest changes if needed?

@martinfleis
Copy link
Copy Markdown
Member

The fact that I haven't responded two days, which also happened to be a weekend made you think it is fine to remind me?

@aman-coder03
Copy link
Copy Markdown
Author

you are right, I apologize. I should have waited longer before pinging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOC] Add user guide and example for GWLinearRegression and GWLogisticRegression

2 participants