How to use the One-Hot Encoding Generator
- 1. Paste the valuesEnter one category per line, such as city or colour.
- 2. Choose optionsPick one-hot or dummy encoding, a prefix and column order.
- 3. DownloadPreview the 0/1 table and download it as CSV.
How it works
Most models need numbers, not text. One-hot encoding creates one column per category and puts a 1 in the column that matches each row and 0 elsewhere. Dummy encoding drops the first category: a row of all zeros then means that category.
Worked example: the values Red, Green, Blue, Green with prefix color give the columns color_Blue,color_Green,color_Red in alphabetical order, as pandas does. The first row, Red, becomes 0, 0, 1 and each Green row becomes 0, 1, 0.
Good practice
- Linear models: use dummy encoding (drop first) to avoid perfect multicollinearity, the dummy variable trap.
- Tree models such as random forests work fine with full one-hot columns.
- Many categories: hundreds of columns add noise. Group rare categories into "Other" or try target or frequency encoding.
- Unseen categories: fit the encoder on training data; in scikit-learn, use
OneHotEncoder(handle_unknown='ignore')so new values in production do not crash. - Ordered categories such as Low, Medium, High may be better as 1, 2, 3.
Values are matched exactly, so "Delhi" and "delhi" become separate columns; clean case and spaces first. Continue preparing features with the normalization calculator, then split with the train-test split calculator. The encoding runs in your browser, so the values you paste are never uploaded.
Frequently asked questions
How many categories can I encode?
Up to 100 distinct values and 5,000 rows here. More than that is rarely sensible for one-hot encoding.
Can I keep the original column?
Yes. The CSV includes the original value as its first column.
Is the One-Hot Encoding Generator free?
Yes, the One-Hot Encoding Generator is free. The first time you see your first result, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.