PyDLM

raw JSON →
0.1.1.13 verified Fri May 01 auth: no python maintenance

A Python library for Bayesian dynamic linear models (DLMs) for time series analysis. Current version 0.1.1.13, released 2024-07. Supports modeling, filtering, smoothing, and forecasting. Low release cadence, maintenance mode.

pip install pydlm
error ImportError: cannot import name 'dlm' from 'pydlm'
cause Outdated package or incorrect import path.
fix
Run pip install --upgrade pydlm and use from pydlm import dlm.
error AttributeError: module 'pydlm' has no attribute 'dlm'
cause Using `import pydlm` and then `pydlm.dlm`; the class is not exposed at module level.
fix
Use from pydlm import dlm.
error ValueError: Can not detect multivariate dimension from the data.
cause Data is not a list of floats or has unexpected dimension (e.g., 2D array).
fix
Pass a simple Python list: data = list(your_series).
gotcha The library expects 1D list-like data; passing a pandas Series may cause silent errors or shape mismatches.
fix Convert to list before passing: `data = series.tolist()`.
deprecated The `dlm.trend()` and `dlm.seasonal()` functions are part of the 'builder' API. Do not confuse with `trend` and `seasonal` as classes.
fix Use `dlm.trend(degree=1)` and `dlm.seasonal(period=4)` as static methods.
gotcha Missing component combination: you must add at least one component (trend, seasonal, or dynamic) before fitting; otherwise the model is degenerate.
fix Always include `dlm.trend(1)` as a minimum.
breaking In version 0.1.1.13, the `printInfo` method was replaced by logging. If you rely on console output being muted, use the new logging configuration.
fix Adjust logging level: `import logging; logging.getLogger('pydlm').setLevel(logging.WARNING)`.

Basic usage: create a DLM, add components, fit, and forecast.

from pydlm import dlm
import numpy as np

# Generate sample time series
data = [2.0, 2.5, 3.0, 3.5, 4.0]

# Create DLM with polynomial trend of order 1 and seasonal component 4
my_dlm = dlm(data) + dlm.trend(1) + dlm.seasonal(4)

# Fit the model
my_dlm.fit()

# One-step ahead predictions
predictions = my_dlm.predictN(N=1)
print(predictions)

# Access filtered states
filtered_states = my_dlm.getFilteredObs()
print(filtered_states)