<jupyter_start><jupyter_text>AZP algorithm<jupyter_code>import warnings
warnings.filterwarnings('ignore')
import sys
sys.path.append("../")
import spopt
import numpy as np
import libpysal
import geopandas as gpd
from spopt.region import AZP<jupyter_output><empty_output><jupyter_text>Mexican State Regional Income ClusteringCluster 32 Mexican states into 8 regions using AZP algorithm (Openshaw, S. and Rao, L. (1995)).<jupyter_code>pth = libpysal.examples.get_path('mexicojoin.shp')

mexico = gpd.read_file(pth)

mexico.plot(column='AREA', figsize=(12,8), edgecolor='w')
attrs_name = [f'PCGDP{year}' for year in range(1950,2010, 10)]
w = libpysal.weights.Queen.from_dataframe(mexico)
n_clusters = 8
allow_move_strategy = None
random_state = 12345
model = AZP(mexico, w, attrs_name, n_clusters, allow_move_strategy, random_state)
model.solve()
mexico['azp_new'] = model.labels_
mexico.plot(column='azp_new', categorical=True, figsize=(12,8), edgecolor='w')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12474645030425964, 'fraction_numerical': 0.029411764705882353, 'mean_word_length': 8.055045871559633, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '50927', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 404, 'n_tokens_neox': 372, 'n_words': 77, 'path': 'docs/notebooks/azp.ipynb', 'repo_name': 'gis-ops/spopt', 'size': '986'}