๐ ๏ธ Scaler Design
August 29, 2025 ยท View on GitHub
๐ง What is a Scaler and Why Do We Need It?
A scaler is a class designed to handle the normalization and denormalization of data. In time series analysis, raw data often exhibits significant variations in scale. As a result, modelsโespecially deep learning modelsโtypically do not operate directly on the raw data. Instead, a scaler is used to normalize the data within a specific range, making it more suitable for modeling. When calculating loss functions or evaluation metrics, the data may be denormalized back to its original scale to ensure accurate comparison.
This makes the scaler an essential component in the time series analysis workflow.
๐พ How is the Scaler Initialized and When Does It Function?
The scaler is initialized alongside other components within the runner.
For example, a Z-Score scaler reads the raw data and computes the mean and standard deviation based on the training data.
The scaler functions after the data is extracted from the dataset. The data is first normalized by the scaler before being passed to the model for training. After the model processes the data, the scaler denormalizes the output before it is passed to the runner for loss calculation and metric evaluation.
Important
In many time series analysis studies, normalization often occurs during data preprocessing, as was the case in earlier versions of BasicTS. However, this approach is not scalable. Adjustments like changing input/output lengths, applying different normalization ways (e.g., individual normalization for each time series), or altering the training/validation/test split ratios would require re-preprocessing the data. To overcome this limitation, BasicTS adopts an "instant normalization" approach, where data is normalized each time it is extracted.
# in runner
for data in dataloader:
data = scaler.transform(data)
forward_return = forward(data)
forward_return = scaler.inverse_transform(forward_return)
๐งโ๐ง How to Select or Customize a Scaler
BasicTS provides several common scalers, such as the Z-Score scaler and Min-Max scaler. You can easily switch scalers by setting CFG.SCALER.TYPE in the configuration file.
If you need to customize a scaler, you can extend the basicts.scaler.BaseScaler class and implement the transform and inverse_transform methods. Alternatively, you can choose not to extend the class but must still implement these two methods.
๐งโ๐ป Explore Further
- ๐ Getting Stared
- ๐ก Understanding the Overall Design Convention of BasicTS
- ๐ฆ Exploring the Dataset Convention and Customizing Your Own Dataset
- ๐ ๏ธ Navigating The Scaler Convention and Designing Your Own Scaler
- ๐ง Diving into the Model Convention and Creating Your Own Model
- ๐ Examining the Metrics Convention and Developing Your Own Loss & Metrics
- ๐โโ๏ธ Mastering The Runner Convention and Building Your Own Runner
- ๐ Interpreting the Config File Convention and Customizing Your Configuration
- ๐ฏ Exploring Time Series Classification with BasicTS
- ๐ Exploring a Variety of Baseline Models