internalsGet Pro

Module 11 · Lesson 3 of 13Pro

Encoding categories as numbers

Level
Beginner
Topic
Data preparation and feature engineering
Reading time
14 min

When you finish this page you can

  1. Explain why numbering categories invents an order that a linear model can’t undo.
  2. One-hot encode a category with scikit-learn, fitted on training rows only, and decide what an unseen value becomes.
  3. Target encode a category with many values, with smoothing and cross fitting so the label doesn’t leak.
  4. Choose an encoding for a category from its number of values and the model that reads it.
  1. Data, features and labels14 min
  2. Train, validation and test sets13 min
  3. Logistic regression: predicting probabilities13 min

Kochi can’t sit between Jaipur and Lucknow

is our example online store. Its ML team works on a notebook sample: about 1 million orders from 200,000 customers. Every Monday, a model ranks those customers by how likely they are to stop buying, and Joseph’s growth team sends vouchers to the top 20,000.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan