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

Creating Polynomial Terms

Generate polynomial features by raising predictors to powers and understand notation like X² and X³ in regression equations.

Creating Polynomial Terms

What you'll learn: How to generate polynomial features by raising predictors to powers (X², X³, etc.) in your regression models.


The Core Idea

Creating polynomial terms means taking an existing predictor variable and raising it to a power—squaring it, cubing it, or beyond. For example, if you have a predictor X, you can create X² (X-squared) or X³ (X-cubed) as new features in your dataset.

Why do this? Sometimes the relationship between your predictor and outcome isn't a straight line. Temperature might affect ice cream sales in a curved pattern, or advertising spend might show diminishing returns. Polynomial terms let your linear regression model capture these curves.

The Notation

In a regression equation, polynomial terms look like this:

y = β₀ + β₁X + β₂X² + β₃X³ + ...

Here, X² means "X times itself," and X³ means "X times itself times itself." Each polynomial term gets its own coefficient (β₁, β₂, β₃), just like any other predictor.

Generating the Terms

To create polynomial terms, you literally compute the powers:

  • Original variable: [2, 3, 5]
  • Squared (²): [4, 9, 25]
  • Cubed (³): [8, 27, 125]

You add these new columns to your dataset alongside the original variable. The regression algorithm treats them as separate predictors, even though they're mathematically related.

Think of It Like...

Imagine describing a ball's arc when thrown. A straight line can't capture that curve, but adding X² gives your model the flexibility to bend into a parabola—matching reality better.

Key Takeaway: Polynomial terms are created by raising predictors to powers (X², X³) and adding them as new features, allowing linear regression to model curved relationships.