2.1.10 · D1Data Preprocessing & Feature Engineering

Foundations — Feature creation and interaction terms

1,967 words9 min readBack to topic

This page assumes nothing. Every letter, subscript, and squiggle used in the parent note (the topic note) is unpacked here, one at a time, each building on the last. If a symbol confused you upstairs, it is defined below with a picture.


0. What a "feature" even is

Figure — Feature creation and interaction terms

Look at the figure. Each column is a feature (say temperature). Each row is a sample (one day's record). "Creating a feature" literally means drawing a new column whose values are computed from the existing ones. That is the entire game.


1. The letters: variables and subscripts

Picture a row of labelled boxes: box holds the temperature, box holds the rainfall. The subscript is just the address of a box.


2. Multiplication as a dot, and "×"

Why does the topic care so much about a humble multiply sign? Because multiplication is how you encode "it depends" — see §6.


3. The linear model: , , and

Figure — Feature creation and interaction terms

4. Why a straight line isn't enough — the curve problem

Real relationships bend. Crop yield rises with temperature, peaks, then falls when it's too hot. That shape is a hill, not a line — a straight line can never trace it.

Figure — Feature creation and interaction terms

Look at the two coloured curves. A positive weight on gives a valley (U); a negative weight flips it into a hill (∩) — exactly the "peaks in the middle" shape crop yield needs. This is why the topic adds as a new feature: it lets the straight-line machinery draw curves. That trick is called a polynomial feature.


5. The "choose" symbol

The parent counts how many new features appear. That count uses a special symbol.

Why does the topic need this symbol? To warn you: the feature count explodes as degree grows, which drives the "combinatorial explosion" mistake in the parent note.


6. The interaction: making a weight depend on another feature

This is the heart of the topic, so we build it fully.

Why multiplication and not, say, addition? Watch what algebra reveals. Group every term that contains :

Figure — Feature creation and interaction terms

In the figure, the two lines are the same feature at two settings of : same idea, different steepness. A model without the interaction is forced to use one slope for both — it literally cannot draw two.


7. Ratios, differences, and the divide bar


8. Reading the Haversine symbols (so they don't scare you)

The parent's distance formula uses two Greek letters you can now decode:

  • (phi) = latitude (how far north/south), (lambda) = longitude (how far east/west), = Earth's radius.
  • , , are trig functions that convert angle differences on a sphere into a straight-line-on-the-globe distance. You don't need to derive them here — just know each symbol names a real, pictured quantity (an angle or a radius), never a free-floating letter.

Prerequisite map

Data table rows and columns

Feature x and subscript i

Bold x the whole row

Multiply dot and cross

Linear model weights w and bias b

Straight line limitation

Power x squared curves

Polynomial features and degree

Choose symbol counts features

Interaction term x1 times x2

Effective slope depends on other feature

Ratio and difference features

Feature creation topic


Equipment checklist

Cover each answer and test yourself; reveal only after you've tried.

What does a subscript tell you?
Which feature — it is an address/label, not a maths operation.
How is different from ?
Low = which feature (label); high = power (multiply the feature by itself).
What do the bold and the plain each mean?
Bold is the whole row of features; plain is a single feature value.
In , what do and control on the graph?
is the line's steepness (slope); is its height where (intercept).
Why can't a linear model draw a hill shape?
A linear (straight-line) model has no term that bends — it needs a created feature like to curve.
What shape does draw, and how do you flip a U into a hill?
A parabola (U-shape); a negative weight flips it into a ∩ (hill).
What does count, and what is ?
The number of ways to choose items from ; .
Compute and say what it counts.
— the new degree-2 features for 2 inputs: .
Why is an interaction made by multiplying, not adding?
Multiplying makes the effective slope of one feature depend on the other — encoding "it depends."
What does a ratio give you that raw numbers don't?
A scale-free, relative value (e.g. burden relative to income) instead of absolute magnitude.
What do and stand for in the distance formula?
= latitude (north–south), = longitude (east–west).