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

# predict_survival

> Use a pretrained model to predict new data. 

## Usage

The following examples show how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      Without configuration, the median survival time is returned.

      ```stan theme={null}
      predict_survival(ds, "surv-model") -> (ds.median_survival_time)
      ```
    </Tab>

    <Tab title="Example 2">
      To predict the survival time at the 0.75 percentile.

      ```stan theme={null}
      predict_survival(ds, "surv-model", {"kind": "percentile", "percentile": 0.75}) -> (ds.survival_time_75th_percentile)
      ```
    </Tab>

    <Tab title="Example 3">
      To predict the survival function at specific points in time.

      ```stan theme={null}
      predict_survival(ds, "surv-model", {"kind": "survival_function", "times": [1, 2, 3]}) -> (ds.survival_series)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      predict_survival(ds: dataset, model: model_survival[ds], {
          "param": value,
          ...
      }) -> (predicted: number)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="ds" type="dataset" required>
    Contains the target column and the rest of the columns you wish to use in the model.
  </ParamField>

  <ParamField path="model" type="file[model_survival[ds]]" required>
    File containing the model used to make the prediction.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="predicted" type="column[number]" required>
    Column containing the model predictions.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="kind" type="string" default="median">
    Kind of prediction.
    `median` returns the median survival time. `percentile` returns the survival time at
    the given percentile. `expectation` returns the expected survival time.
    `survival_function` returns the whole survival function (one series per sample).

    Values must be one of the following:

    * `median`
    * `percentile`
    * `expectation`
    * `survival_function`
  </ParamField>

  <ParamField path="percentile" type="number" default="0.5">
    Percentile when `kind` is set to `percentile`

    Values must be in the following range:

    ```javascript theme={null}
    0 ≤ percentile ≤ 1
    ```
  </ParamField>

  <ParamField path="times" type="[array, object]">
    Points in time to predict.
    Configures at which points to predict when `kind` is set to `survival_function`.
    Either an explicit array of durations, or an object specifying a duration step size and
    maximum duration.

    <Accordion title="Options">
      <Tabs>
        <Tab title="array">
          <ParamField path="{_}" type="array[number]">
            array.

            <Accordion title="Array items">
              <ParamField path="Item" type="number">
                Each item in array.
              </ParamField>
            </Accordion>
          </ParamField>
        </Tab>

        <Tab title="object">
          <ParamField path="step" type="number" default="1">
            Step size.

            Values must be in the following range:

            ```javascript theme={null}
            0 < step < inf
            ```
          </ParamField>

          <ParamField path="max" type="[number, null]">
            Maximum duration.
            If not provided, or `null`, the maximum duration in the dataset is used.
          </ParamField>
        </Tab>
      </Tabs>
    </Accordion>
  </ParamField>

  <ParamField path="conditional_after" type="boolean" default="false">
    Whether to predict remaining time.
    Conditions the predictions on known durations. In other words, the prediction is made for
    each sample taking into account that the sample has survived up to the duration in this column, and
    the prediction is made for the *remaining* time. This applies only to censored samples, where
    the event has not been observed. If the event *has* already been observed, on the other hand, predicted
    remaining time will be 0 / `null`.

    To use this feature, the `target` parameter must also be provided to identify the event and duration
    columns in the dataset.
  </ParamField>

  <ParamField path="target" type="array">
    Target variables.
    Two names, exactly, corresponding to the target columns that contain in the following order:

    1. whether the event was observed (boolean) and
    2. the time (duration) to event or censoring (number).

    <Accordion title="Array items">
      <ParamField path="Item 0" type="string (ds.column:boolean)" />

      <ParamField path="Item 1" type="string (ds.column:number)" />
    </Accordion>
  </ParamField>
</Accordion>
