Feature Engineering for Sensor Telemetry: Windowing, Rolling Stats, and the Leaks That Fool You
The most common reason an IoT model looks great offline and useless in production is not the model. It is the features — specifically, the difference between how features were computed in the notebook and how they are computed on the gateway. This post covers windowing, rolling statistics, gap handling, and the leakage patterns that quietly inflate offline metrics. All the code is plain Python…
Many IoT models perform well offline but fail in real-world production due to feature computation discrepancies. This article discusses windowing, rolling statistics, gap handling, and leakage patterns that inflate offline metrics. The code presented is in plain Python with NumPy, ensuring readability for those porting the features to C. Telemetry is not a simple table; it has properties that break traditional table assumptions.
Irregular arrival, gaps, non-monotonic time, and multiple rates are common issues that can corrupt rolling window calculations if performed on row indices rather than time.
To address these issues, the article introduces window types and their appropriate use cases. Tumbling windows provide fixed-duration non-overlapping intervals, while sliding windows offer overlapping intervals with lower detection latency. For alerting, a sliding window with a hop of 10-25% of the window length is recommended. The article also explains time-based resampling onto a fixed grid, keeping last values in duplicated buckets and handling missing buckets as explicit NaNs. This approach ensures accurate downstream rolling calculations.
The author provides a simple implementation of rolling statistics (mean and standard deviation) using a time-ordered stream, which can be implemented with O(1) per sample complexity. This is crucial for devices with limited computational resources. Additionally, the article emphasizes the need for robust features in industrial signals, recommending the use of median and interquartile range instead of mean and standard deviation, as the latter are sensitive to outliers.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to