![]() |
VOOZH | about |
Time series data is a sequence of values recorded over time. It is widely used across industries to analyze patterns, monitor changes and make forecasts. Before modeling, it's important to check for key components in the data, such as trend, seasonality and cycles.
A trend is a long-term upward or downward movement in time series data. It is observed as an increasing or decreasing slope over a period of time. Trends usually last for a while but do not repeat regularly.
Example: A new song may trend for a few weeks (uptrend) and then fade away.
Trends can be detected visually or through decomposition of the dataset.
By simply plotting the dataset you can see the general trend in data.
Approach:
Note: In the examples given below the same code is used to show all three trends just the dataset used is different to reflect that particular trend.
To Download the csv file used in this article, click here
Example: Uptrend
Output
Explanation:
Example: Downtrend
Output
Example: Horizontal Trend
Output
Linear plots may not always show the full trend clearly. The seasonal_decompose() function from statsmodels can break a time series into trend, seasonality, and residual components. We can access the trend component using seasonal_decompose().trend. This function estimates the trend using moving averages, helping to reveal the long-term pattern hidden in the data.
statsmodels.tsa.seasonal.seasonal_decompose(x, model='additive', period=None, extrapolate_trend=0)
Parameters:
Returns: An object with seasonal, trend, and resid attributes.
Example:
Output