mapclassify.classify¶
- mapclassify.classify(y, scheme, k=5, pct=[1, 10, 50, 90, 99, 100], pct_sampled=0.1, truncate=True, hinge=1.5, multiples=[-2, -1, 1, 2], mindiff=0, initial=100, bins=None, lowest=None, anchor=False)[source]¶
Classify your data with
mapclassify.classify. Input parameters are dependent on classifier used.- Parameters:
- y
numpy.array \((n,1)\), values to classify.
- scheme
str pysal.mapclassifyclassification scheme.- k
int(default5) The number of classes.
- pct
numpy.array(default[1, 10, 50, 90, 99, 100]) Percentiles used for classification with
percentiles.- pct_sampled
floatdefault(0.10) The percentage of n that should form the sample (
JenksCaspallSampled,FisherJenksSampled) Ifpctis specified such thatn*pct > 1000, thenpct=1000.- truncatebool (
defaultTrue) Truncate
pct_sampledin cases wherepct * n > 1000.- hinge
float(default1.5) Multiplier for IQR when
BoxPlotclassifier used.- multiples
numpy.array(default[-2,-1,1,2]) The multiples of the standard deviation to add/subtract from the sample mean to define the bins using
std_mean.- mindiff
float(defaultis0) The minimum difference between class breaks if using
maximum_breaksclassifier.- initial
int(default100) Number of initial solutions to generate or number of runs when using
natural_breaksormax_p_classifier. Setting initial to0will result in the quickest calculation of bins.- bins
numpy.array(defaultNone) \((k,1)\), upper bounds of classes (have to be monotically increasing) if using
user_definedclassifier. Default isNone. For example:[20, max(y)].- lowest
float(defaultNone) Scalar minimum value of lowest class. Default is to set the minimum to
-infify.min()> first upper bound (which will override the default), otherwise minimum is set toy.min().- anchorbool (
defaultFalse) Anchor upper bound of one class to the sample mean.
- y
- Returns:
- classifier
mapclassify.classifiers.MapClassifier Object containing bin ids for each observation (
.yb), upper bounds of each class (.bins), number of classes (.k) and number of observations falling in each class (.counts).
- classifier
Notes
Supported classifiers include:
quantilesboxplotequalintervalfisherjenksfisherjenkssampledheadtailbreaksjenkscaspalljenkscaspallsampledjenks_caspallforcedmaxpmaximumbreaksnaturalbreakspercentilesprettybreaksstdmeanuserdefined
Examples
>>> import libpysal >>> import geopandas >>> from mapclassify import classify
Load example data.
>>> link_to_data = libpysal.examples.get_path("columbus.shp") >>> gdf = geopandas.read_file(link_to_data) >>> x = gdf['HOVAL'].values
Classify values by quantiles.
>>> quantiles = classify(x, "quantiles")
Classify values by box_plot and set hinge to
2.>>> box_plot = classify(x, 'box_plot', hinge=2) >>> box_plot BoxPlot Interval Count ---------------------- ( -inf, -9.50] | 0 (-9.50, 25.70] | 13 (25.70, 33.50] | 12 (33.50, 43.30] | 12 (43.30, 78.50] | 9 (78.50, 96.40] | 3