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

bookDate and Time-Based Features

Scorri per mostrare il 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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Sezione 1. Capitolo 6
some-alt