Feature Engineering
This page covers the process of turning data that can't be computed directly, like images and text, into numeric columns.
Features and Derived Variables
A feature is each column, that is, each variable, that goes into an analysis or model. Feature engineering is creating useful new features from the raw data, and the columns made this way are called derived variables. Models can only handle numbers, so turning text, images, and dates into numbers takes up a large share of the work.
| Original | Feature created | Method |
|---|---|---|
| Image (28×28 array) | img_mean, img_std | Mean and standard deviation of pixel brightness for each image |
| Product name (text) | name_word_count, name_length | Number of words, number of characters |
| Quantity, unit price | amount | Quantity × unit price = order amount |
| Order date (date) | recency | Reference date - last purchase date (days) |
Turning Images into Numbers
One grayscale image is a grid of 28×28 cells, each holding a brightness value from 0 (black) to 255 (white). Collecting 60,000 of them gives a 3D array of shape (60000, 28, 28).
Image: preview of the image data from the A1-1 repository. Data source: Fashion-MNIST (MIT)
The mean value above each image is that image's mean brightness. The mean shows whether the clothing is bright or dark overall, and the standard deviation shows how strong the contrast is.
images.shape # (60000, 28, 28)
images.mean(axis=(1, 2)) # average the 28×28 cells of each image → array of length 60000
images.std(axis=(1, 2)) # standard deviation of each imageaxis=(1, 2) means "compute across the vertical and horizontal directions together." It keeps the first axis (image number) and reduces the rest, so you get one value per image.
Interview Questions
Q. What is feature engineering, and what features did you extract from the images?
This checks whether you can explain how you turned raw data into numbers, more than whether you know the term.
A feature is a variable that goes into an analysis or model, and feature engineering is creating useful new variables from the raw data. Models only handle numbers, so text and images have to be turned into numbers. In A1-1, each 28×28 image was reduced to two numbers, the mean and standard deviation of pixel brightness, and product names were turned into word counts and character counts. However, because the images were attached to products at random, the correlation coefficient between these features and the purchase amount was -0.012, almost nothing, so they were not used in the insights.
Source: dubu-alt/A1-1 (Codyssey AI Advanced A1-1 mission)
