Your question is Precision and Recall for Multi-Class. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The RealReal evaluates a classifier that assigns categories to fashion listings. Given the true category and predicted category for each listing, calculate precision and recall independently for every requested class.
Implement multiclass_precision_recall(y_true, y_pred, labels), where y_true, y_pred, and labels are lists of strings. y_true[i] is the correct class for item i, and y_pred[i] is the model's prediction. The lists y_true and y_pred have equal length. Return a dictionary mapping each label to a dictionary containing numeric precision and recall values.
For class c:
precision = TP / (TP + FP), where the denominator is the number of predictions equal to c.recall = TP / (TP + FN), where the denominator is the number of true labels equal to c.0.0 for that metric.Preserve the labels supplied by the caller, including classes that do not appear in either input. Do not calculate macro or micro averages.
def multiclass_precision_recall(y_true, y_pred, labels):