class_docstr: Compute confusion matrix related metrics. This function supports to calculate all metrics mentioned in:
  `Confusion matrix <https://en.wikipedia.org/wiki/Confusion_matrix>`_.
  It can support both multi-classes and multi-labels classification and segmentation tasks.
  `y_preds` is expected to have binarized predictions and `y` should be in one-hot format. You can use suitable transforms
  in ``monai.transforms.post`` first to achieve binarized values.
  The `include_background` parameter can be set to ``False`` for an instance to exclude
  the first category (channel index 0) which is by convention assumed to be background. If the non-background
  segmentations are small compared to the total image size they can get overwhelmed by the signal from the
  background.
  
  Example of the typical execution steps of this metric class follows :py:class:`monai.metrics.metric.Cumulative`.
  
  Args:
      include_background: whether to include metric computation on the first channel of
          the predicted output. Defaults to True.
      metric_name: [``"sensitivity"``, ``"specificity"``, ``"precision"``, ``"negative predictive value"``,
          ``"miss rate"``, ``"fall out"``, ``"false discovery rate"``, ``"false omission rate"``,
          ``"prevalence threshold"``, ``"threat score"``, ``"accuracy"``, ``"balanced accuracy"``,
          ``"f1 score"``, ``"matthews correlation coefficient"``, ``"fowlkes mallows index"``,
          ``"informedness"``, ``"markedness"``]
          Some of the metrics have multiple aliases (as shown in the wikipedia page aforementioned),
          and you can also input those names instead.
          Except for input only one metric, multiple metrics are also supported via input a sequence of metric names, such as
          ("sensitivity", "precision", "recall"), if ``compute_sample`` is ``True``, multiple ``f`` and ``not_nans`` will be
          returned with the same order as input names when calling the class.
      compute_sample: when reducing, if ``True``, each sample's metric will be computed based on each confusion matrix first.
          if ``False``, compute reduction on the confusion matrices first, defaults to ``False``.
      reduction: define mode of reduction to the metrics, will only apply reduction on `not-nan` values,
          available reduction modes: {``"none"``, ``"mean"``, ``"sum"``, ``"mean_batch"``, ``"sum_batch"``,
          ``"mean_channel"``, ``"sum_channel"``}, default to ``"mean"``. if "none", will not do reduction.
      get_not_nans: whether to return the `not_nans` count, if True, aggregate() returns [(metric, not_nans), ...]. If False,
          aggregate() returns [metric, ...].
          Here `not_nans` count the number of not nans for True Positive, False Positive, True Negative and False Negative.
          Its shape depends on the shape of the metric, and it has one more dimension with size 4. For example, if the shape
          of the metric is [3, 3], `not_nans` has the shape [3, 3, 4].
class_docstr_tok: ["Compute","confusion","matrix","related","metrics",".","This","function","supports","to","calculate","all","metrics","mentioned","in",":","`","Confusion","matrix","<","https",":","\/\/en.wikipedia.org\/wiki\/Confusion_matrix",">","`","_",".","It","can","support","both","multi-classes","and","multi-labels","classification","and","segmentation","tasks",".","`","y_preds","`","is","expected","to","have","binarized","predictions","and","`","y","`","should","be","in","one-hot","format",".","You","can","use","suitable","transforms","in","``","monai.transforms.post","``","first","to","achieve","binarized","values",".","The","`","include_background","`","parameter","can","be","set","to","``","False","``","for","an","instance","to","exclude","the","first","category","(","channel","index","0",")","which","is","by","convention","assumed","to","be","background",".","If","the","non-background","segmentations","are","small","compared","to","the","total","image","size","they","can","get","overwhelmed","by","the","signal","from","the","background",".","Example","of","the","typical","execution","steps","of","this","metric","class","follows",":","py",":","class",":","`","monai.metrics.metric.Cumulative","`",".","Args",":","include_background",":","whether","to","include","metric","computation","on","the","first","channel","of","the","predicted","output",".","Defaults","to","True",".","metric_name",":","[","``","``","sensitivity","''","``",",","``","``","specificity","''","``",",","``","``","precision","''","``",",","``","``","negative","predictive","value","''","``",",","``","``","miss","rate","''","``",",","``","``","fall","out","''","``",",","``","``","false","discovery","rate","''","``",",","``","``","false","omission","rate","''","``",",","``","``","prevalence","threshold","''","``",",","``","``","threat","score","''","``",",","``","``","accuracy","''","``",",","``","``","balanced","accuracy","''","``",",","``","``","f1","score","''","``",",","``","``","matthews","correlation","coefficient","''","``",",","``","``","fowlkes","mallows","index","''","``",",","``","``","informedness","''","``",",","``","``","markedness","''","``","]","Some","of","the","metrics","have","multiple","aliases","(","as","shown","in","the","wikipedia","page","aforementioned",")",",","and","you","can","also","input","those","names","instead",".","Except","for","input","only","one","metric",",","multiple","metrics","are","also","supported","via","input","a","sequence","of","metric","names",",","such","as","(","``","sensitivity","''",",","``","precision","''",",","``","recall","''",")",",","if","``","compute_sample","``","is","``","True","``",",","multiple","``","f","``","and","``","not_nans","``","will","be","returned","with","the","same","order","as","input","names","when","calling","the","class",".","compute_sample",":","when","reducing",",","if","``","True","``",",","each","sample","'s","metric","will","be","computed","based","on","each","confusion","matrix","first",".","if","``","False","``",",","compute","reduction","on","the","confusion","matrices","first",",","defaults","to","``","False","``",".","reduction",":","define","mode","of","reduction","to","the","metrics",",","will","only","apply","reduction","on","`","not-nan","`","values",",","available","reduction","modes",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``",",","``","``","mean_batch","''","``",",","``","``","sum_batch","''","``",",","``","``","mean_channel","''","``",",","``","``","sum_channel","''","``","}",",","default","to","``","``","mean","''","``",".","if","``","none","''",",","will","not","do","reduction",".","get_not_nans",":","whether","to","return","the","`","not_nans","`","count",",","if","True",",","aggregate","(",")","returns","[","(","metric",",","not_nans",")",",","...","]",".","If","False",",","aggregate","(",")","returns","[","metric",",","...","]",".","Here","`","not_nans","`","count","the","number","of","not","nans","for","True","Positive",",","False","Positive",",","True","Negative","and","False","Negative",".","Its","shape","depends","on","the","shape","of","the","metric",",","and","it","has","one","more","dimension","with","size","4",".","For","example",",","if","the","shape","of","the","metric","is","[","3",",","3","]",",","`","not_nans","`","has","the","shape","[","3",",","3",",","4","]","."]
code: def __init__(
      self,
      include_background: bool = True,
      metric_name: Sequence[str] | str = "hit_rate",
      compute_sample: bool = False,
      reduction: MetricReduction | str = MetricReduction.MEAN,
      get_not_nans: bool = False,
  ) -> None:
      super().__init__()
      self.include_background = include_background
      self.metric_name = ensure_tuple(metric_name)
      self.compute_sample = compute_sample
      self.reduction = reduction
      self.get_not_nans = get_not_nans
  
file_path: MONAI/monai/metrics/confusion_matrix.py
imports: from __future__ import annotations
  import warnings
  from collections.abc import Sequence
  import torch
  from monai.metrics.utils import do_metric_reduction, ignore_background
  from monai.utils import MetricReduction, ensure_tuple
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 to create a new ConfusionMatrixMetric object from inherited base classes: CumulativeIterationMetric with example: obj = ConfusionMatrixMetric(include_background, metric_name, compute_sample, reduction, get_not_nans)