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

> Use a pretrained classification model to predict new categorical data. 

Usually employed after the `train_classification` step.
???+ info "Prediction Model"
To use this step successfully you need to make sure the dataset you're predicting on is
as similar as possible to the one the model was trained on. We check that the necessary data
types and columns are present, but you should pay attention to how you handled these in the
recipe the model was generated. Any changes might lead to a significant degradation in
model performance.

## 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 only predict the label of the class with the highest probability

      ```stan theme={null}
      predict_classification(ds, "my-model") -> (ds.predicted)
      ```
    </Tab>

    <Tab title="Example 2">
      To predict the label and its *corresponding* probability

      ```stan theme={null}
      predict_classification(ds, "my-model") -> (ds.predicted, ds.probability)
      ```
    </Tab>

    <Tab title="Example 3">
      To predict the most likely label but the probability of a *specific* class

      ```stan theme={null}
      predict_classification(ds, "my-model", {"positive_class": "some_label"}) -> (ds.predicted, ds.probability)
      ```
    </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_classification(ds: dataset, model: model_classification[ds], {
          "param": value,
          ...
      }) -> (*predicted: 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="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_classification[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">
    Column(s) containing the model predictions. If a single output column is provided,
    the model will output the predicted class. If two column names are provided, the model
    will additionally output the predicted probabilities.
  </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="positive_class" type="string">
    Name of the positive class.
    In *binary* classification, usually the class you're most interested in, for example the label/class
    corresponding to successful lead conversion in a lead score model, the class corresponding to a
    customer who has churned in a churn prediction model, etc.

    If provided, will return predicted probabilities for the positive class. If not provided, will return
    probabilities for the predicted class (i.e. the 'winning' class with the highest probability).
  </ParamField>
</Accordion>
