TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Micro-F1

Metrics & Evaluation
Easy

Compute the micro-averaged F1 score for equal-length sequences of single-label multiclass predictions. First aggregate true positives, false positives, and false negatives across every class, then compute

F1,micro=2TP2TP+FP+FNF_{1,\mathrm{micro}} = \frac{2TP}{2TP + FP + FN}F1,micro​=2TP+FP+FN2TP​

Here, TPTPTP, FPFPFP, and FNFNFN are the totals across all classes. Return the score as a Python float rounded to four decimal places.

Loading visualization...

Examples

Input: y_true = [0, 1, 1], y_pred = [0, 1, 0]

Output: 0.6667

Explanation: Across all classes there are two true positives, one false positive, and one false negative.

Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 2, 2]

Output: 1.0

Input: y_true = [2, 2, 1, 0], y_pred = [1, 2, 1, 0]

Output: 0.75

Hint 1

sum(actual == predicted for actual, predicted in zip(y_true, y_pred)) counts correct single-label predictions.

Hint 2

For single-label multiclass data, every mismatch contributes one false positive and one false negative.

Requirements

  • y_true and y_pred contain one integer class label per sample
  • Aggregate counts across every class
  • Return a Python float rounded to four decimal places

Constraints

  • y_true and y_pred have the same nonzero length
  • At most 100,000100{,}000100,000 labels are provided
  • Do not use an external machine learning library
Try Similar Problems
Classification MetricsAucIou Bounding BoxConfusion Matrix NormLog Loss Per Sample

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Implement Micro-F1

Metrics & Evaluation
Easy

Compute the micro-averaged F1 score for equal-length sequences of single-label multiclass predictions. First aggregate true positives, false positives, and false negatives across every class, then compute

F1,micro=2TP2TP+FP+FNF_{1,\mathrm{micro}} = \frac{2TP}{2TP + FP + FN}F1,micro​=2TP+FP+FN2TP​

Here, TPTPTP, FPFPFP, and FNFNFN are the totals across all classes. Return the score as a Python float rounded to four decimal places.

Loading visualization...

Examples

Input: y_true = [0, 1, 1], y_pred = [0, 1, 0]

Output: 0.6667

Explanation: Across all classes there are two true positives, one false positive, and one false negative.

Input: y_true = [0, 1, 2, 2], y_pred = [0, 1, 2, 2]

Output: 1.0

Input: y_true = [2, 2, 1, 0], y_pred = [1, 2, 1, 0]

Output: 0.75

Hint 1

sum(actual == predicted for actual, predicted in zip(y_true, y_pred)) counts correct single-label predictions.

Hint 2

For single-label multiclass data, every mismatch contributes one false positive and one false negative.

Requirements

  • y_true and y_pred contain one integer class label per sample
  • Aggregate counts across every class
  • Return a Python float rounded to four decimal places

Constraints

  • y_true and y_pred have the same nonzero length
  • At most 100,000100{,}000100,000 labels are provided
  • Do not use an external machine learning library
Try Similar Problems
Classification MetricsAucIou Bounding BoxConfusion Matrix NormLog Loss Per Sample

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.