tempor.models.ts_model module¶
Model implementations for time-series model(s).
- tempor.models.ts_model.TSModelMode¶
Time series model ‘mode’, that is, the underlying architecture.
alias of
Literal[LSTM, GRU, RNN, Transformer, MLSTM_FCN, TCN, InceptionTime, InceptionTimePlus, XceptionTime, ResCNN, OmniScaleCNN, XCM]
-
class tempor.models.ts_model.TimeSeriesModel(task_type: Literal[classification] | Literal[regression], n_static_units_in: int, n_temporal_units_in: int, n_temporal_window: int, output_shape: list[int], n_static_units_hidden: int =
102, n_static_layers_hidden: int =2, n_temporal_units_hidden: int =102, n_temporal_layers_hidden: int =2, n_iter: int =500, mode: Literal[LSTM] | Literal[GRU] | Literal[RNN] | Literal[Transformer] | Literal[MLSTM_FCN] | Literal[TCN] | Literal[InceptionTime] | Literal[InceptionTimePlus] | Literal[XceptionTime] | Literal[ResCNN] | Literal[OmniScaleCNN] | Literal[XCM] ='RNN', n_iter_print: int =10, batch_size: int =100, lr: float =0.001, weight_decay: float =0.001, window_size: int =1, device: Any =device(type='cpu'), dataloader_sampler: Sampler | None =None, nonlin_out: list[tuple[Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax], int]] | None =None, loss: Callable | None =None, dropout: float =0.0, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu', random_state: int =0, clipping_value: int =1, patience: int =20, train_ratio: float =0.8, use_horizon_condition: bool =True)[source]¶ Bases:
ModuleBasic neural net for time series.
- Parameters:¶
- task_type : ModelTaskType¶
The type of the problem. Available options:
ModelTaskType.- n_static_units_in : int¶
Number of input units for the static data.
- n_temporal_units_in : int¶
Number of units for the temporal features.
- n_temporal_window : int¶
Number of temporal observations for each subject.
- output_shape : List[int]¶
Shape of the output tensor.
Number of hidden units for the static features. Defaults to
102.Number of hidden layers for the static features. Defaults to
2.Number of hidden units for the temporal features. Defaults to
102.Number of hidden layers for the temporal features. Defaults to
2.- n_iter : int, optional¶
Number of epochs. Defaults to
500.- mode : TSModelMode, optional¶
Core neural net architecture. Available options:
TSModelMode. Defaults to"RNN".- n_iter_print : int, optional¶
Number of epochs to print the loss. Defaults to
10.- batch_size : int, optional¶
Batch size. Defaults to
100.- lr : float, optional¶
Learning rate. Defaults to
1e-3.- weight_decay : float, optional¶
l2 (ridge) penalty for the weights. Defaults to
1e-3.- window_size : int, optional¶
How many hidden states to use for the outcome. Defaults to
1.- device : Any, optional¶
PyTorch device to use. Defaults to
DEVICE.- dataloader_sampler : Optional[sampler.Sampler], optional¶
Custom data sampler for training. Defaults to None.
- nonlin_out : Optional[List[Tuple[Nonlin, int]]], optional¶
List of activations for the output. Example
[("tanh", 1), ("softmax", 3)]- means the output layer will apply"tanh"for the first unit, and"softmax"for the following 3 units in the output. Defaults toNone.- loss : Optional[Callable], optional¶
Custom additional loss. Defaults to
None.- dropout : float, optional¶
Dropout value. Defaults to
0.0.- nonlin : Nonlin, optional¶
Activation for hidden layers. Available options:
Nonlin. Defaults to"relu".- random_state : int, optional¶
Random seed. Defaults to
0.- clipping_value : int, optional¶
Gradients clipping value. Zero disables the feature. Defaults to
1.- patience : int, optional¶
How many
epoch * n_iter_printto wait without loss improvement. Defaults to20.- train_ratio : float, optional¶
Train/test split ratio. Defaults to
0.8.- use_horizon_condition : bool, optional¶
Whether to predict using the observation times (
True) or just the covariates (False). Defaults toTrue.
- forward(static_data: Tensor, temporal_data: Tensor, observation_times: Tensor) Tensor[source]¶
Forward pass.
- predict(static_data: list | ndarray, temporal_data: list | ndarray, observation_times: list | ndarray) ndarray[source]¶
Make predictions.
- predict_proba(static_data: list | ndarray, temporal_data: list | ndarray, observation_times: list | ndarray) ndarray[source]¶
Predict probabilities.
- score(static_data: list | ndarray, temporal_data: list | ndarray, observation_times: list | ndarray, outcome: ndarray) float[source]¶
Get default model score.
- fit(static_data: list | ndarray, temporal_data: list | ndarray, observation_times: list | ndarray, outcome: list | ndarray) Any[source]¶
Fit (train) the model.
-
class tempor.models.ts_model.TimeSeriesLayer(n_static_units_in: int, n_temporal_units_in: int, n_temporal_window: int, n_units_out: int, n_static_units_hidden: int =
100, n_static_layers_hidden: int =2, n_temporal_units_hidden: int =100, n_temporal_layers_hidden: int =2, mode: str ='RNN', window_size: int =1, device: Any =device(type='cpu'), dropout: float =0, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu')[source]¶ Bases:
ModuleTime series layer implementation.
-
class tempor.models.ts_model.WindowLinearLayer(n_static_units_in: int, n_temporal_units_in: int, window_size: int, n_units_out: int, n_units_hidden: int =
100, n_layers: int =1, dropout: float =0, nonlin: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax] ='relu', device: Any =device(type='cpu'))[source]¶ Bases:
ModuleWindowed linear layer implementation.