Lesson 5 of 7

Features from Dates, Text and Geo

In Lesson 4 you gave a linear model the power to bend, with interactions and splines. Those tricks reshaped columns that were already numbers. This lesson goes one step earlier, to the columns that are not numbers at all.

Meet our running example. Priya runs dispatch at a bike-courier food-delivery service, and she wants to predict how long each delivery will take. Her table has ten orders, and three of its columns hold things a model cannot do arithmetic on: ordered_at is a timestamp like 2026-02-07 20:05, note is whatever the customer typed (say, "URGENT hand it to me directly"), and each order carries a pickup and a drop-off as raw latitude and longitude. A model only multiplies and adds, so as they stand these three columns are dead weight.

The widget below shows the whole job in one picture: the raw timestamp, note and coordinates on the left become tidy numeric feature columns on the right. That transformation is this entire lesson.

By the end you will be able to:

  • Pull calendar features out of a timestamp, and encode cyclical time so late night sits next to early morning
  • Turn a free-text note into numeric features a model can read
  • Collapse a pickup and a drop-off into one honest distance
  • Say which of these features are safe, and which can quietly leak the answer

Prerequisites: you can run R and read a data-frame column, you have dummy-coded a factor (Encoding Categorical Variables), and you have met target leakage (Target Encoding Without Leakage).

The shared problem

Three columns a model cannot read

Every model you have built in this course eats a table of numbers and multiplies each column by a weight. Hand it the text "URGENT hand it to me directly" and there is nothing to multiply. Same for a timestamp, and same for a latitude paired with a longitude. The information is clearly there, a human reads urgency, rush hour and a long crosstown trip at a glance, but it is locked in the wrong TYPE.

Feature engineering from these columns is always the same move: read the raw value and emit one or more numeric columns that carry its signal. The plan for the lesson is exactly three passes of that move, one per raw type:

  • Dates: a timestamp becomes hour, day-of-week, a weekend flag, and a cyclical encoding.
  • Text: a note becomes its length, a word count, and keyword flags.
  • Geo: a pickup and a drop-off become one distance, plus a landmark flag.

Then one last pass asks the question that runs through this whole course: which of these new features are safe, and which can leak.