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_clustersint, required

the number of clusters to model. The default is 6).

spatial_weightsstr (‘queen’ or ‘rook’) or libpysal.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_kwargsdict, optional

If passing a libpysal.weights.W instance to spatial_weights, these additional keyword arguments that will be passed to the weights constructor

methodstr 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_variablestr, 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

thresholdnumeric, optional

threshold to use for max-p clustering (the default is 10).

scalerNone or scaler from sklearn.preprocessing, optional

a scikit-learn preprocessing class that will be used to rescale the data. Defaults to sklearn.preprocessing.StandardScaler

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