Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Date and Time-Based Features | Section
Engineering Temporal Features

bookDate and Time-Based Features

Deslize para mostrar o menu

Extracting calendar-based features from date and time information is a powerful technique in temporal feature engineering. By breaking down a timestamp into components such as the day of the week, month, or whether it falls on a weekend, you can capture recurring patterns or seasonality that often drive changes in real-world data. These features are especially valuable in time series forecasting, where many phenomena – like sales, traffic, or energy usage – follow predictable cycles tied to the calendar. For example, demand might spike on weekends or drop during certain months, and models that incorporate this information can make more accurate predictions.

12345678910111213141516
import pandas as pd # Create a sample datetime index dates = pd.date_range(start="2024-06-01", end="2024-06-14", freq="D") df = pd.DataFrame(index=dates) # Extract day of week (Monday=0, Sunday=6) df["day_of_week"] = df.index.dayofweek # Extract month df["month"] = df.index.month # Determine if the date is a weekend (Saturday=5, Sunday=6) df["is_weekend"] = df.index.dayofweek >= 5 print(df)
copy
question mark

Why are calendar-based features, such as day of week or month, important when building time series forecasting models?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 6

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Seção 1. Capítulo 6
some-alt