spopt.region.AZP¶
- class spopt.region.AZP(gdf, w, attrs_name, n_clusters=5, allow_move_strategy=None, random_state=None, initial_labels=None, objective_func=<spopt.region.objective_function.ObjectiveFunctionPairwise object>)[source]¶
AZP involves class offering the implementation of the automatic zoning procedure algorithm.
- Parameters:
- gdf
geopandas.GeoDataFrame Geodataframe containing original data.
- w
libpysal.weights.W Weights object created from given data.
- attrs_name
list Strings for attribute names (cols of
geopandas.GeoDataFrame).- n_clusters
int The number of clusters to form. Default is
5.- allow_move_strategy
NoneorAllowMoveStrategy For a different behavior for allowing moves an AllowMoveStrategy instance can be passed as argument. Default is
None.- random_state
None,int,str,bytes, orbytearray Random seed. Default is
None.- initial_labels
numpy.ndarrayorNone One-dimensional array of labels at the beginning of the algorithm. If
None, then a random initial clustering will be generated. Default isNone.- objective_func
spopt.region.objective_function.ObjectiveFunction The objective function to use. Default is
ObjectiveFunctionPairwise().
- gdf
- Attributes:
- labels_
numpy.ndarray Each element is a region label specifying to which region the corresponding area was assigned to by the last run of a fit-method.
- labels_
Examples
>>> import numpy as np >>> import libpysal >>> import geopandas as gpd >>> from spopt.region import AZP
Read the data.
>>> pth = libpysal.examples.get_path('mexicojoin.shp') >>> mexico = gpd.read_file(pth)
Initialize the parameters.
>>> attrs_name = [f'PCGDP{year}' for year in range(1950,2010, 10)] >>> w = libpysal.weights.Queen.from_dataframe(mexico) >>> n_clusters = 8 >>> floor = 3 >>> allow_move_strategy = None >>> random_state = 12345
Run the skater algorithm.
>>> model = AZP( ... mexico, w, attrs_name, n_clusters, allow_move_strategy, random_state ... ) >>> model.solve()
Get the region IDs for unit areas.
>>> model.labels_
Show the clustering results.
>>> mexico['azp_new'] = model.labels_ >>> mexico.plot(column='azp_new', categorical=True, figsize=(12,8), edgecolor='w')
- __init__(gdf, w, attrs_name, n_clusters=5, allow_move_strategy=None, random_state=None, initial_labels=None, objective_func=<spopt.region.objective_function.ObjectiveFunctionPairwise object>)[source]¶
Methods
__init__(gdf, w, attrs_name[, n_clusters, ...])solve()Solve the azp