Concepts / Features for Time Series Prediction

Features for Time Series Prediction

Time series prediction uses the past to forecast the future, so an honest evaluation must respect the direction of time.

  • Programming

Predicting Tomorrow From Today

Imagine a bike rental company that has recorded how many bikes were rented each hour over several weeks. The manager asks a practical question: given everything known about rentals up to now, how many bikes do we expect to be rented in the coming hours? Answering that question is the core task of time series prediction. The data arrives in a sequence, each observation is tied to a point in time, and the goal is to forecast what comes next.

What do you think happens?

The input feature for one prediction is the timestamp 2015-08-01 00:00:00. What time window does the output cover?

  • Only the single instant 00:00:00

  • The three hours that follow 00:00:00, from 00:00 up to 03:00

  • The three hours that came before 00:00:00

Reveal answer
Answer:

The three hours that follow 00:00:00, from 00:00 up to 03:00

The source defines the output as the number of rentals in the following three hours. Each prediction is a window that starts at the input timestamp and runs forward, not a single moment and not a window in the past.

Why Past Patterns Carry Information

Time series data is recorded in sequence, so the order of the observations carries meaning. Plot bike rentals over several days and a pattern appears almost immediately. The daytime hours and the nighttime hours of each 24-hour cycle look clearly different. Weekdays also seem to follow a different rhythm than weekends.

These regularities are exactly what makes forecasting possible. They suggest that what happened before carries information about what will happen next. A quiet night is usually followed by a quiet early morning, and a busy weekday afternoon tells you something about the afternoon that follows. Prediction works by exploiting this connection between the past and the future.

The central question of time series prediction is a question about direction. You take everything you know up to now and ask what you expect next. The model's job is to learn a mapping from earlier observations to later ones, and the evaluation must honestly reflect the fact that at prediction time the model can only look backward.

Choosing a Cutoff Date for the Split

To evaluate a forecaster honestly, the ordered dataset is divided at a cutoff date. The training set consists of all data up to the chosen date, and the test set consists of all data after that date. The cutoff is a deliberate choice that marks where the past ends and the prediction period begins.

Days 1 to 23184 points, training setCutoffbetween day 23 and day 24Days 24 to 3164 points, test setends attest begins
Where the cutoff date falls on the timeline, and which rows land before it (training) versus after it (test).

The reason for this rule follows directly from the goal of prediction. If the test set contained moments that happened earlier than some training moments, the model would be judged on a situation it could never face in practice, because a real forecaster does not know the future. A date-based cutoff keeps the test period entirely in the future relative to everything the model learned from.

The source applies this rule to its bike rental data. The first 184 data points, which correspond to the first 23 days, form the training set. The remaining 64 data points, which correspond to the remaining 8 days, form the test set. The cutoff falls between the 23rd day and the 24th day, so the model learns from the opening stretch of the record and is judged on the stretch that follows.

Input Feature and Output in the Bike Rental Setup

A forecasting task needs a precise statement of what goes in and what comes out. In the bike rental example, the only input feature is the date and time at which a given number of rentals occurred. The source gives the example timestamp 2015-08-01 00:00:00 as the input. Nothing else about the rentals, such as weather or station details, is used in this particular setup.

Input timestamp2015-08-01 00:00:00(feature)Following three hoursnumber of rentals (output)predicts
For a given prediction, the input timestamp supplies the feature and the three-hour window that follows supplies the target.
Worked example

Reading one prediction setup

A forecaster is given the timestamp 2015-08-01 00:00:00 and must predict rentals. Identify the feature, the output, and the time window the output describes.

  1. 1
    Identify the feature

    The only input feature is the date and time, so the feature is 2015-08-01 00:00:00.

  2. 2
    Identify the output

    The output is the number of rentals in the following three hours, not the number at a single moment.

  3. 3
    Locate the window

    The window starts at the input timestamp and runs forward three hours, so it covers 00:00 to 03:00 on 2015-08-01.

  4. 4
    Check what is excluded

    Weather and station details are not part of this setup, so the model is given no information beyond the timestamp.

Result

Feature: the timestamp 2015-08-01 00:00:00. Output: the count of rentals from 00:00 to 03:00. No other inputs are used.

Shuffling Versus Keeping Time Order

A common habit from other machine learning tasks is to shuffle rows randomly before splitting them into training and test sets. For a time series this habit breaks the setup. A random split can place rows from later dates into the training set and rows from earlier dates into the test set, so the model is tested on a past that it has already seen the future of.

Future rows intrainingfrom random mixingTraining ends atcutoffall training rows comefirstPast rows in testfrom random mixingTest lies aftercutoffno future rows in training
How a random shuffle puts future rows into training, compared with a split that keeps time order.

The chronological split keeps the test period entirely in the future relative to the training data. That matches the real situation, where a forecaster never has access to tomorrow's rentals when making today's prediction.

Common Errors That Make Evaluation Unrealistic

  • Common mistake

    Shuffling the rows before splitting

    What it looks like

    Randomly assigning each hourly row to train or test, so that a rental count from late August sits in training while an earlier day sits in test.

    Why it fails

    The model is trained on the future and then asked to predict the past, a situation a real forecaster never faces.

    Do this instead

    Split by a cutoff date so that every training row comes before every test row.

  • Common mistake

    Choosing a cutoff that lets test moments precede training moments

    What it looks like

    Taking a test set that starts earlier in the record than the last training points.

    Why it fails

    The test period overlaps the data the model learned from, which inflates the score.

    Do this instead

    Place the cutoff so the test period lies entirely after the training period.

  • Common mistake

    Changing the output window between training and evaluation

    What it looks like

    Training to predict rentals in the following three hours but scoring against a different time span.

    Why it fails

    The reported accuracy reflects a mismatch in what is being predicted rather than the model's quality.

    Do this instead

    Define the output as a fixed window that starts at the input timestamp and use the same definition throughout.

  • Common mistake

    Computing features from statistics over the whole dataset

    What it looks like

    Calculating an average rental count using every row, including those in the test period, and then using that average as an input for training rows.

    Why it fails

    Information from the test period flows back into the training features, so the model indirectly sees the future. This is a general leakage concern rather than a detail stated in the source.

    Do this instead

    Compute any feature using only data available up to the prediction time, and fit any summary statistics on the training portion alone.

Checking a Split for Honesty

MEDIUM

A dataset holds 31 days of hourly bike rental records. You choose a cutoff so that the first 23 days are training and the last 8 days are test. Explain, in your own words, why every test row lies after every training row, and say what would go wrong if a random shuffle were used instead.

Hints
  • Ask which rows the model is allowed to see when it makes a prediction on a test day.
  • Think about whether a random shuffle could place a later date in training and an earlier date in test.
  • The source's split uses 184 training points and 64 test points, covering 23 and 8 days.

Summary of the Forecasting Setup

  1. 1
    Time series prediction uses the past to forecast the future, so the evaluation must respect the direction of time.
  2. 2
    The training set holds all data up to a chosen cutoff date, and the test set holds all data after it.
  3. 3
    In the bike rental setup, the input feature is the date and time, and the output is the number of rentals in the following three hours.
  4. 4
    Random shuffling and features computed from the full dataset can let future information leak into training, making the evaluation unrealistic.

At a glance

  • Time series prediction uses the past to forecast the future, so an honest evaluation must respect the direction of time.
  • A date-based cutoff divides the ordered data: everything before it trains the model and everything after it tests the model.
  • In the bike rental example, the only input feature is the date and time, and the output is the number of rentals in the following three hours.
  • Random shuffling and feature statistics drawn from the whole dataset are common errors that make a time series evaluation unrealistic.

Related concepts

More concepts starting with F