Skip to content

Commit 8ef0947

Browse files
committed
Docs and testing for anchoring StdMean
1 parent b97c316 commit 8ef0947

File tree

3 files changed

+68
-33
lines changed

3 files changed

+68
-33
lines changed

mapclassify/classifiers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,12 @@ class StdMean(MapClassifier):
15431543
Notes
15441544
-----
15451545
1546-
If anchor is True, the closed upper bound of the first class is set to
1547-
min(y)+std(y), while the open lower bound of the last class is set to
1548-
max(y)-std(y). k is ignored if anchor is True, and is determined
1549-
by the number of standar deviations required to span the range of
1550-
y. multiples is also ignored if anchor is True.
1546+
If anchor is True, one of the intervals will its closed upper bound equal to
1547+
the mean of y. Intermediate intervals will have widths equal to the standard
1548+
deviation of y. The first interval will be closed on the minimum value of
1549+
y, and the last interval will be closed on the maximum of y. The first and
1550+
last intervals may have widths different from the intermediate intervals.
1551+
15511552
15521553
Examples
15531554
--------

mapclassify/tests/test_mapclassify.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,13 @@ def test_UserDefined_invariant(self):
623623
numpy.testing.assert_array_almost_equal(ud.counts, numpy.array([0, 3, 0, 0]))
624624

625625

626-
class TestStdMeanAnchor(unittest.TestCase):
627-
def setUp(self):
626+
class TestStdMeanAnchor:
627+
def setup_method(self):
628628
self.V = load_example()
629629

630630
def test_StdMeanAnchor(self):
631631
sm = StdMean(self.V, anchor=True)
632-
bins = np.array(
632+
bins = numpy.array(
633633
[
634634
125.92810345,
635635
672.57333208,
@@ -642,9 +642,9 @@ def test_StdMeanAnchor(self):
642642
4111.45,
643643
]
644644
)
645-
counts = np.array([50, 6, 1, 0, 0, 0, 0, 0, 1])
646-
np.testing.assert_array_almost_equal(sm.bins, bins)
647-
np.testing.assert_array_almost_equal(sm.counts, counts)
645+
counts = numpy.array([50, 6, 1, 0, 0, 0, 0, 0, 1])
646+
numpy.testing.assert_array_almost_equal(sm.bins, bins)
647+
numpy.testing.assert_array_almost_equal(sm.counts, counts)
648648

649649

650650
class TestMaxP:

notebooks/06_api.ipynb

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"ExecuteTime": {
2424
"end_time": "2022-11-05T15:10:19.167785Z",
2525
"start_time": "2022-11-05T15:10:14.404320Z"
26-
}
26+
},
27+
"tags": []
2728
},
2829
"outputs": [],
2930
"source": [
@@ -46,13 +47,14 @@
4647
"ExecuteTime": {
4748
"end_time": "2022-11-05T15:10:19.182165Z",
4849
"start_time": "2022-11-05T15:10:19.171353Z"
49-
}
50+
},
51+
"tags": []
5052
},
5153
"outputs": [
5254
{
5355
"data": {
5456
"text/plain": [
55-
"'2.4.2+78.gc62d2d7.dirty'"
57+
"'2.4.2+107.gb97c316a.dirty'"
5658
]
5759
},
5860
"execution_count": 2,
@@ -71,7 +73,8 @@
7173
"ExecuteTime": {
7274
"end_time": "2022-11-05T15:10:19.586837Z",
7375
"start_time": "2022-11-05T15:10:19.187232Z"
74-
}
76+
},
77+
"tags": []
7578
},
7679
"outputs": [
7780
{
@@ -295,7 +298,8 @@
295298
"ExecuteTime": {
296299
"end_time": "2022-11-05T15:10:19.595711Z",
297300
"start_time": "2022-11-05T15:10:19.589037Z"
298-
}
301+
},
302+
"tags": []
299303
},
300304
"outputs": [
301305
{
@@ -339,7 +343,8 @@
339343
"ExecuteTime": {
340344
"end_time": "2022-11-05T15:10:19.603460Z",
341345
"start_time": "2022-11-05T15:10:19.598526Z"
342-
}
346+
},
347+
"tags": []
343348
},
344349
"outputs": [
345350
{
@@ -374,7 +379,8 @@
374379
"ExecuteTime": {
375380
"end_time": "2022-11-05T15:10:19.611996Z",
376381
"start_time": "2022-11-05T15:10:19.608075Z"
377-
}
382+
},
383+
"tags": []
378384
},
379385
"outputs": [
380386
{
@@ -399,7 +405,8 @@
399405
"ExecuteTime": {
400406
"end_time": "2022-11-05T15:10:19.619168Z",
401407
"start_time": "2022-11-05T15:10:19.614412Z"
402-
}
408+
},
409+
"tags": []
403410
},
404411
"outputs": [
405412
{
@@ -440,7 +447,8 @@
440447
"ExecuteTime": {
441448
"end_time": "2022-11-05T15:10:19.627988Z",
442449
"start_time": "2022-11-05T15:10:19.621853Z"
443-
}
450+
},
451+
"tags": []
444452
},
445453
"outputs": [
446454
{
@@ -474,7 +482,8 @@
474482
"ExecuteTime": {
475483
"end_time": "2022-11-05T15:10:19.634396Z",
476484
"start_time": "2022-11-05T15:10:19.629847Z"
477-
}
485+
},
486+
"tags": []
478487
},
479488
"outputs": [
480489
{
@@ -508,7 +517,8 @@
508517
"ExecuteTime": {
509518
"end_time": "2022-11-05T15:10:19.641115Z",
510519
"start_time": "2022-11-05T15:10:19.636017Z"
511-
}
520+
},
521+
"tags": []
512522
},
513523
"outputs": [
514524
{
@@ -537,18 +547,19 @@
537547
},
538548
{
539549
"cell_type": "code",
540-
"execution_count": 10,
550+
"execution_count": 13,
541551
"metadata": {
542552
"ExecuteTime": {
543553
"end_time": "2022-11-05T15:10:19.691302Z",
544554
"start_time": "2022-11-05T15:10:19.645124Z"
545-
}
555+
},
556+
"tags": []
546557
},
547558
"outputs": [
548559
{
549560
"data": {
550561
"text/plain": [
551-
"StdMean \n",
562+
"StdMean\n",
552563
"\n",
553564
" Interval Count\n",
554565
"----------------------\n",
@@ -559,29 +570,30 @@
559570
"(75.37, 96.40] | 4"
560571
]
561572
},
562-
"execution_count": 10,
573+
"execution_count": 13,
563574
"metadata": {},
564575
"output_type": "execute_result"
565576
}
566577
],
567578
"source": [
568-
"classify(y, 'Std_Mean')"
579+
"mapclassify.classify(y, 'Std_Mean')"
569580
]
570581
},
571582
{
572583
"cell_type": "code",
573-
"execution_count": 11,
584+
"execution_count": 15,
574585
"metadata": {
575586
"ExecuteTime": {
576587
"end_time": "2022-10-26T03:01:45.977181Z",
577588
"start_time": "2022-10-26T03:01:45.931234Z"
578-
}
589+
},
590+
"tags": []
579591
},
580592
"outputs": [
581593
{
582594
"data": {
583595
"text/plain": [
584-
"StdMean \n",
596+
"StdMean\n",
585597
"\n",
586598
" Interval Count\n",
587599
"----------------------\n",
@@ -593,13 +605,35 @@
593605
"(93.83, 96.40] | 1"
594606
]
595607
},
596-
"execution_count": 11,
608+
"execution_count": 15,
609+
"metadata": {},
610+
"output_type": "execute_result"
611+
}
612+
],
613+
"source": [
614+
"mapclassify.classify(y, 'Std_Mean', anchor=True)"
615+
]
616+
},
617+
{
618+
"cell_type": "code",
619+
"execution_count": 16,
620+
"metadata": {
621+
"tags": []
622+
},
623+
"outputs": [
624+
{
625+
"data": {
626+
"text/plain": [
627+
"(38.43622446938775, 18.466069465206047, 17.9, 96.400002)"
628+
]
629+
},
630+
"execution_count": 16,
597631
"metadata": {},
598632
"output_type": "execute_result"
599633
}
600634
],
601635
"source": [
602-
"classify(y, 'Std_Mean', anchor=True)"
636+
"y.mean(), y.std(), y.min(), y.max()"
603637
]
604638
},
605639
{
@@ -626,7 +660,7 @@
626660
"name": "python",
627661
"nbconvert_exporter": "python",
628662
"pygments_lexer": "ipython3",
629-
"version": "3.10.6"
663+
"version": "3.10.10"
630664
}
631665
},
632666
"nbformat": 4,

0 commit comments

Comments
 (0)