def test_likelihood_efron(rossi, coef_rossi_coxph_efron): cph = CoxPHOptimizer(rossi.x.values, rossi.y['arrest'], rossi.y['week'], alpha=0., ties="efron") w = coef_rossi_coxph_efron.loc[rossi.x.columns].values actual_loss = cph.nlog_likelihood(w) assert round(abs(658.7477 - rossi.x.shape[0] * actual_loss), 4) == 0
def test_likelihood_breslow(rossi, coef_rossi_coxph_breslow): cph = CoxPHOptimizer(rossi.x.values, rossi.y['arrest'], rossi.y['week'], alpha=0., ties="breslow") w = coef_rossi_coxph_breslow.loc[rossi.x.columns].values actual_loss = cph.nlog_likelihood(w) assert round(abs(659.1206 - rossi.x.shape[0] * actual_loss), 4) == 0
def test_gradient_breslow(rossi): cph = CoxPHOptimizer(rossi.x.values, rossi.y['arrest'], rossi.y['week'], alpha=numpy.zeros(rossi.x.shape[1]), ties="breslow") assert_gradient_correctness(cph)
def test_gradient_efron(rossi): cph = CoxPHOptimizer(rossi.x.values.astype(float), rossi.y['arrest'], rossi.y['week'], alpha=numpy.zeros(rossi.x.shape[1]), ties="efron") assert_gradient_correctness(cph)
def test_likelihood(self): cph = CoxPHOptimizer(self.x.values, self.y['arrest'], self.y['week'], alpha=0.) w = pandas.Series({ "fin": -0.37902189, "age": -0.05724593, "race": 0.31412977, "wexp": -0.15111460, "mar": -0.43278257, "paro": -0.08498284, "prio": 0.09111154 }) actual_loss = cph.nlog_likelihood(w.loc[self.x.columns].values) self.assertAlmostEqual(659.1206, self.x.shape[0] * actual_loss, 4)
def test_likelihood(rossi): cph = CoxPHOptimizer(rossi.x.values, rossi.y['arrest'], rossi.y['week'], alpha=0.) w = pandas.Series({ "fin": -0.37902189, "age": -0.05724593, "race": 0.31412977, "wexp": -0.15111460, "mar": -0.43278257, "paro": -0.08498284, "prio": 0.09111154 }) actual_loss = cph.nlog_likelihood(w.loc[rossi.x.columns].values) assert round(abs(659.1206 - rossi.x.shape[0] * actual_loss), 4) == 0