Ejemplo n.º 1
0
                            np.array([compute_median_survival_time(mesh_points,
                                                                   surv_row)
                                      for surv_row in np.exp(-cum_haz)])
                        cindex = concordance_index(fold_y_val[:, 0],
                                                   predicted_medians,
                                                   fold_y_val[:, 1])
                    else:
                        raise NotImplementedError(
                            'Unsupported c-index method: %s' % cindex_method)
                    cindex_scores.append(cindex)

                    # ---------------------------------------------------------
                    # compute IPEC score using a few horizon times
                    #
                    fold_IPEC_scores = compute_IPEC_scores(
                        fold_y_train, fold_y_val, mesh_points, surv,
                        IPEC_horizons)
                    for idx, IPEC_horizon in enumerate(IPEC_horizons):
                        IPEC_scores[idx].append(fold_IPEC_scores[IPEC_horizon])

                cross_val_cindex = np.mean(cindex_scores)
                cross_val_IPEC_scores = {}
                for idx, q in enumerate(IPEC_percentiles):
                    cross_val_IPEC_scores[q] = np.mean(IPEC_scores[idx])
                # print('Bandwidth percentile: %5.4f, ' % bandwidth_percentile
                #       + 'c-index: %5.4f, ' % cross_val_cindex
                #       + ', '.join(['IPEC (%.2f): %5.4f'
                #                    % (q, cross_val_IPEC_scores[q] / horizon)
                #                    for q, horizon in
                #                    zip(IPEC_percentiles,
                #                        IPEC_horizons)]))
Ejemplo n.º 2
0
            predicted_medians = \
                np.array([compute_median_survival_time(mesh_points,
                                                       surv_row)
                          for surv_row in np.exp(-cum_haz)])
            test_cindex = concordance_index(y_test[:, 0],
                                            predicted_medians,
                                            y_test[:, 1])
        else:
            raise NotImplementedError('Unsupported c-index method: %s'
                                      % cindex_method)

        # ---------------------------------------------------------------------
        # compute IPEC score using a few horizon times
        #
        test_IPEC_scores = compute_IPEC_scores(y_train, y_test,
                                               mesh_points, surv,
                                               IPEC_horizons)
        print('c-index: %5.4f' % test_cindex
              + ', '
              + ', '.join(['IPEC (%.2f): %5.4f'
                          % (q, test_IPEC_scores[horizon] / horizon)
                          for q, horizon in
                          zip(IPEC_percentiles,
                              IPEC_horizons)]))

        csv_writer.writerow([dataset, experiment_idx, 'cox', test_cindex] +
                            [test_IPEC_scores[horizon] / horizon
                             for horizon in IPEC_horizons])

        print()
        print()