Skip to content

Working out the features

H.P. Gansevoort edited this page Oct 16, 2026 · 4 revisions

Step 4 — Working out the features

In short

A feature is worked out from the columns as they stand, row by row, above the split. Nothing in this step learns from the data, which is why it may stand there. The one rule to remember: a feature must be what the split divides, not something added to one part of it.

You want to… Write
make a column from two others .AddFeature("warmth", "temp", Arithmetic.Minus, "hum")
put a date's day of the week and month on a circle .Cyclical(cyclical => cyclical.DayOfWeek("dteday").MonthOfYear("dteday"))
use another period of a date .HourOfDay(…), .DayOfMonth(…), .DayOfYear(…), .Season(…) on the same line
put a number that goes round on a circle of a length you say .Cycle("age", 7)
let the date go once its features are written .Drop("dteday") below the split, before what learns
drop the first rows an indicator cannot yet speak for .DropWarmUp()

The rest of this page explains each one.

Why features stand above the split

Work a feature out after the rows are divided and you have three slightly different feature sets, one per part, each made by its own code path.

using DeepSharp.Pipelines;

var prepared = Pdd.Create()
    .ReadCsv("bikes.csv")
    .Declare(schema => schema.Timestamp("dteday").Number("temp", "hum", "cnt"))
    .Cyclical(cyclical => cyclical                   // one line, a period a column
        .DayOfWeek("dteday")
        .MonthOfYear("dteday"))
    .AddFeature("warmth", "temp", Arithmetic.Minus, "hum")
    .SplitByTime("dteday", train: 0.70, validation: 0.15)
    .Target("cnt")
    .Drop("dteday")                                  // a moment is not a number a model takes
    .Normalise("temp", "hum", "warmth")
    .Build()
    .Run();

Console.WriteLine(string.Join(", ", prepared.Batch(Part.Train).FeatureNames));

Nothing here learns anything

warmth is one subtraction a row at a time. The day of the week is written as a place on a circle so that Monday and Sunday are neighbours, which is arithmetic on a date and not a fact about the data set.

That is why these may stand above the line and a mean may not.

The date stays behind

Once the day of the week and the month are written from dteday, it has done its work, and a moment is not a number a model takes. So it is dropped below the split, before what learns, and what was worked out from it stays.

A circle of any length

.Cyclical(…) puts a moment on a circle by a period. A number that goes round — an age in days around a week — has the same shape with a length you say: .Cycle("age", 7) writes age_cycle7_sin and age_cycle7_cos.

  • The length is declared, never taken from the data's largest value, because the largest value seen is not a period.
  • A weekday or a season as a plain number is refused where it is written, since neither has a number to be: use a circle, or categories.

The one thing to watch: gaps

A feature inherits the gaps of what it was made from. If temp had gaps, warmth would have them in the same rows, and nothing below the split reaches back into it.

That is the whole reason Settling the gaps comes before this step rather than after it. The handover will say so by name if you forget, naming the columns a feature came from rather than only that a gap is a gap.

Indicators

Indicators that read a window of rows — a moving average, a band — live in a package of their own and bring their own rule: the rows at the start that an indicator cannot yet speak for are dropped, above the split, by .DropWarmUp().

Next: Splitting the rows · Every feature verb, and the indicators: Pipeline

Clone this wiki locally