geosnap.Community.cluster_spatial¶
-
Community.
cluster_spatial
(self, n_clusters=6, spatial_weights='rook', method=None, best_model=False, columns=None, threshold_variable='count', threshold=10, return_model=False, scaler=None, weights_kwargs=None, **kwargs)[source]¶ Create a spatial geodemographic typology by running a cluster analysis on the metro area’s neighborhood attributes and including a contiguity constraint.
- Parameters
- n_clusters
int
, required the number of clusters to model. The default is 6).
- spatial_weights
str
(‘queen’ or ‘rook’) orlibpysal.weights.W
instance, optional spatial weights matrix specification` (the default is “rook”). If ‘rook’ or ‘queen’ then contiguity weights will be constructed internally, otherwise pass a libpysal.weights.W with additional arguments specified in weights_kwargs
- weights_kwargs
dict
, optional If passing a libpysal.weights.W instance to spatial_weights, these additional keyword arguments that will be passed to the weights constructor
- method
str
in
[‘ward_spatial’, ‘spenc’, ‘skater’, ‘azp’, ‘max_p’], required the clustering algorithm used to identify neighborhood types
- columnsarray_like, required
subset of columns on which to apply the clustering
- threshold_variable
str
, required if using max-p, optional otherwise for max-p, which variable should define p. The default is “count”, which will grow regions until the threshold number of polygons have been aggregated
- threshold
numeric
, optional threshold to use for max-p clustering (the default is 10).
- scaler
None
orscaler
fromsklearn.preprocessing
, optional a scikit-learn preprocessing class that will be used to rescale the data. Defaults to sklearn.preprocessing.StandardScaler
- n_clusters
- Returns
geosnap.Community
a copy of input Community with neighborhood cluster labels appended as a new column. If the cluster is already present, the name will be incremented