def predict_surv_df(self, input, batch_size=8224, eval_=True, to_cpu=False, num_workers=0): """Predict the survival function for `input` and return as a pandas DataFrame. See `predict_surv` to return tensor or np.array instead. Arguments: input {tuple, np.ndarray, or torch.tensor} -- Input to net. Keyword Arguments: batch_size {int} -- Batch size (default: {8224}) eval_ {bool} -- If 'True', use 'eval' mode on net. (default: {True}) num_workers {int} -- Number of workers in created dataloader (default: {0}) Returns: pd.DataFrame -- Predictions """ surv = self.predict_surv(input, batch_size, True, eval_, to_cpu, num_workers) index = None if self.duration_index is not None: index = utils.make_subgrid(self.duration_index, self.sub) return pd.DataFrame(surv.transpose(), index)
def predict_surv_df(self, input, batch_size=8224, eval_=True, num_workers=0): self._check_out_features() surv = self.predict_surv(input, batch_size, True, eval_, True, num_workers) index = None if self.duration_index is not None: index = make_subgrid(self.duration_index, self.sub) return pd.DataFrame(surv.transpose(), index)
def test_make_subgrid(sub, start, stop, n): grid = np.linspace(start, stop, n) new_grid = make_subgrid(grid, sub) true_new = np.linspace(start, stop, n * sub - (sub - 1)) assert len(new_grid) == len(true_new) assert np.abs(true_new - new_grid).max() < 1e-13
def test_make_subgrid_1(n): grid = np.random.uniform(0, 100, n) grid = np.sort(grid) new_grid = make_subgrid(grid, 1) assert len(new_grid) == len(grid) assert (new_grid == grid).all()