Lesson 2 of 3 Feature Engineering

Reshaping Features with Binning, Log Transforms and Feature Splitting

This lesson explains three feature engineering techniques named in the exam guide, binning, log transformation and feature splitting, which make features more useful by changing their shape or breaking them into parts.

Learning outcomes

After completing this lesson, you will be able to:

  • Apply a log transformation to skewed values.
  • Distinguish fixed-width from quantile binning.
  • Split compound values such as timestamps into features.

Log transformation

Values such as income, house prices, transaction amounts and counts are often right-skewed: most values are small and a few are very large. A log transformation (for example, log(1 + x) to handle zeros) compresses large values and makes the distribution closer to normal, which helps linear models and reduces the influence of extreme values. Predictions made on a log-transformed target must be transformed back with the inverse function.

The following diagram shows the transformation applied to each raw feature of a taxi tip prediction model.

The feature transformations for the taxi tip model. The skewed fare becomes log(1 + fare), the raw timestamp is split into hour, day of week and a weekend flag with hour encoded as sine and cosine, and trip distance is binned into quantiles, so a simple linear model can learn rush-hour, weekend and short-trip patterns.
The scenario is illustrative.

Binning

Binning, also called bucketing or discretisation, groups continuous values into ranges. Fixed-width bins use equal ranges, such as ages 0 to 9, 10 to 19 and so on. Quantile bins put an equal number of records in each bin, which handles skewed data well, because a few extreme values do not leave most bins empty.

Binning helps in several ways. It lets linear models capture non-linear effects, such as risk that rises sharply above a certain age; it reduces the influence of noise and outliers; and it makes features easier to explain. The cost is lost detail, because all values within a bin are treated as the same.

Match the pairs

Choose the transformation

Exam skills 1.2.4

Match each feature problem with the transformation that addresses it.

Log in to try this activity Interactive activities are free with an account.

Feature splitting

Feature splitting breaks a compound value into meaningful parts. A timestamp can become hour of day, day of week, month and an is-weekend flag, which expose daily and weekly patterns. An address can become city and postal code; a product code such as ELEC-TV-55 can become category, subcategory and size. Cyclical parts such as hour can be encoded with sine and cosine so that 23:00 and 00:00 are close.

The following table summarises the three techniques.

TechniqueUse whenExample
Log transformationRight-skewed positive valueslog(1 + income)
Fixed-width binningNatural equal rangesAge in 10-year bands
Quantile binningSkewed values, equal-sized groupsSpend in quartiles
Feature splittingCompound values hide patternsTimestamp into hour, weekday, month
Select all that apply

Split the timestamp

Exam skills 1.2.4

Identify the useful features that can be split out of a pickup timestamp for a taxi demand model.

Log in to try this activity Interactive activities are free with an account.
Worked example

Predicting taxi tips

A linear model predicts taxi tips from fare amount and pickup time. Fare is heavily skewed (most trips under 20, some over 300), and the raw timestamp gives the model no useful signal.

  • Apply log(1 + fare) so a few long airport trips do not dominate the fitted line.
  • Split the timestamp into hour, day of week and is_weekend; encode hour with sine and cosine.
  • Bin trip distance into quantiles to capture the non-linear effect of short trips.

These changes let a simple, interpretable model learn the rush-hour and weekend patterns that were hidden in the raw timestamp.

Check yourself

Which transformation suits right-skewed values such as income?

Show answer

A log transformation, which compresses the long tail.

Exam Tips

Remember for the exam

  • Right-skewed values: log transformation.
  • Quantile binning handles skewed distributions.
  • Split timestamps into hour, weekday and month.
  • Encode cyclical features with sine and cosine.
  • Invert the log transform when predicting a log-transformed target.