Skip to content

Commit

Permalink
Fixed Zscore implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KulikDM committed Aug 18, 2024
1 parent 278c2ec commit 0798d36
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest -vs --doctest-modules --cov-fail-under=90 --cov-branch --cov=pythresh --cov-report term-missing --pyargs pythresh --continue-on-collection-errors -o log_cli=true -o log_level=DEBUG
pytest -vs --doctest-modules --cov-fail-under=90 --cov-branch --cov=pythresh --cov-report term-missing --pyargs pythresh --continue-on-collection-errors
- name: Codecov
uses: codecov/codecov-action@v4
env:
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ datasets may help when selecting based on either accuracy or robustness
or both. PyOD provides a highly detailed analysis on the performance of
all the available methods, with great insight and interpretability
`anomaly detection benchmark paper
<https://www.andrew.cmu.edu/user/yuezhao2/papers/22-neurips-adbench.pdf>`_.
<https://proceedings.neurips.cc/paper_files/paper/2022/hash/cf93972b116ca5268827d575f2cc226b-Abstract-Datasets_and_Benchmarks.html>`_.

Since the thresholding methods are dependant on both the dataset and the
outlier detection likelihood scores, in order to quantify how well a
Expand Down
2 changes: 1 addition & 1 deletion pythresh/test/test_zscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_prediction_labels(self):
for scores in self.all_scores:

pred_labels = self.thres.eval(scores)
assert (self.thres.thresh_ is None)
assert (self.thres.thresh_ is not None)
assert (self.thres.dscores_ is not None)

assert (self.thres.dscores_.min() == 0)
Expand Down
10 changes: 5 additions & 5 deletions pythresh/thresholds/zscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def eval(self, decision):
self.dscores_ = decision

# Get the zscore of the decision scores
zscore = np.abs(stats.zscore(decision))
zscore = stats.zscore(decision)

# Set the limit to where the zscore is 1
scores = np.zeros(len(decision), dtype=int)
labels = np.zeros(len(decision), dtype=int)
mask = np.where(zscore >= 1.0)
scores[mask] = 1
labels[mask] = 1

self.thresh_ = None
self.thresh_ = np.min(labels[labels == 1])

return scores
return labels

0 comments on commit 0798d36

Please sign in to comment.