code: def concordance_index(
      event_times, predicted_scores, event_observed=None
  ) -> float:
      """
      Calculates the concordance index (C-index) between a series
      of event times and a predicted score. The first is the real survival times from
      the observational data, and the other is the predicted score from a model of some kind.
  
      The c-index is the average of how often a model says X is greater than Y when, in the observed
      data, X is indeed greater than Y. The c-index also handles how to handle censored values
      (obviously, if Y is censored, it's hard to know if X is truly greater than Y).
  
  
      The concordance index is a value between 0 and 1 where:
  
      - 0.5 is the expected result from random predictions,
      - 1.0 is perfect concordance and,
      - 0.0 is perfect anti-concordance (multiply predictions with -1 to get 1.0)
  
      The calculation internally done is
  
      >>> (pairs_correct + 0.5 * pairs_tied) / admissable_pairs
  
      where ``pairs_correct`` is the number of pairs s.t. if ``t_x > t_y``, then ``s_x > s_y``, pairs,
      ``pairs_tied`` is the number of pairs where ``s_x = s_y``, and ``admissable_pairs`` is all possible pairs. The subtleties
      are in how censored observation are handled (ex: not all pairs can be evaluated due to censoring).
  
  
      Parameters
      ----------
      event_times: iterable
           a length-n iterable of observed survival times.
      predicted_scores: iterable
          a length-n iterable of predicted scores - these could be survival times, or hazards, etc. See https://stats.stackexchange.com/questions/352183/use-median-survival-time-to-calculate-cph-c-statistic/352435#352435
      event_observed: iterable, optional
          a length-n iterable censoring flags, 1 if observed, 0 if not. Default None assumes all observed.
  
      Returns
      -------
      c-index: float
        a value between 0 and 1.
  
      References
      -----------
      Harrell FE, Lee KL, Mark DB. Multivariable prognostic models: issues in
      developing models, evaluating assumptions and adequacy, and measuring and
      reducing errors. Statistics in Medicine 1996;15(4):361-87.
  
      Examples
      --------
      .. code:: python
  
          from lifelines.utils import concordance_index
          cph = CoxPHFitter().fit(df, 'T', 'E')
          concordance_index(df['T'], -cph.predict_partial_hazard(df), df['E'])
  
      """
      (
          event_times,
          predicted_scores,
          event_observed,
      ) = _preprocess_scoring_data(
          event_times, predicted_scores, event_observed
      )
      (
          num_correct,
          num_tied,
          num_pairs,
      ) = _concordance_summary_statistics(
          event_times, predicted_scores, event_observed
      )
  
      return _concordance_ratio(num_correct, num_tied, num_pairs)
  
file_path: lifelines/lifelines/utils/concordance.py
imports: import numpy
  from lifelines.utils.btree import _BTree
label_desc: Use image node_id 2 for calling a global function with example usage: concordance_index(event_times, predicted_scores, event_observed) and returns: _concordance_ratio