Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update f1 score to not consider Label.Unclear as unlabeled matches #171

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/yardstick/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def __post_init__(self, result: ScanResult, lineage: list[str]):
# capture any matches that are in an indeterminate state...
# note: it is important NOT to use a set here, as multiple instances of the same label will throw
# the F1 score (e.g. [TP, TP ,TP] != [TP], only the latter is acceptable).
if len(label_set) != 1 or Label.Unclear in labels_for_match:
# note: we're not considering unclear label to count as an indeterminate match
# we want a definite f1 score in the quality gate without being overwhelmed by "disputed" unclear label
if len(label_set) != 1:
self.matches_with_indeterminate_labels.append(match)
# capture TP & FP only beyond this point...
continue
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_comparison_against_labels_indeterminate():
m3_indeterminate = [
artifact.LabelEntry(
label=artifact.Label.Unclear,
vulnerability_id="CVE-2021-2222",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this was changed so that it would now match against a vulnerability_id in the fixture. This test is effective since it shows the f1 score going up based on the change of Unclear being removed while also decreasing the amount of indeterminate found in the summary

vulnerability_id="CVE-2020-2222",
package=package_bash_5,
**common_label_options,
),
Expand Down Expand Up @@ -226,8 +226,8 @@ def test_comparison_against_labels_indeterminate():
lineage=[],
)

assert actual.summary.indeterminate == 2
assert set(actual.matches_with_indeterminate_labels) == {m2, m3}
assert actual.summary.indeterminate == 1
assert set(actual.matches_with_indeterminate_labels) == {m2}
assert actual.summary.f1_score == 1
assert actual.summary.f1_score_lower_confidence == 0.5
assert actual.summary.f1_score_lower_confidence == 0.6666666666666666
assert actual.summary.f1_score_upper_confidence == 1