-
-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have crossval tests use predict_partial_hazard
Since other predict methods are numerically unstable atm, use predict_partial_hazard in k_fold_crossval tests. Since this method works, I could remove the outer loop and increase expected result because results are consistently good now (at .93 to 0.97). Signed-off-by: Jonas Kalderstam <jonas@kalderstam.se>
- Loading branch information
1 parent
9e10813
commit 12635b7
Showing
1 changed file
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1043,33 +1043,39 @@ def test_crossval_for_cox_ph_with_normalizing_times(self): | |
times /= np.std(times) | ||
data_norm['t'] = times | ||
|
||
mean_scores = [] | ||
for repeat in range(20): | ||
scores = k_fold_cross_validation(cf, data_norm, | ||
duration_col='t', | ||
event_col='E', k=3) | ||
mean_scores.append(np.mean(scores)) | ||
scores = k_fold_cross_validation(cf, data_norm, | ||
duration_col='t', | ||
event_col='E', k=3, | ||
predictor='predict_partial_hazard') | ||
|
||
expected = 0.85 | ||
mean_score = np.mean(scores) | ||
# partial_hazard will get inverse concordance | ||
if mean_score < 0.5: | ||
mean_score = 1 - mean_score | ||
|
||
expected = 0.9 | ||
msg = "Expected min-mean c-index {:.2f} < {:.2f}" | ||
self.assertTrue(np.mean(mean_scores) > expected, | ||
msg.format(expected, np.mean(mean_scores))) | ||
self.assertTrue(mean_score > expected, | ||
msg.format(expected, mean_score)) | ||
|
||
def test_crossval_for_cox_ph(self): | ||
cf = CoxPHFitter() | ||
|
||
for data_pred in [data_pred1, data_pred2]: | ||
mean_scores = [] | ||
for repeat in range(20): | ||
scores = k_fold_cross_validation(cf, data_pred, | ||
duration_col='t', | ||
event_col='E', k=3) | ||
mean_scores.append(np.mean(scores)) | ||
scores = k_fold_cross_validation(cf, data_pred, | ||
duration_col='t', | ||
event_col='E', k=3, | ||
predictor='predict_partial_hazard') | ||
|
||
expected = 0.85 | ||
mean_score = np.mean(scores) | ||
# partial_hazard will get inverse concordance | ||
if mean_score < 0.5: | ||
mean_score = 1 - mean_score | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
spacecowboy
Author
Collaborator
|
||
|
||
expected = 0.9 | ||
msg = "Expected min-mean c-index {:.2f} < {:.2f}" | ||
self.assertTrue(np.mean(mean_scores) > expected, | ||
msg.format(expected, np.mean(mean_scores))) | ||
self.assertTrue(mean_score > expected, | ||
msg.format(expected, mean_score)) | ||
|
||
def test_crossval_for_cox_ph_normalized(self): | ||
cf = CoxPHFitter() | ||
|
@@ -1093,16 +1099,19 @@ def test_crossval_for_cox_ph_normalized(self): | |
x2 /= np.std(x2) | ||
data_norm['x2'] = x2 | ||
|
||
mean_scores = [] | ||
for repeat in range(20): | ||
scores = k_fold_cross_validation(cf, data_norm, | ||
duration_col='t', | ||
event_col='E', k=3) | ||
mean_scores.append(np.mean(scores)) | ||
expected = 0.85 | ||
scores = k_fold_cross_validation(cf, data_norm, | ||
duration_col='t', | ||
event_col='E', k=3, | ||
predictor='predict_partial_hazard') | ||
|
||
mean_score = np.mean(scores) | ||
# partial_hazard will get inverse concordance | ||
if mean_score < 0.5: | ||
mean_score = 1 - mean_score | ||
expected = 0.9 | ||
msg = "Expected min-mean c-index {:.2f} < {:.2f}" | ||
self.assertTrue(np.mean(mean_scores) > expected, | ||
msg.format(expected, np.mean(mean_scores))) | ||
self.assertTrue(mean_score > expected, | ||
msg.format(expected, mean_score)) | ||
|
||
def test_output_against_R(self): | ||
# from http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf | ||
|
This is because partial hazards
are negativeI have no idea?