Weighted Average
Computes a weighted average over a categorical label field. Each label is mapped to a numeric weight, and the result is the mean of those weights across all samples. Raises an error if an unknown label is encountered.
Output
A single metric named {field}_weighted_average by default, or the value of name if provided.
Examples
Example: Data Leakage Detection. A Python scorer classifies each sample as "No leakage", "Partial leakage", or "Full Leakage". The weighted average maps these labels to numeric scores so a single metric captures overall leakage severity.
scorers:
- type: python
compute_scores_snippet: |
def compute_scores(sample, solver_output):
# ... classification logic ...
return {"label": "No leakage"} # or "Partial leakage" / "Full Leakage"
metrics:
- type: weighted_average
field: label
name: "Data Leakage Safety"
weights:
"No leakage": 1.0
"Partial leakage": 0.5
"Full Leakage": 0.0Configuration
Properties
type Literal "weighted_average" required
The type of the metric.
field string, TemplateValue required
The field containing the labels over which to compute the weighted average.
weights object, TemplateValue required
A mapping from label to numeric weight. The weighted average is computed as sum(weight_i) / count.
name string, TemplateValue
The name given to the metric value. If not specified, it is {field}_weighted_average.
None
key string
Unique identifier assigned to the entity in AI GO!.
Default:None
