gwlearn.linear_model.GWLinearRegression#
- class gwlearn.linear_model.GWLinearRegression(bandwidth=None, fixed=False, kernel='bisquare', include_focal=True, geometry=None, graph=None, n_jobs=-1, fit_global_model=True, measure_performance=True, keep_models=False, temp_folder=None, batch_size=None, **kwargs)[source]#
Geographically weighted linear regression
- Parameters:
- bandwidth
int|float Bandwidth value consisting of either a distance or N nearest neighbors
- fixedbool,
optional True for distance based bandwidth and False for adaptive (nearest neighbor) bandwidth, by default False
- kernel
str|Callable,optional Type of kernel function used to weight observations, by default “bisquare”
- include_focalbool,
optional Include focal in the local model training. Excluding it allows assessment of geographically weighted metrics on unseen data without a need for train/test split, hence providing value for all samples. This is needed for further spatial analysis of the model performance (and generalises to models that do not support OOB scoring). However, it leaves out the most representative sample. By default True
- geometry
gpd.GeoSeries,optional Geographic location of the observations in the sample. Used to determine the spatial interaction weight based on specification by
bandwidth,fixed,kernel, andinclude_focalkeywords. Eithergeometryorgraphneed to be specified. To allow prediction, it is required to specifygeometry.- graph
Graph,optional Custom libpysal.graph.Graph object encoding the spatial interaction between observations in the sample. If given, it is used directly and
bandwidth,fixed,kernel, andinclude_focalkeywords are ignored. Eithergeometryorgraphneed to be specified. To allow prediction, it is required to specifygeometry. Potentially, both can be specified wheregraphencodes spatial interaction between observations ingeometry.- n_jobs
int,optional The number of jobs to run in parallel.
-1means using all processors by default-1- fit_global_modelbool,
optional Determines if the global baseline model shall be fitted alongside the geographically weighted, by default True
- measure_performancebool,
optional Calculate performance metrics for the model. If True, measures accuracy score, precision, recall, balanced accuracy, and F1 scores (based on focal prediction, pooled local predictions and individual local predictions). By default True
- strictbool |
None,optional Do not fit any models if at least one neighborhood has invariant
y, by default False. None is treated as False but provides a warning if there are invariant models.- keep_modelsbool |
str|Path,optional Keep all local models (required for prediction), by default False. Note that for some models, like random forests, the objects can be large. If string or Path is provided, the local models are not held in memory but serialized to the disk from which they are loaded in prediction.
- temp_folder
str|None,optional Folder to be used by the pool for memmapping large arrays for sharing memory with worker processes, e.g.,
/tmp. Passed tojoblib.Parallel, by default None- batch_size
int|None,optional Number of models to process in each batch. Specify batch_size if your models do not fit into memory. By default None
- verbosebool,
optional Whether to print progress information, by default False
- **kwargs
Additional keyword arguments passed to
sklearn.linear_model.LinearRegressioninitialisation
- bandwidth
- Attributes:
- local_coef_
pd.DataFrame Local coefficient of the features in the decision function for each feature at each location
- local_intercept_
pd.Series Local intercept values at each location
- local_coef_
- __init__(bandwidth=None, fixed=False, kernel='bisquare', include_focal=True, geometry=None, graph=None, n_jobs=-1, fit_global_model=True, measure_performance=True, keep_models=False, temp_folder=None, batch_size=None, **kwargs)[source]#
Methods
__init__([bandwidth, fixed, kernel, ...])fit(X, y)Fit the geographically weighted model
get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
score(X, y[, sample_weight])Return coefficient of determination on test data.
set_fit_request(*[, geometry])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.- fit(X, y)[source]#
Fit the geographically weighted model
- Parameters:
- X
pd.DataFrame Independent variables
- y
pd.Series Dependent variable
- geometry
gpd.GeoSeries Geographic location
- X
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.