# 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>)

  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 `python:list`

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

    n_clusters `python:int`

      The number of clusters to form. Default is `5`.

    allow_move_strategy `python:None` or `AllowMoveStrategy`

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

    random_state `python:None`, `python:int`, `python:str`, `bytes`, or `bytearray`

      Random seed. Default is `None`.

    initial_labels `numpy.ndarray` or `python: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_func `spopt.region.objective_function.ObjectiveFunction`

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

  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.

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

  Methods

  `__init__`(gdf, w, attrs_name[, n_clusters, ...]) |
  `solve`() | Solve the azp

  solve()

    Solve the azp