gnn_tracking.metrics.binary_classification
==========================================

.. py:module:: gnn_tracking.metrics.binary_classification

.. autoapi-nested-parse::

   This class collects figures of merit for binary classification



Classes
-------

.. autoapisummary::

   gnn_tracking.metrics.binary_classification.BinaryClassificationStats


Functions
---------

.. autoapisummary::

   gnn_tracking.metrics.binary_classification.zero_divide
   gnn_tracking.metrics.binary_classification.get_maximized_bcs
   gnn_tracking.metrics.binary_classification.roc_auc_score
   gnn_tracking.metrics.binary_classification.get_roc_auc_scores


Module Contents
---------------

.. py:class:: BinaryClassificationStats(output: torch.Tensor, y: torch.Tensor, thld: torch.Tensor | float)

   Calculator for binary classification metrics.
   All properties are cached, so they are only calculated once.

   :param output: Output weights
   :param y: True labels
   :param thld: Threshold to consider something true

   :returns: accuracy, TPR, TNR


   .. py:attribute:: _output


   .. py:attribute:: _y


   .. py:attribute:: _thld


   .. py:property:: _true
      :type: torch.Tensor



   .. py:property:: n_true
      :type: int



   .. py:property:: _false
      :type: torch.Tensor



   .. py:property:: n_false
      :type: int



   .. py:property:: _predicted_false
      :type: torch.Tensor



   .. py:property:: n_predicted_false
      :type: int



   .. py:property:: _predicted_true
      :type: torch.Tensor



   .. py:property:: n_predicted_true
      :type: int



   .. py:property:: TP
      :type: float



   .. py:property:: TN
      :type: float



   .. py:property:: FP
      :type: float



   .. py:property:: FN
      :type: float



   .. py:property:: acc
      :type: float



   .. py:property:: TPR
      :type: float



   .. py:property:: TNR
      :type: float



   .. py:property:: FPR
      :type: float



   .. py:property:: FNR
      :type: float



   .. py:property:: balanced_acc
      :type: float



   .. py:property:: F1
      :type: float



   .. py:property:: MCC
      :type: float



   .. py:method:: get_all() -> dict[str, float]


.. py:function:: zero_divide(a: float, b: float) -> float

   Normal division a/b but return 0 for x/0


.. py:function:: get_maximized_bcs(*, output: torch.Tensor, y: torch.Tensor, n_samples=200) -> dict[str, float]

   Calculate the best possible binary classification stats for a given output and y.

   :param output: Weights
   :param y: True
   :param n_samples: Number of thresholds to sample

   :returns: Dictionary of metrics


.. py:function:: roc_auc_score(*, y_true: torch.Tensor, y_score: torch.Tensor, max_fpr: float | None = None, device=None) -> float

   Wrapper that ignores exceptions
   that can e.g., be raised if there's only one label present.


.. py:function:: get_roc_auc_scores(true, predicted, max_fprs: Iterable[float | None])

   Calculate ROC AUC scores for a given set of maximum FPRs.


