kats.models.lstm module¶

The LSTM model stands for Long short-term memory, it is a recurrent neural network model that can be used for sequential data.

More information for the model can be found: https://en.wikipedia.org/wiki/Long_short-term_memory We directly adopt the PyTorch implementation and apply the model for time series forecast. More details for the PyTorch modules are here: https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html

class kats.models.lstm.LSTMForecast(params: kats.models.lstm.LSTMParams, input_size: int, output_size: int)[source]¶

Bases: torch.nn.modules.module.Module

Torch forecast class for time series LSTM model

This is the forecast class for time series LSTM model inherited from the PyTorch module, detailed implementation for the core LSTM and Linear modules can be gound here: https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html https://pytorch.org/docs/stable/generated/torch.nn.Linear.html

params¶

A LSTMParams instance for parameters

input_size¶

Input unit feature size for the LSTM layer

output_size¶

Output unit feature size from the output Linear layer

forward(input_seq: torch.Tensor)torch.Tensor[source]¶

The forward method for the LSTM forecast PyTorch module

Parameters

input_seq – A torch tensor contains the input data sequence for the LSTM layer

Returns

A torch tensor contains the output prediction from the output Linear layer

Return type

prediction

class kats.models.lstm.LSTMModel(data: kats.consts.TimeSeriesData, params: kats.models.lstm.LSTMParams)[source]¶

Bases: Generic[kats.models.model.ParamsType]

Kats model class for time series LSTM model

This is the Kats model class for time series forecast using the LSTM model

data¶

kats.consts.TimeSeriesData, the input data

params¶

A LSTMParams object for the parameters

fit(**kwargs)None[source]¶

Fit the LSTM forecast model

Parameters

None –

Returns

The fitted LSTM model object

static get_parameter_search_space()List[Dict[str, Any]][source]¶

Get default parameter search space for the LSTM model

Parameters

None –

Returns

A dictionary with the default LSTM parameter search space.

plot()[source]¶

Plot forecast results from the LSTM model

predict(steps: int, **kwargs)pandas.core.frame.DataFrame[source]¶

Prediction function for a multi-step forecast

Parameters

steps – number of steps for the forecast

Returns

A pd.DataFrame that includes the forecast and confidence interval

class kats.models.lstm.LSTMParams(hidden_size: int, time_window: int, num_epochs: int)[source]¶

Bases: kats.consts.Params

Parameter class for time series LSTM model

This is the parameter class for time series LSTM model, it currently contains three parameters

hidden_size¶

LSTM hidden unit size

time_window¶

Time series sequence length that feeds into the model

num_epochs¶

Number of epochs for the training process