N-HiTS › Practical Implications

Michael BrenndoerferAugust 23, 20259 min read
Machine Learning from ScratchAll chapters
Part 8 of 9Time Series
Chapter 61N-HiTS › Practical Implications
Reading section 6 of 8 · Practical Implications · 9 minSection 6 of 8 · 9 min

Book contents

Section 6 of 8 · 9 min read

N-HiTS › Practical ImplicationsOne section · Sections in this chapter6 / 8 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

NHITS is particularly effective for time series that exhibit patterns at multiple temporal scales simultaneously. In retail forecasting, sales data typically contains daily promotional effects, weekly shopping patterns, monthly seasonality, and yearly trends. The hierarchical decomposition allows NHITS to process each scale separately, enabling the model to capture both short-term fluctuations and long-term dynamics without one overwhelming the other. This multi-scale capability makes NHITS well-suited for energy consumption forecasting, where hourly usage patterns interact with daily routines, weekly work cycles, and seasonal weather variations.

The method also gives interpretability advantages over standard deep learning approaches. The learned hierarchical combination weights reveal which temporal scales contribute most to predictions, showing whether short-term volatility or long-term trends dominate the forecast. This transparency is useful in business contexts where stakeholders need to understand prediction drivers, such as financial forecasting where different strategic decisions may be appropriate depending on whether short-term market movements or long-term economic trends are driving the forecast. NHITS also performs well for long-horizon forecasting tasks, as the hierarchical structure helps maintain accuracy far into the future by preventing short-term noise from obscuring long-term signal.

NHITS is less appropriate for time series with simple, single-scale patterns where traditional methods like ARIMA or exponential smoothing can achieve comparable accuracy with lower computational cost. The method also requires sufficient historical data to learn meaningful patterns at each hierarchical level, typically at least 2-3 complete cycles of the longest seasonal pattern. For sparse data or short time series that don't meet this requirement, simpler models are more appropriate and often more reliable.

Best Practices

Select hierarchical levels that align with your data's natural temporal structure. For hourly data with daily and weekly patterns, use levels like [1, 24, 168] where level 24 captures daily cycles and level 168 captures weekly patterns. Generic factors like [1, 2, 4, 8] work when your data exhibits patterns at those scales, but misaligned levels waste computational resources. Analyze autocorrelation at different lags or perform spectral analysis to identify dominant frequencies, then choose downsampling factors that target those scales. For example, if autocorrelation peaks at lags 7, 30, and 365, consider levels like [1, 7, 30, 365] rather than arbitrary power-of-2 factors.

Standardize your time series to zero mean and unit variance before training, as this helps neural networks at different hierarchical levels learn more effectively. Handle missing values using interpolation methods that respect temporal ordering, avoiding forward-fill or backward-fill approaches that can introduce artifacts at scale boundaries. When working with multiple related time series, training a single NHITS model across all series often improves both efficiency and accuracy by learning shared patterns while the hierarchical structure captures series-specific dynamics.

Start with moderate hyperparameter settings and adjust based on performance. Use hidden layer sizes of 64-128 units initially, increasing to 256 if the model underfits. Set MLP depth to 2-3 layers per hierarchical block, as deeper networks increase training time without proportional accuracy gains. Initialize the learning rate between 0.001-0.01 and use learning rate scheduling to reduce it during training. Monitor learned combination weights: if one level dominates (weight >0.8), other levels may contribute little, suggesting you could simplify the hierarchy by removing uninformative levels.

Data Requirements and Preprocessing

NHITS requires time series with sufficient length to learn patterns at multiple scales. As a guideline, provide at least 2-3 complete cycles of your longest seasonal pattern for the model to learn meaningful representations at coarse hierarchical levels. For daily data with yearly seasonality, this means 2-3 years of history. Shorter series can work but may require fewer hierarchical levels, using only scales where adequate data exists. Each hierarchical level should have at least 10-20 times as many training samples as the input window size to ensure reliable learning.

Data must be regularly sampled with consistent time intervals, as the hierarchical downsampling operation requires equally spaced observations. If your data has irregular timestamps, resample to a regular frequency using appropriate aggregation methods before applying NHITS. The time series should exhibit clear multi-scale patterns for the hierarchical approach to provide value over simpler methods. Assess this by examining autocorrelation at different lags or performing spectral analysis to identify multiple dominant frequencies.

Handle outliers carefully during preprocessing, as extreme values can disproportionately affect the downsampling averaging operation. Use robust scaling methods or cap extreme values at sensible percentiles (e.g., 1st and 99th percentiles) rather than removing them entirely, as outliers may contain information about rare but important events. For data with strong trends, detrending can sometimes improve performance, though the hierarchical structure often handles trends effectively without explicit removal. Apply all preprocessing transformations consistently during both training and inference to avoid prediction errors.

Common Pitfalls

Using hierarchical levels that don't align with your data's temporal structure is a frequent mistake. Applying downsampling factors like [1, 2, 4, 8] to weekly data creates a level-8 representation averaging over 8 weeks, which may exceed meaningful pattern durations. This leads to coarse-scale networks learning little useful information and wastes computational resources. To avoid this, analyze your data's autocorrelation or spectral properties to identify dominant frequencies, then select hierarchical levels that correspond to those scales. For weekly data with monthly patterns, use levels like [1, 4, 13] rather than arbitrary power-of-2 factors.

Insufficient training data for coarse hierarchical levels causes poor generalization. If your time series has 1000 points and you use a downsampling factor of 8, the coarsest level sees only 125 points. With typical input/output window sizes of 50/10, this leaves very few training samples for that level's network. To prevent this, ensure each hierarchical level has at least 10-20 times as many training samples as the input window size. When working with limited data, use fewer hierarchical levels or smaller downsampling factors to maintain adequate sample sizes at each scale.

Underestimating computational requirements is another common issue. NHITS trains multiple neural networks simultaneously, increasing both training time and memory requirements compared to single-scale models. For datasets with millions of observations, the memory needed to process all hierarchical representations can exceed available GPU memory. To address this, use smaller batch sizes (16-32 instead of 64-128), reduce the number of hierarchical levels, or process the time series in overlapping chunks. Allocate sufficient time and computational budget for hyperparameter tuning, as this process takes longer with NHITS than with simpler models.

Computational Considerations

NHITS computational complexity scales with both the number of hierarchical levels and the neural network architecture at each level. Training time increases roughly linearly with the number of levels, as each level requires separate forward and backward passes. For a typical configuration with 3 hierarchical levels, expect training to take 2-3 times longer than a comparable single-scale neural network. Memory usage also increases proportionally, as the model must simultaneously store activations and gradients for all hierarchical blocks. For datasets larger than 10,000 observations, monitor memory usage and adjust batch sizes (typically 16-32) if GPU memory is constrained.

Inference with trained NHITS models is relatively efficient, with hierarchical decomposition and neural network forward passes computing quickly. For real-time applications requiring millisecond latencies, NHITS typically performs well once trained, with inference time similar to other neural time series models. The upsampling and weighted combination operations add minimal overhead compared to models that predict directly at the target resolution. For production deployments, convert the model to optimized formats like ONNX or TorchScript, which often provide 2-3x inference speedups.

Scaling to very large datasets or multiple time series requires distributed training strategies. For datasets with millions of observations, use distributed training across multiple GPUs, with each GPU handling a subset of data or hierarchical levels. When forecasting multiple related time series, training a shared model across series often improves both efficiency and accuracy by learning common temporal patterns, though this requires careful batching to ensure diverse examples from different series during training. For production systems, implement model caching and batch prediction to amortize model loading and GPU initialization costs across multiple forecast requests.

Performance and Deployment Considerations

Evaluate NHITS performance using metrics appropriate for time series forecasting. Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE) provide overall accuracy measures, with RMSE penalizing large errors more heavily. For business applications, Mean Absolute Percentage Error (MAPE) often makes results more interpretable by expressing errors as percentages, though it can be sensitive to small actual values. Evaluate on a held-out test set that comes chronologically after the training data, as time series structure makes random train-test splits inappropriate. Use rolling or expanding window validation to simulate realistic forecasting scenarios where the model is retrained periodically as new data arrives.

Examine learned hierarchical weights to understand which temporal scales the model finds most predictive. If weights are highly imbalanced (one level >0.8, others <0.1), some levels may contribute little. Use this insight to simplify the model by removing uninformative hierarchical levels, reducing computational cost without sacrificing accuracy. Visualize predictions against actuals at different forecast horizons to identify whether errors grow systematically with horizon length, which might indicate issues with long-term trend capture at coarse scales.

Deploy NHITS to production using infrastructure for model serving and monitoring. Export the model as a serialized PyTorch or TensorFlow checkpoint and load it in serving frameworks like TorchServe or TensorFlow Serving. For lower latency, convert to ONNX format and use ONNX Runtime, which often provides 2-3x inference speedups. Monitor prediction accuracy in production by comparing forecasts against realized values as they become available, and set up alerts for anomalous prediction errors that might indicate model drift. Retrain the model periodically (weekly or monthly, depending on your domain) as new data accumulates, using updated training sets to capture evolving patterns. Maintain version control for both models and preprocessing pipelines to enable rollbacks if new model versions degrade performance.