#NEWLINE# def concordance_index( event_times , predicted_event_times , event_observed = None ) : #NEWLINE# #INDENT# '\n    Calculates the concordance index (C-index) between two series\n    of event times. The first is the real survival times from\n    the experimental data, and the other is the predicted survival\n    times from a model of some kind.\n\n    The concordance index is a value between 0 and 1 where,\n    0.5 is the expected result from random predictions,\n    1.0 is perfect concordance and,\n    0.0 is perfect anti-concordance (multiply predictions with -1 to get 1.0)\n\n    Score is usually 0.6-0.7 for survival models.\n\n    See:\n    Harrell FE, Lee KL, Mark DB. Multivariable prognostic models: issues in\n    developing models, evaluating assumptions and adequacy, and measuring and\n    reducing errors. Statistics in Medicine 1996;15(4):361-87.\n\n    Parameters:\n      event_times: a (n,) array of observed survival times.\n      predicted_event_times: a (n,) array of predicted survival times.\n      event_observed: a (n,) array of censorship flags, 1 if observed,\n                      0 if not. Default None assumes all observed.\n\n    Returns:\n      c-index: a value between 0 and 1.\n    ' #NEWLINE# event_times = np . array ( event_times , dtype = float ) #NEWLINE# predicted_event_times = np . array ( predicted_event_times , dtype = float ) #NEWLINE# if ( ( event_times . ndim == 2 ) and ( ( event_times . shape [ 0 ] == 1 ) or ( event_times . shape [ 1 ] == 1 ) ) ) : #NEWLINE# #INDENT# event_times = event_times . ravel ( ) #NEWLINE# #UNINDENT# if ( ( predicted_event_times . ndim == 2 ) and ( ( predicted_event_times . shape [ 0 ] == 1 ) or ( predicted_event_times . shape [ 1 ] == 1 ) ) ) : #NEWLINE# #INDENT# predicted_event_times = predicted_event_times . ravel ( ) #NEWLINE# #UNINDENT# if ( event_times . shape != predicted_event_times . shape ) : #NEWLINE# #INDENT# raise ValueError ( 'Event times and predictions must have the same shape' ) #NEWLINE# #UNINDENT# if ( event_times . ndim != 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'Event times can only be 1-dimensional: (n,)' ) #NEWLINE# #UNINDENT# if ( event_observed is None ) : #NEWLINE# #INDENT# event_observed = np . ones ( event_times . shape [ 0 ] , dtype = float ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( event_observed . shape != event_times . shape ) : #NEWLINE# #INDENT# raise ValueError ( 'Observed events must be 1-dimensional of same length as event times' ) #NEWLINE# #UNINDENT# event_observed = np . array ( event_observed , dtype = float ) . ravel ( ) #NEWLINE# #UNINDENT# return _concordance_index ( event_times , predicted_event_times , event_observed )