SGWR¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
SGWR¶
Similarity and geographically weighted regression.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.models import SGWR |
| Signature | SGWR(bandwidth: 'Bandwidth' = 'aicc', adaptive: 'bool' = True, kernel: 'str' = 'bisquare', alpha: 'Alpha' = 'aicc', similarity_vars: 'Optional[Sequence[Union[int, str]]]' = None, *, standardize_similarity: 'bool' = True, bandwidth_kernel: 'Optional[str]' = None, bandwidth_range: 'Optional[Tuple[float, float]]' = None, alpha_range: 'Tuple[float, float]' = (0.01, 1.0), alpha_grid_size: 'int' = 21, fit_intercept: 'bool' = True, distance_metric: 'str' = 'euclidean', sigma2_v1: 'bool' = True, ridge: 'float' = 0.0, store_weights: 'bool' = True, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/models/15_sgwr.py |
SGWR ¶
SGWR(
bandwidth: Bandwidth = "aicc",
adaptive: bool = True,
kernel: str = "bisquare",
alpha: Alpha = "aicc",
similarity_vars: Optional[
Sequence[Union[int, str]]
] = None,
*,
standardize_similarity: bool = True,
bandwidth_kernel: Optional[str] = None,
bandwidth_range: Optional[Tuple[float, float]] = None,
alpha_range: Tuple[float, float] = (0.01, 1.0),
alpha_grid_size: int = 21,
fit_intercept: bool = True,
distance_metric: str = "euclidean",
sigma2_v1: bool = True,
ridge: float = 0.0,
store_weights: bool = True,
verbose: bool = False
)
Similarity and geographically weighted regression.
For calibration location :math:i, SGWR constructs
.. math::
W_i^{GS} = \alpha W_i^G + (1 - \alpha) W_i^S,
where :math:W_i^G is a geographic kernel and the published similarity
kernel is
.. math::
w_{ij}^S = \exp\left[-\left(\frac{1}{m}
\sum_{r=1}^{m}|z_{ir}-z_{jr}|\right)^2\right].
The similarity variables z are standardized using the training-sample
mean and population standard deviation before distances are calculated.
alpha=1 is ordinary GWR and alpha=0 is similarity-only local
regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
Bandwidth
|
Geographic bandwidth. Numeric values are used directly.
|
'aicc'
|
adaptive
|
bool
|
Interpret a numeric bandwidth as a one-based neighbour count. |
True
|
kernel
|
str
|
Geographic kernel used in the final SGWR fit. |
'bisquare'
|
alpha
|
Alpha
|
Geographic mixing proportion. Numeric values lie in |
'aicc'
|
similarity_vars
|
Optional[Sequence[Union[int, str]]]
|
Predictor names or zero-based column indices used to
construct attribute similarity. |
None
|
standardize_similarity
|
bool
|
Standardize similarity variables before the published mean-absolute-distance calculation. |
True
|
bandwidth_kernel
|
Optional[str]
|
Optional kernel used only for automatic pure-GWR bandwidth selection. This permits the software-paper hybrid of an adaptive bi-square search followed by an adaptive Gaussian SGWR fit. |
None
|
bandwidth_range
|
Optional[Tuple[float, float]]
|
Optional search bounds passed to the standard GWR bandwidth selector. |
None
|
alpha_range
|
Tuple[float, float]
|
Bounds used for automatic alpha selection. |
(0.01, 1.0)
|
alpha_grid_size
|
int
|
Number of deterministic coarse alpha candidates before bounded local refinement. |
21
|
fit_intercept
|
bool
|
Include a local intercept. |
True
|
distance_metric
|
str
|
Coordinate distance metric used by pyGWRx. |
'euclidean'
|
sigma2_v1
|
bool
|
Residual variance convention. |
True
|
ridge
|
float
|
Optional non-negative numerical ridge added to slope diagonals. The intercept is not penalized. |
0.0
|
store_weights
|
bool
|
Store the three |
True
|
verbose
|
bool
|
Print selection and fit progress. |
False
|
References
Lessani, M. N., & Li, Z. (2024). SGWR: similarity and geographically weighted regression. International Journal of Geographical Information Science, 38(7), 1232-1255.
Lessani, M. N., & Li, Z. (2025). Enhancing the computational efficiency of the SGWR model and introducing its software implementation. Annals of GIS.
Source code in src/pygwrx/models/sgwr.py
fit ¶
fit(
X: Union[ndarray, DataFrame],
y: Union[ndarray, Series],
coords: Union[ndarray, DataFrame],
) -> "SGWR"
Fit Gaussian SGWR at the observed locations.
Source code in src/pygwrx/models/sgwr.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |
predict_result ¶
predict_result(
X: Union[ndarray, DataFrame],
coords: Union[ndarray, DataFrame],
) -> SGWRPredictionResult
Recalibrate SGWR at new locations and return local parameters.
Source code in src/pygwrx/models/sgwr.py
predict ¶
Predict at new locations using direct SGWR recalibration.
results_frame ¶
Return training-location parameters, inference, and fitted values.
Source code in src/pygwrx/models/sgwr.py
summary ¶
Return a plain-text SGWR configuration and diagnostics table.
Source code in src/pygwrx/models/sgwr.py
Runnable examples used on this page¶
examples/models/15_sgwr.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Fit similarity and geographically weighted regression."""
# Allow this script to run directly from any working directory.
import sys
from pathlib import Path
_PROJECT_ROOT = Path(__file__).resolve().parents[2]
_EXAMPLES_ROOT = _PROJECT_ROOT / "examples"
_SRC_ROOT = _PROJECT_ROOT / "src"
for _path in (_SRC_ROOT, _EXAMPLES_ROOT):
if str(_path) not in sys.path:
sys.path.insert(0, str(_path))
from _common import print_model_result, spatial_regression
from pygwrx import SGWR
X, y, coords = spatial_regression(n=48, p=3)
model = SGWR(
bandwidth=24,
adaptive=True,
alpha=0.45,
similarity_vars=["x1", "x2"],
store_weights=True,
).fit(X, y, coords)
print_model_result(model)
print("combined_weights_shape=", model.combined_weights_.shape)
print("predictions=", model.predict(X.iloc[:3], coords.iloc[:3]))