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

# trim_frequencies

> Remove values whose frequencies (counts) are above/below a given threshold. 

Affected categories are replaced with the missing value (NaN).

## 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">
      To remove categories ocurring fewer than 2 times in the column `cat_col`:

      ```stan theme={null}
      trim_frequencies(ds.cat_col, {"freq_min": 2}) -> (ds.cat_trimmed)
      ```
    </Tab>

    <Tab title="Example 2">
      To only keep the 10 most frequent categories in column `cat_col`:

      ```stan theme={null}
      trim_frequencies(ds.cat_col, {"n_most_common": 10}) -> (ds.cat_top10)
      ```
    </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}
      trim_frequencies(input: category|list[category], {
          "param": value,
          ...
      }) -> (output: column)
      ```
    </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[category|list[category]]" required>
    A categorical column to trim.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="output" type="column" required>
    A categorical column with fewer categories than the input.
  </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="n_most_common" type="[integer, null]">
    The number N indicating how many of the most common values to filter (in descending order).

    Values must be in the following range:

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

  <ParamField path="freq_min" type="[integer, null]">
    Values with a lower frequency (count) than this will be removed.

    Values must be in the following range:

    ```javascript theme={null}
    1 ≤ freq_min < inf
    ```
  </ParamField>

  <ParamField path="freq_max" type="[integer, null]">
    Values with a higher frequency (count) than this will be removed.

    Values must be in the following range:

    ```javascript theme={null}
    1 ≤ freq_max < inf
    ```
  </ParamField>
</Accordion>
