gwlearn.search.BandwidthSearch

gwlearn.search.BandwidthSearch#

class gwlearn.search.BandwidthSearch(model, *, fixed=False, kernel='bisquare', geometry=None, n_jobs=-1, search_method='golden_section', criterion='aicc', metrics=None, minimize=True, min_bandwidth=None, max_bandwidth=None, interval=None, max_iterations=100, tolerance=0.01, verbose=False, **kwargs)[source]#

Optimal bandwidth search for geographically-weighted models

Reports information criteria and (optionally) other scores from multiple models with varying bandwidth. When using golden section search, minimizes one of AIC, AICc, BIC based on prediction probability on focal geometries.

When using classification models with a defined min_proportion, keep in mind that some locations may be excluded from the final model. In such a case, the information criteria are typically not comparable across models with different bandwidths and shall not be used to determine the optimal one.

Parameters:
modelmodel class

Scikit-learn model class or compatible estimator.

fixedbool, optional

True for distance based bandwidth and False for adaptive (nearest neighbor) bandwidth, by default False

kernelstr | Callable, optional

Type of kernel function used to weight observations, by default "bisquare"

n_jobsint, optional

The number of jobs to run in parallel. -1 means using all processors, by default -1

search_method{“golden_section”, “interval”}, optional

Method used to search for optimal bandwidth. When using "golden_section", the Golden section optimization is used to find the optimal bandwidth while attempting to minimize or maximise criterion. When using "interval", fits all models within the specified bandwidths at a set interval without any attempt to optimize the selection. By default "golden_section".

criterionstr, optional

Vriterion used to select optimal bandwidth. Can be one of {"aicc", "aic", "bic"} or any of metrics. By default "aicc".

metricslist[str] | None, optional

List of additional metrics beyond criterion to be reported. Has to be a metric supported by model, passable to measure_performance argument of model’s initialization or ‘prediction_rate’. By default None.

minimizebool, optional

Minimize or maximize the criterion. When using information criterions, like AICc, the optimal solution is the lowest value. When using other metrics, the optimal may the the highest value. By default True, assuming lower is better.

min_bandwidthint | float | None, optional

Minimum bandwidth to consider, by default None

max_bandwidthint | float | None, optional

Maximum bandwidth to consider, by default None

intervalint | float | None, optional

Interval for bandwidth search when using “interval” method, by default None

max_iterationsint, optional

Maximum number of iterations for golden section search, by default 100

tolerancefloat, optional

Tolerance for convergence in golden section search, by default 1e-2

verbosebool | int, optional

Verbosity level, by default False

**kwargs

Additional keyword arguments passed to model initialization

Attributes:
scores_pd.Series

Series of criterion scores for each bandwidth tested (index is bandwidth).

metrics_pd.DataFrame

DataFrame of additional metrics for each bandwidth tested.

optimal_bandwidth_int | float

The optimal bandwidth found by the search method (minimizing or maximizingt the criterion).

__init__(model, *, fixed=False, kernel='bisquare', geometry=None, n_jobs=-1, search_method='golden_section', criterion='aicc', metrics=None, minimize=True, min_bandwidth=None, max_bandwidth=None, interval=None, max_iterations=100, tolerance=0.01, verbose=False, **kwargs)[source]#

Methods

__init__(model, *[, fixed, kernel, ...])

fit(X, y)

fit(X, y)[source]#