energy_fault_detector.data_splitting.sequence_dataset
- class SequenceDatasetBuilder(sequence_length, ts_freq, stride=1, pad_incomplete=False, pad_value=0.0)[source]
Bases:
objectBuild sequence datasets from a time-series DataFrame with a DatetimeIndex.
This class provides two main dataset builders:
build_sliding_datasetfor seq2seq models (sequence → sequence),build_seq2one_datasetfor seq2one models (sequence → single timestep).
Timestamps are handled as datetime64[ns] (tz-naive, effectively UTC), and when mapping back we localize to the original tz.
Features:
Sliding windows with configurable overlap.
Data gaps handled via
DataGapHandler(windows crossing gaps are dropped, so windows represent contiguous data).Optional
conditional_featuressplit out as separate input sequences.
- Parameters:
sequence_length (
int) – Number of time steps in each sequence.ts_freq (
timedelta64) – Expected sampling frequency asnp.timedelta64.stride (
int) – Stride between consecutive windows (sequence_length = disjoint).pad_incomplete (
bool) – If True, resample to a regular grid and pad missing values withpad_valuebefore windowing.pad_value (
float) – Value to use when padding during resampling ifpad_incompleteis True.
- build_seq2one_dataset(df, batch_size, conditional_features=None, shuffle=True, predict_mode=False)[source]
Create a seq2one tf.data.Dataset from a time-series DataFrame.
Inputs are sequences of length
sequence_length, targets are the main features at the last timestep of each sequence.Supports a simple DatetimeIndex or a MultiIndex with exactly one datetime-like level. In the MultiIndex case, windows are built per group (first non-datetime level) and concatenated.
- Parameters:
df (
DataFrame) – Time-series data with DatetimeIndex, already preprocessed.batch_size (
int) – Batch size for the dataset.conditional_features (
Optional[List[str]]) – Optional list of column names to treat as conditional features.shuffle (
bool) – Whether to shuffle sequences (only relevant whentrainingis True).predict_mode (
bool) – If True, the dataset is used for inference. To ensure we can predict all timestamps, we set stride to 1. TODO: consider stride = sequence_length.
- Returns:
datasetis a tf.data.Dataset for training or inference,window_timestampsis an array of shape (n_windows, sequence_length) with timestamps for each window.
- Return type:
Tuple[DatasetV2,ndarray]
- build_sliding_dataset(df, batch_size, conditional_features=None, shuffle=True, predict_mode=False)[source]
Create a seq2seq tf.data.Dataset from a time-series DataFrame.
Supports a simple DatetimeIndex or a MultiIndex with exactly one datetime-like level. In the MultiIndex case, windows are built per group (first non-datetime level) and concatenated.
- Parameters:
df (
DataFrame) – Time-series data with DatetimeIndex, already preprocessed.batch_size (
int) – Batch size for the dataset.conditional_features (
Optional[List[str]]) – Optional list of column names to treat as conditional features.shuffle (
bool) – Whether to shuffle sequences (only relevant whentrainingis True).predict_mode (
bool) – If True, the dataset is used for inference. To ensure we can predict all timestamps, we set stride to 1. TODO: consider stride = sequence_length.
- Returns:
datasetis a tf.data.Dataset for training or inference,window_timestampsis an array of shape (n_windows, sequence_length)with timestamps for each window.
- Return type:
Tuple[DatasetV2,ndarray]