Skip to content

docs(utility): correct score_to_label return description - #733

Open
godarrenw wants to merge 1 commit into
yzhao062:developmentfrom
godarrenw:docs/fix-score-to-label-docstring
Open

docs(utility): correct score_to_label return description#733
godarrenw wants to merge 1 commit into
yzhao062:developmentfrom
godarrenw:docs/fix-score-to-label-docstring

Conversation

@godarrenw

Copy link
Copy Markdown

Description

score_to_label documents a return value it does not produce.

Its Returns section currently ends with:

Return the outlier probability, ranging in [0,1].

but the function returns binary labels:

threshold = percentile(pred_scores, 100 * (1 - outliers_fraction))
pred_labels = (pred_scores > threshold).astype('int')
return pred_labels

The summary line of the same docstring already says "Turn raw outlier scores to binary labels (0 or 1)", so the docstring contradicts itself. The wording appears to have been copied from BaseDetector.predict_proba (base.py:205), which really does return probabilities.

Running it confirms the behaviour:

>>> score_to_label([0.1,0.4,0.2,0.3,0.5,0.9,0.7,1,0.8,0.6], outliers_fraction=0.3)
array([0, 0, 0, 0, 0, 1, 0, 1, 1, 0])   # dtype int64, values {0, 1}

which also matches test_utility.py:198-204, where the expected values are asserted as 0/1.

This PR replaces that sentence with "Returns 0 for inliers and 1 for outliers."

It also drops a duplicated word on the summary line: Turn raw outlier outlier scoresTurn raw outlier scores.

Why it matters

score_to_label is part of the public API — it is exported in pyod/utils/__init__.py and listed in __all__ — so this text is what users see when they read the docs or call help(), and it currently tells them to expect probabilities.

How I checked

Read the implementation, ran the function against the same input the test suite uses, and compared with predict_proba's docstring to identify where the wording came from. python -m py_compile passes. Docstring only — no behaviour change.

No open PR or issue covers this (search/issues for score_to_label returned one unrelated result), so this PR does not close an existing issue.

_Disclosure: prepared with AI assistance; the return value was verified by running the function.

Signed-off-by: Zhu yizhang <95731595+godarrenw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant