Course contentsShow
← Data Science
Lesson 645 of 2,14517. Categorical Predictors and InteractionsFree lesson

Changing the Reference Category

How to manually set a different reference level and when reordering categories improves interpretation.

Changing the Reference Category

You'll learn how to manually switch which category serves as your baseline and why doing so can make your model easier to understand.

The Core Idea

When you encode categorical variables as dummies, one category becomes the "reference" that all others are compared against. By default, software often picks alphabetically or uses the first category it encounters. But you control this choice—and sometimes changing the reference category dramatically improves how you interpret your results.

Think of it like changing the "zero point" on a ruler. If you're measuring heights of buildings, you could measure from sea level or from the city's average elevation. The measurements change, but the relative differences stay the same.

When and Why to Change Reference Categories

Choose a meaningful baseline:

  • Use the most common category (like "No treatment" in medical studies)
  • Pick a natural control group (like "Standard process" in manufacturing)
  • Select the category stakeholders care about comparing against

Example: If you're analyzing salaries across departments (Sales, Engineering, Marketing, HR), setting Engineering as reference makes sense if you're specifically asking "How do other departments compare to Engineering?"

How to Do It

In Python with pandas, you can reorder categories before creating dummies:

# Make 'Engineering' the reference by ensuring it comes first
df['department'] = pd.Categorical(df['department'], 
                                  categories=['Engineering', 'Sales', 'Marketing', 'HR'])

This ensures Engineering gets dropped (becomes reference) when you create dummy variables.

Key Takeaway: The reference category is your baseline for comparison—choose it thoughtfully based on what makes your coefficients easiest to interpret and most meaningful to your audience. Changing it doesn't change your model's predictions, only how you explain them.