Skip to content

Commit

Permalink
exploring anchor for stdMean
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsrey committed Mar 18, 2023
1 parent 0155c6e commit 69f220c
Show file tree
Hide file tree
Showing 2 changed files with 530 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mapclassify/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,8 @@ class StdMean(MapClassifier):
multiples : array
the multiples of the standard deviation to add/subtract from
the sample mean to define the bins, default=[-2,-1,1,2]
anchor : bool, default=False
Anchor upper bound of one class to the sample mean
Attributes
----------
Expand Down Expand Up @@ -1534,15 +1536,20 @@ class StdMean(MapClassifier):
"""

def __init__(self, y, multiples=[-2, -1, 1, 2]):
def __init__(self, y, multiples=[-2, -1, 1, 2], anchor=False):
self.multiples = multiples
self.anchor = anchor
MapClassifier.__init__(self, y)
self.name = "StdMean"

def _set_bins(self):
y = self.y
s = y.std(ddof=1)
m = y.mean()
if self.anchor:
min_z = int((y.min() - m)/s)
max_z = int((y.max() - m)/s) + 1
self.multiples = list(range(min_z, max_z))
cuts = [m + s * w for w in self.multiples]
y_max = y.max()
if cuts[-1] < y_max:
Expand Down
522 changes: 522 additions & 0 deletions notebooks/07_std_anchor.ipynb

Large diffs are not rendered by default.

0 comments on commit 69f220c

Please sign in to comment.