A support team wants to predict whether a ticket will need escalation. One input is the channel where it arrived: chat, email, or phone. If you encode those categories as 0, 1, and 2, a linear model can treat the codes as equally spaced steps. The channel names have no such order.
One-hot encoding turns each observed category into a binary column. A ticket sets its channel’s column to 1 and the other channel columns to 0. The model can learn a separate association for each channel.
Encode three support ticket channels
Suppose the encoder learns these columns in order: channel_chat, channel_email, and channel_phone. An email ticket becomes [0, 1, 0]. A phone ticket becomes [0, 0, 1]. Each known value activates one column in this setup.
| Ticket channel | channel_chat | channel_email | channel_phone |
|---|---|---|---|
| chat | 1 | 0 | 0 |
| 0 | 1 | 0 | |
| phone | 0 | 0 | 1 |

If you also encode a priority field, it gets its own group of indicator columns. A single ticket can then have one active channel column and one active priority column. Numeric features such as ticket age can stay numeric.
Decide what happens when a new channel appears
The trained model expects the same columns and order every time. If the team adds a web form after training, keep the existing schema and apply a policy for the new value. Scikit-learn’s encoder raises an error by default. With handle_unknown="ignore", it produces zeros for all columns belonging to that feature. Scikit-learn OneHotEncoder reference.

Use a strict policy when an unfamiliar value signals a broken data feed. If new categories are expected, choose an explicit fallback and monitor how often it is used. Scikit-learn can map unknown values to an infrequent category when such a bucket was learned and handle_unknown="infrequent_if_exist" is enabled.
Try it with a short Python example
The encoder below learns three categories from training values. It keeps the column order when it transforms both a known phone ticket and a new web ticket. Dense output makes this tiny example easy to read.
from sklearn.preprocessing import OneHotEncoder
encoder = OneHotEncoder(handle_unknown="ignore", sparse_output=False)
encoder.fit([["chat"], ["email"], ["phone"]])
print(encoder.get_feature_names_out(["channel"]))
print(encoder.transform([["phone"], ["web"]]))
# channel_chat, channel_email, channel_phone
# [[0. 0. 1.]
# [0. 0. 0.]]
For a dataset with text categories and numeric columns, use a column transformer so each input receives the appropriate treatment. Put it inside the same pipeline as your estimator, then fit the whole pipeline on training data only. Scikit-learn example for mixed column types.
Fit on training data and reuse the encoder
Split the raw examples first. Learn categories and any rare-value grouping from the training fold, then apply that fitted encoder to validation and test records. In cross-validation, refit the pipeline inside each fold. Fitting preprocessing with access to held-out records can undermine the evaluation. How to find and fix data leakage and How to choose a cross-validation split.
Save the encoder with the trained model so the mapping stays stable after deployment. Check a few known and unknown inputs before launch, including missing values if the source permits them. Treat missing and unseen values according to the intended behavior.
When to keep all columns and when to reduce them
For unregularized linear regression with an intercept, keeping every indicator can make the columns linearly dependent. Dropping one category gives that group a reference level. Keep the estimator and its regularization in mind when choosing a convention. With a dropped reference level and ignored unknowns, both can produce an all-zero group. How logistic regression uses feature weights.
A field with thousands of distinct values can create thousands of columns. Use sparse storage when the estimator supports it. Consider grouping infrequent values if the individual categories carry too little evidence, and compare the result on held-out data.
Common questions
Is one-hot encoding good for ordered categories?
For levels such as low, medium, and high, an ordinal encoding can preserve rank. Check whether the model and the task make sense with that representation. One-hot encoding lets the model learn distinct effects without supplying that order.
How many columns does one-hot encoding create?
A feature with K learned categories creates K indicator columns by default. Rare-category grouping and dropped reference levels can reduce that number. Inspect the fitted encoder’s output feature names before deploying it.















