> ## 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.

# discretize_on_quantiles

> Discretize column into bins based on quantiles. 

Quantiles can be defined as an array of cut points (e.g., \[0.25, 0.5, 0.75]) or as a number indicating the desired number of bins.
Each bin can optionally be assigned a label.

## 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">
      The following parameters will discretize a column with values in the range \[0, 1], producing a new categorical column with bins defined by the borders \[0, 0.25), \[0.25, 0.5), \[0.5, 0.75) and \[0.75, 1]. The bins will have labels "q1", "q2", "q3" and "q4" respectively.

      ```stan theme={null}
      discretize_on_quantiles(ds.price, {
          "quantiles": [0.25, 0.5, 0.75],
          "labels": ["q1", "q2", "q3", "q4"]
      }) -> (ds.price_category)
      ```
    </Tab>

    <Tab title="Example 2">
      The following parameters will discretize a column into 4 equally sized bins.

      ```stan theme={null}
      discretize_on_quantiles(ds.age, {
          "quantiles": 4
      }) -> (ds.age_category)
      ```
    </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}
      discretize_on_quantiles(input: number, {
          "param": value,
          ...
      }) -> (output: category)
      ```
    </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="input" type="column[number]" required>
    A numeric column to discretize.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="output" type="column[category]" required>
    A new categorical column with categories corresponding to discretized bins.
  </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="quantiles" type="[integer, array[number]]" default="[0.25, 0.5, 0.75]">
    Quantiles.
    Defines the quantiles or number of bins for discretizing the column.
    Can be an array of cut points or a number indicating the number of bins.

    Values must be in the following range:

    ```javascript theme={null}
    2 ≤ quantiles < inf
    ```

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

        Values must be in the following range:

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

    <Accordion title="Examples">
      * 4
      * \[0.25, 0.5, 0.75]
    </Accordion>
  </ParamField>

  <ParamField path="labels" type="array[string]" default="['q1', 'q2', 'q3', 'q4']">
    Names for the resulting bins.
    Needs one more label than the number of quantile cut points.

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

    <Accordion title="Examples">
      * \['Q1', 'Q2', 'Q3', 'Q4']
    </Accordion>
  </ParamField>
</Accordion>
