geosnap.analyze.regionalize¶
- geosnap.analyze.regionalize(gdf, n_clusters=6, spatial_weights='rook', method=None, columns=None, threshold_variable='count', threshold=10, temporal_index='year', unit_index='geoid', scaler='std', weights_kwargs=None, region_kwargs=None, model_colname=None, return_model=False)[source]¶
Create a spatial geodemographic typology by running a cluster analysis on the metro area’s neighborhood attributes and including a contiguity constraint.
- Parameters:
- gdf
geopandas.GeoDataFrame
long-form geodataframe holding neighborhood attribute and geometry data.
- n_clusters
int
the number of clusters to model. The default is 6).
- spatial_weights[‘queen’, ‘rook’] or
libpysal.weights.W
object
spatial weights matrix specification`. By default, geosnap will calculate Rook weights, but you can also pass a libpysal.weights.W object for more control over the specification.
- method
str
in
[‘ward_spatial’, ‘kmeans_spatial’, ‘spenc’, ‘skater’, ‘azp’, ‘max_p’] the clustering algorithm used to identify neighborhood types
- columnsarray_like
subset of columns on which to apply the clustering
- threshold_variable
str
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
threshold to use for max-p clustering (the default is 10).
- temporal_index
str
which column on the dataframe defines time and or sequencing of the long-form data. Default is “year”
- unit_index
str
which column on the long-form dataframe identifies the stable units over time. In a wide-form dataset, this would be the unique index
- weights_kwargs
dict
If passing a libpysal.weights.W instance to spatial_weights, these additional keyword arguments that will be passed to the weights constructor
- region_kwargs: dict
additional keyword arguments passed to the regionalization algorithm
- scaler
None
orscaler
class
fromsklearn.preprocessing
a scikit-learn preprocessing class that will be used to rescale the data. Defaults to sklearn.preprocessing.StandardScaler
- model_colname
str
column name for storing cluster labels on the output dataframe. If no name is provided, the colun will be named after the clustering method. If there is already a column named after the clustering method, the name will be incremented with a number
- return_model: bool
If True, also retun a dictional of fitted classes from the regionalization provider
- gdf
- Returns:
- gdf
geopandas.GeoDataFrame
GeoDataFrame with a column of neighborhood cluster labels appended as a new column. If cluster method exists as a column on the DataFrame then the column will be incremented.
- models
dict
ofnamed
tuples
(only
returned
if return_modelis
True
) tab-completable dictionary of named tuples keyed on the Community’s time variable (e.g. year). The tuples store model results and have attributes X, columns, labels, instance, W, which store the input matrix, column labels, fitted model instance, and spatial weights matrix
- gdf