What problem arises when using label encoding for nominal categorical variables in a linear model?

Quick Overview

Asks what goes wrong when nominal categories are mapped to integer codes and fed to a linear model. Tests whether you can explain the false order and spacing this imposes, why the fit depends on the code assignment, and how one-hot encoding, the dummy variable trap and high-cardinality encodings fit in.

What problem arises when using label encoding for nominal categorical variables in a linear model?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What problem arises when using label encoding for nominal categorical variables in a linear model? Label encoding maps each category to an integer, for example red=0, green=1, blue=2, and feeds that integer to the model as a single column. ```hint Write out the predictions Write the model's contribution for each category as a function of its integer code, and look at what shape that forces the category effects into. ``` ### What a Strong Answer Covers - What one coefficient on an integer code assumes about the order and spacing of the categories. - Why some patterns of category effects cannot be represented, and why the fit depends on how the codes were assigned. - The standard fix and how to avoid the dummy variable trap. - Options for high-cardinality categories. - Why tree models are less affected by label encoding. ### Follow-up Questions - With K categories and an intercept, how many dummy columns do you keep, and does that change when you add L2 regularization? - When is an integer encoding acceptable in a linear model? - How would you encode a feature with tens of thousands of distinct values for a linear model? - What should happen at serving time when a category appears that was never seen in training?

Overview: Asks what goes wrong when nominal categories are mapped to integer codes and fed to a linear model. Tests whether you can explain the false order and spacing this imposes, why the fit depends on the code assignment, and how one-hot encoding, the dummy variable trap and high-cardinality encodings fit in.

General logo
General
Nov 25, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

What problem arises when using label encoding for nominal categorical variables in a linear model? Label encoding maps each category to an integer, for example red=0, green=1, blue=2, and feeds that integer to the model as a single column.

What a Strong Answer Covers Guidance

  • What one coefficient on an integer code assumes about the order and spacing of the categories.
  • Why some patterns of category effects cannot be represented, and why the fit depends on how the codes were assigned.
  • The standard fix and how to avoid the dummy variable trap.
  • Options for high-cardinality categories.
  • Why tree models are less affected by label encoding.

Follow-up Questions Guidance

  • With K categories and an intercept, how many dummy columns do you keep, and does that change when you add L2 regularization?
  • When is an integer encoding acceptable in a linear model?
  • How would you encode a feature with tens of thousands of distinct values for a linear model?
  • What should happen at serving time when a category appears that was never seen in training?