gwlearn

An agnostic framework for geographically weighted learning

Martin Fleischmann

Charles University

Spatial non-stationarity is hard.

A common solution?

Geographically Weighted Regression

What about non-linear models?

Most ML implementations are aspatial.

Most spatial models remain linear.

ad-hoc “localising” of specific algorithms

*stolen from Urska Demsar

*stolen from Urska Demsar

“the (not any longer) reproducible code
lives in this (forgotten) repository”

There is no unified framework that
generalises “Geographically Weighted” logic.

gwlearn

An agnostic framework for geographically weighted learning. Written in Python.

agnostic

neighbourhood definition

local estimator

Flexible Definitions of Neighbourhoods

Traditionally defined by Euclidean distance.

Fixed or adaptive (KNN) bandwidth.

What about other ways?

gwlearn allows custom graphs.

network travel time

space-time neighbourhoods

topology of polygon contiguity

Custom local estimator

Typically OLS.

Occasionally something fancier.

gwlearn supports any estimator.

Formally

\[ \hat{\theta}(u_i) = \operatorname*{argmin}_{\theta} \sum_{j=1}^{N} w_{ij}(u_i) \cdot \mathcal{L}\Big(y_j, f(X_j, \theta)\Big) \]

  • \(\hat{\theta}(u_i)\) model parameters specific to location \(u_i\),
  • \(w_{ij}(u_i)\) spatial weights of data point \(j\) relative to location \((u_i)\),
  • ​​\(\mathcal{L}\) the loss function of the model,
  • \(f(X_j, \theta)\) the base estimator’s prediction function.

linear regression

random forest regressor

gradient boosted classifier

gwlearn architecture

modularity

interoperability

flexibility

Spatial weights graphs

Defined in libpysal.graph.Graph created prior model fitting.

scikit-learn compatibility

Any model with scikit-learn compatible API can be used.

gwlearn’s estimators define scikit-learn compatible API.

Spatial prediction

Training set of local models is as a reusable spatial ensemble.

Three inference strategies:

  • Nearest Local Mode
  • Spatial Ensemble
  • Global Model Fusion

Example

Housing price in Busan.

An, S., Jang, H., Kim, H. et al. Assessment of street-level greenness and its association with housing prices in a metropolitan area. Sci Rep 13, 22577 (2023). https://doi.org/10.1038/s41598-023-49845-0

Case 1 - models

bandwidth search across models

Case 2 - graphs

linear regression

difference in local \(R^2\) between Euclidean and network graphs

Case 3 - predictions

OOS prediction using gradient boosted regressor

gwlearn provides the infrastructure

computation remains a bottleneck

gwlearn provides the missing link
between the rich tradition of GWR
and the modern machine learning
ecosystem.

pysal.org/gwlearn

Do you want to follow up

pysal.org/gwlearn

github.com/pysal/gwlearn

uscuni.org/talks

martin.fleischmann@natur.cuni.cz

martinfleischmann.net