Precision and recall scaled

Write codeMedium14 minMeta style

Your task

A moderation model assigns each post one string category. For one target category, compute precision and recall scaled to integers. Given equal-length lists y_true and y_pred and a target category, let tp be positions where both equal target, predicted be positions where y_pred equals target, and actual be positions where y_true equals target. Return [floor(1000 * tp / predicted), floor(1000 * tp / actual)]. If predicted is 0 use -1 for the first value; if actual is 0 use -1 for the second. Example: y_true = ["toxic", "ok", "toxic", "spam"], y_pred = ["toxic", "toxic", "ok", "spam"], target "toxic" gives [500, 500].

Examples

class_prec_recall(y_true: list[str], y_pred: list[str], target: str) -> list[int]
Example 1
Inputclass_prec_recall(["toxic", "ok", "toxic", "spam"], ["toxic", "toxic", "ok", "spam"], "toxic")
Output[500, 500]