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:
gdfgeopandas.GeoDataFrame

Geodataframe containing original data.

wlibpysal.weights.W

Weights object created from given data.

attrs_namelist

Strings for attribute names (cols of geopandas.GeoDataFrame).

n_clustersint

The number of clusters to form. Default is 5.

allow_move_strategyNone or AllowMoveStrategy

For a different behavior for allowing moves an AllowMoveStrategy instance can be passed as argument. Default is None.

random_stateNone, int, str, bytes, or bytearray

Random seed. Default is None.

initial_labelsnumpy.ndarray or None

One-dimensional array of labels at the beginning of the algorithm. If None, then a random initial clustering will be generated. Default is None.

objective_funcspopt.region.objective_function.ObjectiveFunction

The objective function to use. Default is ObjectiveFunctionPairwise().

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')
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.

__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

solve()[source]

Solve the azp