Class AccuracyMetrics
This class performs no I/O and calls no AI provider: given the same
AccuracyMetrics.Sample list it always returns the same AccuracyMetrics.Result, so the metric
math is unit-testable offline. Reading labels and predictions from files is
the job of AccuracyEvaluator.
Two evaluated dimensions
securityRelevant— a binary decision per method, scored as a confusion matrix (TP/FP/FN/TN) where "positive" means security-relevant. Only samples whose truth label carries a relevance decision take part.- taxonomy tags — a multi-label decision per method, scored one-vs-rest per tag (a tag is a TP when predicted and labelled, an FP when predicted only, an FN when labelled only) plus micro- and macro-averages. Only samples whose truth label carries a tag set take part.
Undefined values
Precision is TP/(TP+FP), recall is TP/(TP+FN), F1 is
2TP/(2TP+FP+FN) and accuracy is (TP+TN)/total. When a
denominator is zero the metric is mathematically undefined, and it is reported
as OptionalDouble.empty() rather than silently as 0 or
1: "no evidence" must not read as "perfect" or "terrible" in an audit
report.
Tag normalisation
Tags are trimmed, lower-cased with Locale.ROOT and de-duplicated, and
blank tags are dropped, so "Crypto " and "crypto" are the same
taxonomy tag. The taxonomy is a closed lower-case vocabulary, so this never
merges distinct tags.
This class is stateless and thread-safe.
- Since:
- 6.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordConfusion counts for one binary decision.static final recordThe complete metric set.static final recordOne method for which a prediction is compared with a human label.static final recordMetrics of a single taxonomy tag. -
Method Summary
Modifier and TypeMethodDescriptionstatic AccuracyMetrics.Resultcompute(Collection<AccuracyMetrics.Sample> samples) Computes all metrics for the given samples.normalise(Collection<String> tags) Normalises a tag collection (trim, lower-case withLocale.ROOT, drop blanks, de-duplicate).
-
Method Details
-
compute
Computes all metrics for the given samples.- Parameters:
samples- prediction/label pairs; must not benull; may be empty, which yields all-zero counts and undefined ratios- Returns:
- the metrics; never
null; per-tag list sorted by tag
-
normalise
Normalises a tag collection (trim, lower-case withLocale.ROOT, drop blanks, de-duplicate).- Parameters:
tags- tags to normalise;nullis treated as empty- Returns:
- sorted, normalised tag set; never
null
-