Time Series Analysis
Time Series Analysis deals with data collected over time - like daily stock prices or monthly sales - where the order of observations carries meaningful information.
Key Components of a Time Series
Trend: The long-term increase or decrease in the data
Seasonality: Regular, repeating patterns over a fixed period (e.g. daily, yearly)
Noise: Random variation that isn't explained by trend or seasonality
Visualizing a Time Series in Python
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
"Month": pd.date_range(start="2026-01-01", periods=12, freq="M"),
"Sales": [200, 220, 210, 250, 270, 300, 320, 310, 330, 360, 400, 420]
})
df.set_index("Month", inplace=True)
df["Sales"].plot(title="Monthly Sales")
plt.show()
A Simple Forecasting Approach
from statsmodels.tsa.holtwinters import ExponentialSmoothing
model = ExponentialSmoothing(df["Sales"], trend="add", seasonal=None)
fit = model.fit()
forecast = fit.forecast(3)
print(forecast)
Why Time Series Needs Special Handling
Standard machine learning models assume observations are independent, but time series data is inherently sequential - values are often correlated with their own past values, which regular models don't account for.
Coming Up Next
Next, you'll learn how Cross Sectional data differs from Time Series data.