<jupyter_start><jupyter_text>Introduction to mapclassify`mapclassify` implements a family of classification schemes for choropleth maps. Its focus is on the determination of the number of classes, and the assignment of observations to those classes.It is intended for use with upstream mapping and geovisualization packages (see [geopandas](https://geopandas.org/mapping.html) and [geoplot](https://residentmario.github.io/geoplot/user_guide/Customizing_Plots.html) for examples) that handle the rendering of the maps.In this notebook, the basic functionality of mapclassify is presented.<jupyter_code>import mapclassify as mc
mc.__version__<jupyter_output><empty_output><jupyter_text>Example datamapclassify contains a built-in dataset for employment density for the 58 California counties.<jupyter_code>y = mc.load_example()<jupyter_output><empty_output><jupyter_text>Basic FunctionalityAll classifiers in `mapclassify` have a common interface and afford similar functionality. We illustrate these using the `MaximumBreaks` classifier.`MaximumBreaks` requires that the user specify the number of classes `k`. Given this, the logic of the classifier is to sort the observations in ascending order and find the difference between rank adjacent values. The class boundaries are defined as the $k-1$ largest rank-adjacent breaks in the sorted values.<jupyter_code>mc.MaximumBreaks(y, k=4)<jupyter_output><empty_output><jupyter_text>The classifier returns an instance of `MaximumBreaks` that reports the resulting intervals and counts. The first class has closed lower and upper bounds: `[   0.13,  228.49]`, with `0.13` being the minimum value in the dataset:<jupyter_code>y.min()<jupyter_output><empty_output><jupyter_text>Subsequent intervals are open on the lower bound and closed on the upper bound. The fourth class has the maximum value as its closed upper bound:<jupyter_code>y.max()<jupyter_output><empty_output><jupyter_text>Assigning the classifier to an object let's us inspect other aspects of the classifier:<jupyter_code>mb4 = mc.MaximumBreaks(y, k=4)
mb4<jupyter_output><empty_output><jupyter_text>The `bins` attribute has the upper bounds of the intervals:<jupyter_code>mb4.bins<jupyter_output><empty_output><jupyter_text>and `counts` reports the number of values falling in each bin:<jupyter_code>mb4.counts<jupyter_output><empty_output><jupyter_text>The specific bin (i.e. label) for each observation can be found in the `yb` attribute:<jupyter_code>mb4.yb<jupyter_output><empty_output><jupyter_text>Changing the number of classesStaying the the same classifier, the user can apply the same classification rule, but for a different number of classes:<jupyter_code>mc.MaximumBreaks(y, k=7)
mb7 = mc.MaximumBreaks(y, k=7)
mb7.bins
mb7.counts
mb7.yb<jupyter_output><empty_output><jupyter_text>One additional attribute to mention here is the `adcm` attribute:<jupyter_code>mb7.adcm<jupyter_output><empty_output><jupyter_text>`adcm` is a measure of fit, defined as the mean absolute deviation around the class median.<jupyter_code>mb4.adcm<jupyter_output><empty_output><jupyter_text>The `adcm` can be expected to decrease as $k$ increases for a given classifier. Thus, if using as a measure of fit, the `adcm` should only be used to compare classifiers defined on the same number of classes.  Next Steps`MaximumBreaks` is but one of many classifiers in `mapclassify`:<jupyter_code>mc.classifiers.CLASSIFIERS<jupyter_output><empty_output><jupyter_text>To learn more about an individual classifier, introspection is available:<jupyter_code>mc.MaximumBreaks?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07563959955506118, 'fraction_numerical': 0.008064516129032258, 'mean_word_length': 7.384615384615385, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 2, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '509754', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1082, 'n_words': 366, 'path': 'notebooks/01_maximum_breaks.ipynb', 'repo_name': 'weikang9009/mapclassify', 'size': '3596'}