Course contentsShow
← Machine Learning and Deep Learning
Lesson 440 of 3,53810. Feature EngineeringFree lesson

Polynomial and Interaction Features

Generate polynomial terms and interactions between features to capture non-linear relationships in linear models.

Polynomial and Interaction Features

What you'll learn: How to transform your features into polynomial terms and interactions to help linear models capture non-linear patterns in data.

The Core Idea

Sometimes relationships in data aren't simple straight lines. Imagine predicting house prices: the relationship between square footage and price might accelerate (bigger houses get disproportionately more expensive). Or maybe bedrooms and bathrooms together matter more than either alone.

Polynomial features create powers of existing features (like squaring area to get area²). Interaction features multiply different features together (like bedrooms × bathrooms). These transformations let linear models—which can only draw straight decision boundaries—fit curved patterns.

Why This Matters

You've already learned linear models assume straight-line relationships. But real-world data often curves. Instead of switching to a complex model, you can engineer new features that represent these curves mathematically. A linear model can then fit them perfectly.

How It Works

Start with features like [x₁, x₂]:

  • Polynomial (degree 2): Add x₁² and x₂²
  • Interaction: Add x₁ × x₂
  • Combined: Transform [x₁, x₂] into [1, x₁, x₂, x₁², x₁×x₂, x₂²]

Now your "linear" model y = w₀ + w₁x₁ + w₂x₂ + w₃x₁² + w₄x₁x₂ + w₅x₂² can fit parabolas and other curves!

The Trade-off

Higher-degree polynomials (degree 3, 4, etc.) create many features fast. With 10 original features and degree 3, you might get hundreds of features—risking overfitting and computational cost. Use feature scaling (you've learned this!) before creating polynomials, since squared values explode in magnitude.

Key Takeaway: Polynomial and interaction features transform your data so linear models can capture non-linear relationships—turning curves into features the model can learn from directly.