Пример #1
0
 def test_predict_log_hazard_relative_to_mean_without_normalization(self, rossi):
     cox = CoxPHFitter(normalize=False)
     cox.fit(rossi, 'week', 'arrest')
     log_relative_hazards = cox.predict_log_hazard_relative_to_mean(rossi)
     means = rossi.mean(0).to_frame().T
     assert cox.predict_partial_hazard(means).values[0][0] != 1.0  
     assert_frame_equal(log_relative_hazards, np.log(cox.predict_partial_hazard(rossi) / cox.predict_partial_hazard(means).squeeze()))
Пример #2
0
    def test_predict_log_hazard_relative_to_mean_with_normalization(self, rossi):
        cox = CoxPHFitter(normalize=True)
        cox.fit(rossi, 'week', 'arrest')

        # they are equal because the data is normalized, so the mean of the covarites is all 0,
        # thus exp(beta * 0) == 1, so exp(beta * X)/exp(beta * 0) = exp(beta * X)
        assert_frame_equal(cox.predict_log_hazard_relative_to_mean(rossi), np.log(cox.predict_partial_hazard(rossi)))
Пример #3
0
 def test_predict_log_hazard_relative_to_mean(self, rossi):
     cox = CoxPHFitter()
     cox.fit(rossi, 'week', 'arrest')
     log_relative_hazards = cox.predict_log_hazard_relative_to_mean(rossi)
     means = rossi.mean(0).to_frame().T
     assert_frame_equal(log_relative_hazards, np.log(cox.predict_partial_hazard(rossi) / cox.predict_partial_hazard(means).squeeze()))