{"record":{"id":"85e8c363993ecd8d","repo":"roboflow/supervision","slug":"confusion-matrix-must-have-shape-3-got-co-85e8c3","errorCode":null,"errorMessage":"Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}","messagePattern":"Confusion matrix must have shape \\(\\.\\.\\., 3\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/f1_score.py","lineNumber":499,"sourceCode":"        result_confusion_matrix: npt.NDArray[np.float64] = confusion_matrix\n        return result_confusion_matrix\n\n    @staticmethod\n    def _compute_f1(\n        confusion_matrix: npt.NDArray[np.float64],\n    ) -> npt.NDArray[np.float64]:\n        \"\"\"\n        Broadcastable function, computing the F1 score from the confusion matrix.\n\n        Args:\n            confusion_matrix: shape (N, ..., 3), where the last dimension\n                contains the true positives, false positives, and false negatives.\n\n        Returns:\n            shape (N, ...), containing the F1 score for each element.\n        \"\"\"\n        if not confusion_matrix.shape[-1] == 3:\n            raise ValueError(\n                f\"Confusion matrix must have shape (..., 3), got \"\n                f\"{confusion_matrix.shape}\"\n            )\n        true_positives = confusion_matrix[..., 0]\n        false_positives = confusion_matrix[..., 1]\n        false_negatives = confusion_matrix[..., 2]\n\n        # Alternate formula, avoids multiple zero division checks\n        denominator = 2 * true_positives + false_positives + false_negatives\n        f1_score = np.divide(\n            2 * true_positives,\n            denominator,\n            out=np.zeros_like(denominator, dtype=np.float64),\n            where=denominator != 0,\n        )\n\n        result_f1_score: npt.NDArray[np.float64] = f1_score\n        return result_f1_score","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/f1_score.py#L481-L517","documentation":"Error \"Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/f1_score.py:499 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a confusion matrix whose last dimension is 3.","Use the metric's own computation methods to build the matrix instead of constructing it manually."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}