TensorTonic
Problems
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. You do not need to round the returned score; answers that match the expected value to four decimal places are accepted.

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. Rounding to four decimal places is optional

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
Compute AUC (Area Under ROC)EasyBinary Log Loss per Sample in PythonEasyIntersection over Union (IoU)EasyCompute Accuracy, Precision, Recall, F1MediumCompute Confusion Matrix with NormalizationHardImplement Precision and Recall at K in PythonEasyCatalog CoverageEasyHit Rate at KEasyCalculate P50, P95, and P99 Inference LatencyEasyTop-K Classification AccuracyEasyMean IoU for SegmentationEasyRegression MetricsEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Implement Micro-F1

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. You do not need to round the returned score; answers that match the expected value to four decimal places are accepted.

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. Rounding to four decimal places is optional

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
Compute AUC (Area Under ROC)EasyBinary Log Loss per Sample in PythonEasyIntersection over Union (IoU)EasyCompute Accuracy, Precision, Recall, F1MediumCompute Confusion Matrix with NormalizationHardImplement Precision and Recall at K in PythonEasyCatalog CoverageEasyHit Rate at KEasyCalculate P50, P95, and P99 Inference LatencyEasyTop-K Classification AccuracyEasyMean IoU for SegmentationEasyRegression MetricsEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1