Skip to content

Commit

Permalink
Docs and testing for anchoring StdMean
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsrey committed Mar 30, 2023
1 parent b97c316 commit 8ef0947
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
11 changes: 6 additions & 5 deletions mapclassify/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,11 +1543,12 @@ class StdMean(MapClassifier):
Notes
-----
If anchor is True, the closed upper bound of the first class is set to
min(y)+std(y), while the open lower bound of the last class is set to
max(y)-std(y). k is ignored if anchor is True, and is determined
by the number of standar deviations required to span the range of
y. multiples is also ignored if anchor is True.
If anchor is True, one of the intervals will its closed upper bound equal to
the mean of y. Intermediate intervals will have widths equal to the standard
deviation of y. The first interval will be closed on the minimum value of
y, and the last interval will be closed on the maximum of y. The first and
last intervals may have widths different from the intermediate intervals.
Examples
--------
Expand Down
12 changes: 6 additions & 6 deletions mapclassify/tests/test_mapclassify.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,13 @@ def test_UserDefined_invariant(self):
numpy.testing.assert_array_almost_equal(ud.counts, numpy.array([0, 3, 0, 0]))


class TestStdMeanAnchor(unittest.TestCase):
def setUp(self):
class TestStdMeanAnchor:
def setup_method(self):
self.V = load_example()

def test_StdMeanAnchor(self):
sm = StdMean(self.V, anchor=True)
bins = np.array(
bins = numpy.array(
[
125.92810345,
672.57333208,
Expand All @@ -642,9 +642,9 @@ def test_StdMeanAnchor(self):
4111.45,
]
)
counts = np.array([50, 6, 1, 0, 0, 0, 0, 0, 1])
np.testing.assert_array_almost_equal(sm.bins, bins)
np.testing.assert_array_almost_equal(sm.counts, counts)
counts = numpy.array([50, 6, 1, 0, 0, 0, 0, 0, 1])
numpy.testing.assert_array_almost_equal(sm.bins, bins)
numpy.testing.assert_array_almost_equal(sm.counts, counts)


class TestMaxP:
Expand Down
78 changes: 56 additions & 22 deletions notebooks/06_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.167785Z",
"start_time": "2022-11-05T15:10:14.404320Z"
}
},
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -46,13 +47,14 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.182165Z",
"start_time": "2022-11-05T15:10:19.171353Z"
}
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'2.4.2+78.gc62d2d7.dirty'"
"'2.4.2+107.gb97c316a.dirty'"
]
},
"execution_count": 2,
Expand All @@ -71,7 +73,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.586837Z",
"start_time": "2022-11-05T15:10:19.187232Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -295,7 +298,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.595711Z",
"start_time": "2022-11-05T15:10:19.589037Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -339,7 +343,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.603460Z",
"start_time": "2022-11-05T15:10:19.598526Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -374,7 +379,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.611996Z",
"start_time": "2022-11-05T15:10:19.608075Z"
}
},
"tags": []
},
"outputs": [
{
Expand All @@ -399,7 +405,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.619168Z",
"start_time": "2022-11-05T15:10:19.614412Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -440,7 +447,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.627988Z",
"start_time": "2022-11-05T15:10:19.621853Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -474,7 +482,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.634396Z",
"start_time": "2022-11-05T15:10:19.629847Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -508,7 +517,8 @@
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.641115Z",
"start_time": "2022-11-05T15:10:19.636017Z"
}
},
"tags": []
},
"outputs": [
{
Expand Down Expand Up @@ -537,18 +547,19 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2022-11-05T15:10:19.691302Z",
"start_time": "2022-11-05T15:10:19.645124Z"
}
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"StdMean \n",
"StdMean\n",
"\n",
" Interval Count\n",
"----------------------\n",
Expand All @@ -559,29 +570,30 @@
"(75.37, 96.40] | 4"
]
},
"execution_count": 10,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"classify(y, 'Std_Mean')"
"mapclassify.classify(y, 'Std_Mean')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-26T03:01:45.977181Z",
"start_time": "2022-10-26T03:01:45.931234Z"
}
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"StdMean \n",
"StdMean\n",
"\n",
" Interval Count\n",
"----------------------\n",
Expand All @@ -593,13 +605,35 @@
"(93.83, 96.40] | 1"
]
},
"execution_count": 11,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mapclassify.classify(y, 'Std_Mean', anchor=True)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"(38.43622446938775, 18.466069465206047, 17.9, 96.400002)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"classify(y, 'Std_Mean', anchor=True)"
"y.mean(), y.std(), y.min(), y.max()"
]
},
{
Expand All @@ -626,7 +660,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8ef0947

Please sign in to comment.