def test_prediction_methods_respect_index(self, data_pred2): x = data_pred2[['x1', 'x2']].ix[:3].sort_index(ascending=False) expected_index = pd.Index(np.array([3, 2, 1, 0])) cph = CoxPHFitter() cph.fit(data_pred2, duration_col='t', event_col='E') npt.assert_array_equal(cph.predict_partial_hazard(x).index, expected_index) npt.assert_array_equal(cph.predict_percentile(x).index, expected_index) npt.assert_array_equal(cph.predict_expectation(x).index, expected_index) aaf = AalenAdditiveFitter() aaf.fit(data_pred2, duration_col='t', event_col='E') npt.assert_array_equal(aaf.predict_percentile(x).index, expected_index) npt.assert_array_equal(aaf.predict_expectation(x).index, expected_index)
def test_cox_ph_prediction_monotonicity(self, data_pred2): # Concordance wise, all prediction methods should be monotonic versions # of one-another, unless numerical factors screw it up. t = data_pred2['t'] e = data_pred2['E'] X = data_pred2[['x1', 'x2']] cf = CoxPHFitter() cf.fit(data_pred2, duration_col='t', event_col='E') # Base comparison is partial_hazards ci_ph = concordance_index(t, -cf.predict_partial_hazard(X).values, e) ci_med = concordance_index(t, cf.predict_median(X).ravel(), e) assert ci_ph == ci_med ci_exp = concordance_index(t, cf.predict_expectation(X).ravel(), e) assert ci_ph == ci_exp
def test_cox_ph_prediction_monotonicity(self, data_pred2): # Concordance wise, all prediction methods should be monotonic versions # of one-another, unless numerical factors screw it up. t = data_pred2['t'] e = data_pred2['E'] X = data_pred2[['x1', 'x2']] for normalize in [True, False]: msg = ("Predict methods should get the same concordance" + " when {}normalizing".format('' if normalize else 'not ')) cf = CoxPHFitter(normalize=normalize) cf.fit(data_pred2, duration_col='t', event_col='E') # Base comparison is partial_hazards ci_ph = concordance_index(t, -cf.predict_partial_hazard(X).values, e) ci_med = concordance_index(t, cf.predict_median(X).ravel(), e) assert ci_ph == ci_med, msg ci_exp = concordance_index(t, cf.predict_expectation(X).ravel(), e) assert ci_ph == ci_exp, msg
def test_cox_ph_prediction_monotonicity(self, data_pred2): # Concordance wise, all prediction methods should be monotonic versions # of one-another, unless numerical factors screw it up. t = data_pred2['t'] e = data_pred2['E'] X = data_pred2[['x1', 'x2']] for normalize in [True, False]: msg = ("Predict methods should get the same concordance" + " when {}normalizing".format('' if normalize else 'not ')) cf = CoxPHFitter(normalize=normalize) cf.fit(data_pred2, duration_col='t', event_col='E') # Base comparison is partial_hazards ci_ph = concordance_index(t, -cf.predict_partial_hazard(X).values, e) ci_med = concordance_index(t, cf.predict_median(X).ravel(), e) assert ci_ph == ci_med, msg ci_exp = concordance_index(t, cf.predict_expectation(X).ravel(), e) assert ci_ph == ci_exp, msg