Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Engineer Features for a Forecasting Task | Section
Engineering Temporal Features
Seksjon 1. Kapittel 11
single

single

bookChallenge: Engineer Features for a Forecasting Task

Sveip for å vise menyen

In this challenge, you will apply your knowledge of temporal feature engineering to a practical forecasting scenario. Imagine you are working with a daily sales dataset for a retail store, where each row represents the total sales for one day. Your goal is to prepare this data for a forecasting model by creating essential features that capture temporal patterns and seasonality, while carefully avoiding data leakage.

You need to engineer the following types of features:

  • Lag features that reference previous sales values;
  • Rolling window statistics that summarize recent sales trends;
  • Calendar-based features, such as the day of the week, to capture recurring patterns.

It is crucial to ensure that for each date, only information available up to that point in time is used to construct features. Missing values that result from lagging or rolling operations should be handled appropriately so that your model receives clean, informative inputs. This exercise will help reinforce the best practices for building robust, leakage-free time series features.

Oppgave

Swipe to start coding

You are given a DataFrame with daily sales and dates. Your task is to engineer features for time series forecasting.

  • Create lag features for the sales column with lags of 1 and 7 days.
  • Create rolling window features for the sales column: 7-day rolling mean and 7-day rolling standard deviation, using only past values (do not include the current day in the calculation).
  • Add a calendar feature for the day of the week, where Monday is 0 and Sunday is 6.
  • Handle missing values resulting from lag and rolling operations by filling them with -1.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 11
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt