Skip to content

Added pooled scoring and robust aggregation#97

Closed
jigyasaba wants to merge 4 commits into
pysal:mainfrom
jigyasaba:alias_of_pooled_score
Closed

Added pooled scoring and robust aggregation#97
jigyasaba wants to merge 4 commits into
pysal:mainfrom
jigyasaba:alias_of_pooled_score

Conversation

@jigyasaba

@jigyasaba jigyasaba commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

** Summary:**

This PR resolves the existing TODO regarding score_ by exposing a pooled global metric for both GWLogisticRegression and GWLinearRegression.

Motivation:
While local models were fitted correctly in the base classes, a global summary metric consistent with the scikit-learn API (score_) was not explicitly provided.

Geographically Weighted (GW) models produce location-specific results, but users expect an overall performance summary comparable to standard sklearn estimators. This PR introduces a pooled metric based on focal predictions.

Implementation:

GWLogisticRegression

  • score_ defined as pooled mean accuracy of focal predictions.
  • NaN focal predictions are masked to avoid invalid aggregation.
  • Added safeguards when concatenating pooled arrays to prevent shape issues when local models are skipped.

GWLinearRegression

  • score_ defined as pooled R² computed from focal predictions.
  • Guard added for division-by-zero when total variance (ss_tot) equals zero.
    The design uses focal predictions rather than weighted aggregation, ensuring consistency with the interpretation of GW estimators as a spatial ensemble of local models.

Impact:

  • No API-breaking changes.
  • Backward compatible.
  • Aligns GW estimators more closely with sklearn estimator conventions.
  • Improves stability when some neighborhoods are skipped due to invariance or min_proportion.

All existing tests pass locally.
Open to feedback and suggestions.

@codecov

codecov Bot commented Feb 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.95%. Comparing base (9b62eef) to head (f0a5df8).

Files with missing lines Patch % Lines
gwlearn/linear_model.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #97      +/-   ##
==========================================
- Coverage   92.96%   92.95%   -0.02%     
==========================================
  Files           6        6              
  Lines         825      837      +12     
==========================================
+ Hits          767      778      +11     
- Misses         58       59       +1     

☔ 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.

@jigyasaba jigyasaba force-pushed the alias_of_pooled_score branch from a4d2cb1 to 7cb1172 Compare February 27, 2026 03:37
@jigyasaba jigyasaba changed the title aliasing done Added pooled scoring and robust aggregation Feb 27, 2026
@jigyasaba jigyasaba force-pushed the alias_of_pooled_score branch from 7cb1172 to e7fa4eb Compare February 27, 2026 04:05
@martinfleis

Copy link
Copy Markdown
Member

Duplicate of #76. Also, see the discussion in there.

@jigyasaba jigyasaba deleted the alias_of_pooled_score branch February 27, 2026 15:06
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.

2 participants