Esc
Ask AIAnswers may be inaccurate; check the linked pages.Esc
Ask anything about these docs, like how to get started or what a function does.

LstmHyperparams

chronax.models.lstm_model.LstmHyperparams · inherits PydanticBaseModel

Pydantic model defining the hyperparameters for the LstmModel.

Attributes

Attribute Type Default Description
units int 32 Number of LSTM units
layers int 2 Number of LSTM layers
dropout float 0.3 Dropout rate
learning_rate float - Learning rate for optimizer
batch_size int 32 Batch size for training
epochs int 500 Number of training epochs
context_length int 32 Context length
prediction_window int 8 Prediction window

LstmModel

chronax.models.lstm_model.LstmModel · inherits BaseModel

Multivariate LSTM model implementation. This model extends the univariate LSTM to handle multiple target variables simultaneously. It uses a single output layer that predicts forecast_horizon * n_targets values (flattened). Optional past and future covariates are concatenated on the feature axis. context_length and prediction_window are clamped during training to ensure at least one sliding window fits the available data.

__init__(self, params: Dict[str, Any], settings: Dict[str, Any])

Initializes the LstmModel, validating hyperparameters against LstmHyperparams.

Parameter Type Default Description
params Dict[str, Any] - (undocumented)
settings Dict[str, Any] - (undocumented)

train(self, y_context: np.ndarray, y_target: np.ndarray, timestamps_context: np.ndarray, timestamps_target: np.ndarray, x_context: Optional[np.ndarray] = None, x_target: Optional[np.ndarray] = None, **kwargs: dict) -> LstmModel

Train the Multivariate LSTM model on given data.

Uses sliding window, multi-step learning for multiple targets.

Parameter Type Default Description
y_context np.ndarray - Past target values, shape (num_steps, num_targets)
y_target np.ndarray - Future target values (for supervised labels)
timestamps_context np.ndarray - Timestamps for context (unused here)
timestamps_target np.ndarray - Timestamps for target (unused here)
x_context Optional[np.ndarray] None Optional covariates aligned with y_context
x_target Optional[np.ndarray] None Optional covariates aligned with y_target
**kwargs dict - Must include tuning_loss

Returns: LstmModel (the fitted model instance).

predict(self, y_context: np.ndarray, timestamps_context: np.ndarray, timestamps_target: np.ndarray, x_context: Optional[np.ndarray] = None, x_target: Optional[np.ndarray] = None, **kwargs: dict) -> np.ndarray

Make predictions with the trained Multivariate LSTM model.

Predicts the required number of steps ahead for all targets using non-overlapping multi-step windows. Does not use own predictions as further inputs for target channels (y); known future covariates are used when provided.

Parameter Type Default Description
y_context np.ndarray - Context/history values (n_steps, n_targets)
timestamps_context np.ndarray - Timestamps for context (unused)
timestamps_target np.ndarray - Timestamps for target (unused)
x_context Optional[np.ndarray] None Covariates aligned with y_context (required if model was trained with covariates)
x_target Optional[np.ndarray] None Future covariates aligned with timestamps_target (required if trained with covariates)
**kwargs dict - (undocumented)

Returns: np.ndarray (Model predictions with shape (forecast_steps, n_targets)).