print('*** Fitting with hyperparam:', hyperparam, flush=True) if num_durations > 0: surv_model.fit(X_train_std, y_train_discrete, batch_size, n_epochs, verbose=True) else: surv_model.fit(X_train_std, (y_train[:, 0], y_train[:, 1]), batch_size, n_epochs, verbose=True) surv_model.save_net(model_filename) else: print('*** Loading ***', flush=True) surv_model.load_net(model_filename) if num_durations > 0: surv_df = surv_model.interpolate(10).predict_surv_df(X_test_std) else: surv_df = surv_model.predict_surv_df(X_test_std) surv = surv_df.to_numpy().T print() print('[Test data statistics]') sorted_y_test_times = np.sort(y_test[:, 0]) print('Quartiles:') print('- Min observed time:', np.min(y_test[:, 0])) print('- Q1 observed time:', sorted_y_test_times[int(0.25 * len(sorted_y_test_times))]) print('- Median observed time:', np.median(y_test[:, 0])) print('- Q3 observed time:', sorted_y_test_times[int(0.75 * len(sorted_y_test_times))]) print('- Max observed time:', np.max(y_test[:, 0])) print('Mean observed time:', np.mean(y_test[:, 0])) print('Fraction censored:', 1. - np.mean(y_test[:, 1]))
print('Time elapsed: %f second(s)' % elapsed) np.savetxt(time_elapsed_filename, np.array(elapsed).reshape(1, -1)) surv_model.save_net(model_filename) else: print('*** Loading ***', flush=True) surv_model.load_net(model_filename) elapsed = float(np.loadtxt(time_elapsed_filename)) print('Time elapsed (from previous fitting): ' + '%f second(s)' % elapsed) if num_durations > 0: surv_df = \ surv_model.interpolate(10).predict_surv_df(fold_X_val_std) else: surv_df = surv_model.predict_surv_df(fold_X_val_std) ev = EvalSurv(surv_df, fold_y_val[:, 0], fold_y_val[:, 1], censor_surv='km') sorted_fold_y_val = np.sort(np.unique(fold_y_val[:, 0])) time_grid = np.linspace(sorted_fold_y_val[0], sorted_fold_y_val[-1], 100) surv = surv_df.to_numpy().T cindex_scores.append(ev.concordance_td('antolini')) integrated_brier_scores.append( ev.integrated_brier_score(time_grid)) print(' c-index (td):', cindex_scores[-1]) print(' Integrated Brier score:', integrated_brier_scores[-1])