pysal.viz.mapclassify.Natural_Breaks¶

class pysal.viz.mapclassify.Natural_Breaks(y, k=5, initial=100)[source]

Natural Breaks Map Classification

Parameters: y : array (n,1), values to classify k : int number of classes required initial : int number of initial solutions to generate, (default=100)

Notes

There is a tradeoff here between speed and consistency of the classification If you want more speed, set initial to a smaller value (0 would result in the best speed, if you want more consistent classes in multiple runs of Natural_Breaks on the same data, set initial to a higher value.

Examples

>>> import numpy as np
>>> import pysal.viz.mapclassify as mc
>>> np.random.seed(123456)
>>> nb = mc.Natural_Breaks(cal, k=5)
>>> nb.k
5
>>> nb.counts
array([41,  9,  6,  1,  1])
>>> nb.bins
array([  29.82,  110.74,  370.5 ,  722.85, 4111.45])
>>> x = np.array([1] * 50)
>>> x[-1] = 20
>>> nb = mc.Natural_Breaks(x, k = 5, initial = 0)


Warning: Not enough unique values in array to form k classes Warning: setting k to 2

>>> nb.bins
array([ 1, 20])
>>> nb.counts
array([49,  1])

Attributes: yb : array (n,1), bin ids for observations, bins : array (k,1), the upper bounds of each class k : int the number of classes counts : array (k,1), the number of observations falling in each class

Methods

 __call__(*args, **kwargs) This will allow the classifier to be called like it’s a function. find_bin(x) Sort input or inputs according to the current bin estimate get_adcm() Absolute deviation around class median (ADCM). get_gadf() Goodness of absolute deviation of fit get_tss() Total sum of squares around class means make(*args, **kwargs) Configure and create a classifier that will consume data and produce classifications, given the configuration options specified by this function. update([y, inplace]) Add data or change classification parameters.
__init__(y, k=5, initial=100)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

 __init__(y[, k, initial]) Initialize self. find_bin(x) Sort input or inputs according to the current bin estimate get_adcm() Absolute deviation around class median (ADCM). get_gadf() Goodness of absolute deviation of fit get_tss() Total sum of squares around class means make(*args, **kwargs) Configure and create a classifier that will consume data and produce classifications, given the configuration options specified by this function. update([y, inplace]) Add data or change classification parameters.