MixedGWR¶
This page documents 1 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
MixedGWR¶
Fit a semiparametric GWR with global and local coefficients.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.models import MixedGWR |
| Signature | MixedGWR(kernel: 'Union[str, Callable]' = 'bisquare', bandwidth: 'Union[float, int, str, None]' = 'aicc', bandwidth_method: 'str' = 'aicc', adaptive: 'bool' = True, local_vars: 'VariableSpec' = None, global_vars: 'VariableSpec' = None, intercept_fixed: 'bool' = True, ridge: 'float' = 0.0, fit_intercept: 'bool' = True, bandwidth_range: 'Optional[tuple[float, float]]' = None, optimization_method: 'str' = 'golden_section', distance_metric: 'str' = 'euclidean', verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/models/08_mixed_gwr.py |
MixedGWR ¶
MixedGWR(
kernel: Union[str, Callable] = "bisquare",
bandwidth: Union[float, int, str, None] = "aicc",
bandwidth_method: str = "aicc",
adaptive: bool = True,
local_vars: VariableSpec = None,
global_vars: VariableSpec = None,
intercept_fixed: bool = True,
ridge: float = 0.0,
fit_intercept: bool = True,
bandwidth_range: Optional[tuple[float, float]] = None,
optimization_method: str = "golden_section",
distance_metric: str = "euclidean",
verbose: bool = False,
)
Bases: BaseSpatialRegressor
Fit a semiparametric GWR with global and local coefficients.
Mixed GWR partitions explanatory variables into globally constant and
geographically varying groups. The implementation follows the partial-
regression algorithm used by GWmodel::gwr.mixed rather than an
iterative backfitting algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Union[str, Callable]
|
Spatial kernel name or callable. |
'bisquare'
|
bandwidth
|
Union[float, int, str, None]
|
Fixed distance, adaptive neighbour count, or one of
|
'aicc'
|
bandwidth_method
|
str
|
Selection method used when |
'aicc'
|
adaptive
|
bool
|
Whether numeric bandwidth is a neighbour count. |
True
|
local_vars
|
VariableSpec
|
Feature indices or DataFrame column names with local
coefficients. If omitted with |
None
|
global_vars
|
VariableSpec
|
Feature indices or names with global coefficients. If only one variable group is supplied, the other is its complement. |
None
|
intercept_fixed
|
bool
|
Whether the fitted intercept is global. If false, the intercept varies locally. |
True
|
ridge
|
float
|
Non-negative regularization applied explicitly to local and global
normal equations. The default |
0.0
|
fit_intercept
|
bool
|
Whether to fit an intercept. |
True
|
bandwidth_range
|
Optional[tuple[float, float]]
|
Optional search range for automatic bandwidth selection. |
None
|
optimization_method
|
str
|
Bandwidth optimizer passed to the shared selector. |
'golden_section'
|
distance_metric
|
str
|
Distance metric used by the shared distance utility. |
'euclidean'
|
verbose
|
bool
|
Whether to print fit progress. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
coef_local_ |
Local coefficients with shape |
|
coef_global_ |
Constant coefficients for the global feature variables. |
|
intercept_ |
Scalar global intercept or a vector of local intercepts. |
|
coef_ |
Full coefficient surface in original feature order. |
|
enp_ |
Effective parameter count |
References
Fotheringham, A. S., Brunsdon, C., & Charlton, M. (2002). Geographically Weighted Regression. Wiley.
Source code in src/pygwrx/models/mixed_gwr.py
fit ¶
fit(
X: Union[ndarray, DataFrame],
y: Union[ndarray, Series],
coords: Union[ndarray, DataFrame],
compute_enp: bool = True,
) -> "MixedGWR"
Fit the mixed global/local coefficient model.
Source code in src/pygwrx/models/mixed_gwr.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
predict ¶
Predict at new locations without modifying fitted training state.
Source code in src/pygwrx/models/mixed_gwr.py
test_spatial_variation ¶
Return descriptive variation of fitted local coefficients.
This method is descriptive and is not a formal hypothesis test.
Source code in src/pygwrx/models/mixed_gwr.py
Runnable examples used on this page¶
examples/models/08_mixed_gwr.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Fit a semiparametric Mixed GWR with global and local predictors."""
# 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 mixed_regression, print_model_result
from pygwrx import MixedGWR
X, y, coords = mixed_regression()
model = MixedGWR(
bandwidth=28,
adaptive=True,
global_vars=["global_x"],
local_vars=["local_x"],
intercept_fixed=True,
).fit(X, y, coords, compute_enp=False)
print_model_result(model)
print("global_coefficients=", model.coef_global_)
print("predictions=", model.predict(X.iloc[:3], coords.iloc[:3]))