> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracebloc.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Survival analysis (time-to-event)

> Dataset template for survival analysis: one CSV with covariates, a duration column and an event indicator, the required label policy, ingest.yaml and the checks the data ingestor runs.

Predict how long until an event happens, allowing for cases where it has not happened yet (censoring). The dataset is a single CSV where every row is one subject: covariate columns, a **duration** column and an **event indicator** column (1 = event observed, 0 = censored).

## Folder layout

```text theme={null}
/data/shared/survival/
└── survival.csv
```

## Data CSV

```csv theme={null}
age,anaemia,creatinine_phosphokinase,diabetes,ejection_fraction,high_blood_pressure,platelets,serum_creatinine,serum_sodium,sex,smoking,time,DEATH_EVENT
48,0,315,0,40,1,275841,1.6,131,0,1,225,0
78,0,3964,1,62,0,315081,0.9,135,0,0,5,1
64,0,2656,0,45,0,372021,3.0,142,0,1,13,1
```

| Column | Meaning |
| - | - |
| covariate columns | Declared in `schema` with their SQL type. |
| duration column (`time` here) | Name it `time`. Training reads only a column named `time`: a different name set with `time_column` ingests, but training cannot find it. Every value must be a number greater than 0. The ingestor accepts `0` and only warns on empty values, but training rejects both. Declared in `schema` like any other column. |
| event indicator (`DEATH_EVENT` here) | The label column, named by `label.column` and **not** declared in `schema`. Must be `0` (censored) or `1` (event). Other codes ingest, but training rejects them. |

## Ingest with the CLI

Pass the CSV file, or a folder that holds only that CSV. Ingest the training and the test split separately:

```bash theme={null}
tracebloc data ingest ./survival_train.csv --task time_to_event_prediction --name heart_failure_survival_train --intent train \
  --label-column DEATH_EVENT --time-column time --label-policy bucket --holds patient_data
tracebloc data ingest ./survival_test.csv --task time_to_event_prediction --name heart_failure_survival_test --intent test \
  --label-column DEATH_EVENT --time-column time --label-policy bucket --holds patient_data
```

`--holds patient_data` marks the dataset as patient data. Pass `--holds open_data` or `--holds synthetic_data` only when your data is open data or synthetic data. Leave `--holds` out on a terminal and the CLI asks; in a script, the dataset is marked as patient data. The mark decides which [use case types](https://docs.tracebloc.io/create-use-case/define.md#step-2-data-&-evaluation) you can create on the dataset.

`--time-column time` and `--label-policy bucket` are the defaults. The CLI infers a SQL type for every column, so `--schema` is optional. To set the types yourself, pass `--schema 'col:TYPE,col:TYPE'` and quote it, because a type such as `VARCHAR(64)` contains shell characters. `--schema` replaces the inferred schema: list every feature column you want stored, not just the ones you retype. Including the label column in `--schema` is fine: the ingestor drops it from the stored schema. The CLI has no flags for `time_unit` and `event_indicator`: they are optional and can only be set in `ingest.yaml`.

## ingest.yaml

```yaml theme={null}
apiVersion: tracebloc.io/v1
kind: IngestConfig
category: time_to_event_prediction
table: heart_failure_survival_train
intent: train
csv: /data/shared/survival/survival.csv
time_column: time          # the default; training reads only a column named time
time_unit: days
event_indicator:
  event: 1
  censored: 0
schema:
  age: INT
  anaemia: INT
  creatinine_phosphokinase: INT
  diabetes: INT
  ejection_fraction: INT
  high_blood_pressure: INT
  platelets: FLOAT
  serum_creatinine: FLOAT
  serum_sodium: INT
  sex: INT
  smoking: INT
  time: INT                # the duration column is declared like any other
label:
  column: DEATH_EVENT
  policy: bucket
```

| Field | Required | Meaning |
| - | - | - |
| `csv` | yes | Path to the data CSV. |
| `schema` | **yes** (with the CLI, inferred for you) | Covariates plus the duration column, with SQL types. Every schema column must exist in the CSV. |
| `label` | **yes, object form** | `column` names the event indicator; `policy` is required. `bucket` makes the platform receive hash buckets, not raw values — stored rows keep the raw indicator that training reads. `passthrough` sends raw values; use it only with a compliance sign-off. With `bucket`, the experiment's class counts show hash bucket ids instead of event and censored counts. |
| `time_column` | no | Name of the duration column. Default `time`. Matched exactly as written. Keep the default: training reads only `time`. |
| `time_unit` | no | `days`, `weeks`, `months` or `years`. Recorded so combined datasets are not compared across units. |
| `event_indicator` | no | `{event: 1, censored: 0}`. Recorded so a flipped convention across combined datasets is caught. It does not change the codes training accepts, which are always `1` and `0`. |
| `columns` | no | Per-column `unit` and `ordinal` facts. |
| `data_id`, `spec.csv_options` | no | See [the contract](https://docs.tracebloc.io/create-use-case/templates.md#the-ingest-yaml-contract). |

## What the ingestor checks

| Check | Rejects |
| - | - |
| Time to event | A CSV without the duration column (exact name); non-numeric duration values; negative durations. Empty durations produce a warning. |
| Data types | Duplicate headers, schema columns missing from the CSV, values that do not match their declared type, unknown SQL types. |

Plus the [checks every ingest runs](https://docs.tracebloc.io/create-use-case/templates.md#checks-every-ingest-runs). There is no label-diversity check.

## Sample dataset

The template ships 30 synthetic rows shaped like a heart-failure clinical dataset (no real patients): eleven covariates (`age`, `anaemia`, `creatinine_phosphokinase`, `diabetes`, `ejection_fraction`, `high_blood_pressure`, `platelets`, `serum_creatinine`, `serum_sodium`, `sex`, `smoking`), the duration `time` in days and the event indicator `DEATH_EVENT`. The covariates are linearly independent on purpose — a Cox proportional-hazards fit needs that. The rows shown above are its first rows, and the `ingest.yaml` above ingests it as is; only `csv:` changes to wherever you staged the file.

## Model settings for this dataset

When you link a model, the platform checks `num_feature_points` against the dataset (see [model parameters by task](https://docs.tracebloc.io/join-use-case/start-training.md#model-parameters-by-task)). It must equal the number of stored columns minus the event indicator, so the duration column counts. For the sample, that is 12, which matches the model-zoo default. `output_classes` is not checked for this task. Feature columns reach the model sorted by column name, whatever order the CSV or `schema` uses.

The lifelines and scikit-survival models, such as `cox_ph`, need the matching SDK extra. Without it, the local model check fails with `No module named 'lifelines'`:

```bash theme={null}
pip install "tracebloc[lifelines,scikit-survival]>=1.2.47"
```

## Next steps

* Ingest the data: [Prepare Data](https://docs.tracebloc.io/create-use-case/prepare-dataset.md)
* Shared rules for every template: [Dataset templates](https://docs.tracebloc.io/create-use-case/templates.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.