Documentation

    Encode

    Turn text categories into number codes or indicator columns for models or other numeric work. Choose Label for category codes, One-hot for separate category flags or Ordinal for categories with a meaningful order.

    Label

    Label turns a product category into codes for a model to predict, keeping the original text beside them. The One-hot and Ordinal examples below use their own data.

    The live example needs a desktop screen. The result it produces is shown here, and the explanation and settings below work on any screen.

    Result
    categorycategory_encoded
    Tea1
    Coffee0
    Tea1
    Coffee0
    1. Select the Encode block and select its output port. Label gives Coffee code 0 and Tea code 1 in category_encoded. The codes identify categories but don't rank them.

    One-hot

    One-hot keeps channel and adds channel_Web, channel_Store and channel_Phone. A Web row has 1 in channel_Web and 0 in the other two columns. The indicator columns follow first appearance in the input.

    The live example needs a desktop screen. The result it produces is shown here, and the explanation and settings below work on any screen.

    Result
    channelchannel_Webchannel_Storechannel_Phone
    Web100
    Store010
    Phone001
    Web100
    1. Select the Encode block and select its output port. Each row flags its channel, with no numeric ranking between channels.

    Ordinal

    Ordinal keeps priority and adds priority_ordinal. Low becomes 1, Medium becomes 2 and High becomes 3. Unlike the Label codes, these numbers stand for an order.

    The live example needs a desktop screen. The result it produces is shown here, and the explanation and settings below work on any screen.

    Result
    prioritypriority_ordinal
    Low1
    High3
    Medium2
    High3
    1. Select the Encode block and select its output port. Ordinal uses Levels set to High,Medium,Low, assigning priorities 3, 2 and 1.
    2. Select the red arrow Override defaults beside Levels, then change Levels to Low,Medium,High. The ranks reverse: Low gets 3 and High gets 1.

    When to use

    Use Encode when a model or calculation needs numbers but your column holds categories. Choose Label, One-hot or Ordinal depending on whether the categories have an order.

    Read the output

    Label keeps category and adds category_encoded. Coffee becomes 0 and Tea becomes 1, following text sort order. These are the two target classes to predict.

    One-hot keeps channel and adds channel_Web, channel_Store and channel_Phone. A Web row has 1 in channel_Web and 0 in the other two columns. The indicator columns follow first appearance in the input.

    Ordinal keeps priority and adds priority_ordinal. Low becomes 1, Medium becomes 2 and High becomes 3. Unlike the Label codes, these numbers stand for an order.

    Each flow keeps all five rows. Its missing value stays NULL in every encoded result, including all three One-hot indicators. Clearing Separate Columns removes the original text column and keeps the encoded results.

    Choose the order for Ordinal

    The first category in Levels gets the highest number, with ranks ending at 1. Enter the categories highest first: High,Medium,Low assigns 3, 2 and 1 in that order.

    Leaving Levels blank uses first appearance. In this example, Low appears first, so the automatic order would give it the highest rank. Levels you set must include every input category, or the block reports an error.

    To rescale existing numeric values, use Scale.

    To parse text that represents actual numbers, use Number.

    Inputs and outputs

    Inputs

    1 port
    InRequired

    Accepts: Tables, Geospatial data.

    Accepts one connection on this port.

    Outputs

    1 port
    Out

    Configure the block

    Choose a method for each text column and whether to keep its original values. A chosen column missing from the input is skipped with a warning, and its settings are kept.

    Method

    None leaves the column unchanged. Label assigns codes starting at 0 in text sort order. One-hot creates a 0/1 column per category. Ordinal assigns ranks using your chosen order. Default: None.

    Levels

    Shown for Ordinal. Enter categories separated by commas, highest rank first. Include every category present in the input, with no empty or repeated entries. Leave blank to use order of first appearance.

    Label all text / One-hot all text / Ordinal all text

    Apply the chosen method to every text column. Other column types remain unchanged. These buttons also clear any custom Levels.

    Clear all

    Set every column's method to None and clear custom Levels.

    Separate Columns

    Keep source columns and append results. Label uses _encoded, Ordinal uses _ordinal and One-hot adds the category to each column name. When cleared, results replace their source columns. Default: false.

    Encode FAQs

    When should I use Label encoding?
    Use Label mainly for a classification target. Two classes become 0 and 1, and each extra class gets the next code. For unordered input features, One-hot is usually better, because a model may read Label codes as an order or distance that doesn't exist.
    When should I use One-hot encoding?
    Use One-hot when categories have no natural order and you need separate numeric indicators, such as Web, Store and Phone sales channels. Each category gets its own column, so no category is represented as larger than another.
    When should I use Ordinal encoding?
    Use Ordinal when categories have a meaningful order, such as Low, Medium and High priority. Set Levels highest first to make the ranks reflect that order. The ranks show position only. They don't measure the distance between levels.
    What happens to missing values?
    NULL stays NULL. One-hot produces NULL in every indicator column for that row, rather than zeros. Every input row stays.
    Are Label codes fixed across different inputs?
    No. They're calculated from the categories in the current input. Adding or removing categories can change the codes.
    How many categories are supported?
    One-hot and Ordinal support at most 64 categories per column and report an error if none are present. Label has no 64-category limit.

    Prepare your data. Build it in Strata.

    Strata opens in your browser, with no account.