0
0
ML Pythonml~20 mins

Time series components (trend, seasonality) in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Time Series Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Identifying trend in a time series
Which of the following best describes the trend component in a time series?
ASudden spikes or drops caused by unexpected events
BRandom fluctuations that do not follow any pattern
CA repeating pattern that occurs at regular intervals, like daily or yearly cycles
DA long-term increase or decrease in the data values over time
Attempts:
2 left
💡 Hint
Think about whether the data is generally going up or down over a long period.
Predict Output
intermediate
2:00remaining
Output of seasonal decomposition
Given a time series with yearly seasonality and an upward trend, what will the seasonal component look like after decomposition?
ML Python
import numpy as np
import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose

time = pd.date_range(start='2020-01-01', periods=24, freq='M')
data = 10 + 0.5 * np.arange(24) + 3 * np.sin(2 * np.pi * np.arange(24) / 12)
series = pd.Series(data, index=time)
result = seasonal_decompose(series, model='additive', period=12)
seasonal = result.seasonal.round(2).tolist()
A[0.0, 1.5, 3.0, 1.5, 0.0, -1.5, -3.0, -1.5, 0.0, 1.5, 3.0, 1.5, 0.0, 1.5, 3.0, 1.5, 0.0, -1.5, -3.0, -1.5, 0.0, 1.5, 3.0, 1.5]
B[10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5, 20.0, 20.5, 21.0, 21.5]
C[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
D[5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5]
Attempts:
2 left
💡 Hint
Seasonal component repeats every 12 months and oscillates around zero.
Model Choice
advanced
1:30remaining
Choosing a model for trend and seasonality
You have monthly sales data with a clear upward trend and yearly seasonal peaks. Which model is best to capture both components?
AARIMA model without seasonal terms
BSARIMA model with seasonal order set to 12 months
CSimple Linear Regression on time index only
DK-Means clustering on sales values
Attempts:
2 left
💡 Hint
Consider models that explicitly handle seasonality.
Hyperparameter
advanced
1:00remaining
Selecting period parameter in seasonal decomposition
When using seasonal_decompose on daily data with weekly seasonality, what should the period parameter be set to?
A365
B30
C7
D12
Attempts:
2 left
💡 Hint
Think about how many days make a week.
Metrics
expert
2:00remaining
Evaluating model fit on decomposed components
After decomposing a time series into trend, seasonal, and residual components, which metric best measures how well the trend component fits the original data's long-term movement?
AMean Absolute Error (MAE) between original series and trend component
BRoot Mean Squared Error (RMSE) between seasonal component and original series
CR-squared value between residual component and original series
DAccuracy score comparing predicted and actual seasonal peaks
Attempts:
2 left
💡 Hint
Focus on measuring difference between trend and original data ignoring seasonality and noise.