Skip to content

Commit

Permalink
tidy ks
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxHalford committed Nov 1, 2023
1 parent 0e87b80 commit 3d0d6b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions river/stats/kolmogorov_smirnov.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,6 @@ def __init__(self, statistic="ks"):
self.n_samples = 0
self.statistic = statistic

@staticmethod
def ca(p_value):
return (-0.5 * math.log(p_value)) ** 0.5

@classmethod
def ks_threshold(cls, p_value, n_samples):
return cls.ca(p_value) * (2.0 * n_samples / n_samples**2)

def update(self, x, y):
keys = ((x, 0), (y, 1))

Expand Down Expand Up @@ -282,7 +274,11 @@ def get(self):
else:
raise ValueError(f"Unknown statistic {self.statistic}, expected one of: ks, kuiper")

def test_ks_threshold(self, ca):
@staticmethod
def _ca(p_value):
return (-0.5 * math.log(p_value)) ** 0.5

def _test_ks_threshold(self, ca):
"""
Test whether the reference and sliding window follows the same or different probability distribution.
This test will return `True` if we **reject** the null hypothesis that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def test_incremental_ks_statistics():

assert np.allclose(np.array(incremental_ks_statistics), np.array(ks_2samp_statistics))

assert incremental_ks.test_ks_threshold(ca=incremental_ks.ca(p_value=0.05)) is True
assert incremental_ks._test_ks_threshold(ca=incremental_ks._ca(p_value=0.05)) is True

0 comments on commit 3d0d6b4

Please sign in to comment.