mapclassify.NaturalBreaks

class mapclassify.NaturalBreaks(y, k=5, initial=10)[source]

Natural Breaks Map Classification

Parameters
yarray

(n,1), values to classify

kint

number of classes required

initialint, default: 10

Number of initial solutions generated with different centroids. Best of initial results is returned.

Examples

>>> import numpy as np
>>> import mapclassify as mc
>>> np.random.seed(123456)
>>> cal = mc.load_example()
>>> nb = mc.NaturalBreaks(cal, k=5)
>>> nb.k
5
>>> nb.counts
array([49,  3,  4,  1,  1])
>>> nb.bins
array([  75.29,  192.05,  370.5 ,  722.85, 4111.45])
>>> x = np.array([1] * 50)
>>> x[-1] = 20
>>> nb = mc.NaturalBreaks(x, k = 5)

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
ybarray

(n,1), bin ids for observations,

binsarray

(k,1), the upper bounds of each class

kint

the number of classes

countsarray

(k,1), the number of observations falling in each class

__init__(self, y, k=5, initial=10)[source]

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

Methods

__init__(self, y[, k, initial])

Initialize self.

find_bin(self, x)

Sort input or inputs according to the current bin estimate

get_adcm(self)

Absolute deviation around class median (ADCM).

get_fmt(self)

get_gadf(self)

Goodness of absolute deviation of fit

get_legend_classes(self[, fmt])

Format the strings for the classes on the legend

get_tss(self)

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.

plot(self, gdf[, border_color, …])

Plot Mapclassiifer NOTE: Requires matplotlib, and implicitly requires geopandas dataframe as input.

set_fmt(self, fmt)

table(self)

update(self[, y, inplace])

Add data or change classification parameters.

Attributes

fmt

update(self, y=None, inplace=False, \*\*kwargs)[source]

Add data or change classification parameters.

Parameters
yarray

(n,1) array of data to classify

inplacebool

whether to conduct the update in place or to return a copy estimated from the additional specifications.

Additional parameters provided in **kwargs are passed to the init
function of the class. For documentation, check the class constructor.