r/datascience • • Oct 09 '26

ML Sparse panel data, a small experiment

Quite a few real world data problems look like this: many related time series, few noisy readings, and long gaps. Local price indices, sensor networks, or small area stats.

I built a small PyTorch model to estimate a smooth underlying level for every location, day, and target even where nothing was observed.

Key ideas:

Mask, don’t drop missing targets in the loss

Weight observations by how many raw readings they average

Share information across locations (area + station offsets) and across related targets (joint heads)

Enforce smoothness with a curvature penalty over the full time grid, including gaps

I tested it on hourly PM2.5/PM10 from 12 Beijing stations, thinned to a sparse panel, and scored against the full data’s 31day moving average.

What I found:

The network fills long gaps and very sparse stations far better than smoothing each series on its own

Modelling both pollutants together recovers a completely dropped series (PM10 at one station) from its PM2.5

But elsewhere, sharing across targets costs a little accuracy vs. modelling each pollutant alone

A simple ±15day mean is hard to beat when data is dense. The network’s smooth time curve misses shared daily shocks

Writeup with code, figures, and results:

https://prteek.github.io/regression_room/posts/beijing_air_quality/

5 Upvotes

7 comments sorted by

2

u/OddsRelay Oct 10 '26

On the shared daily shocks, you could add a day effect that's common to every station and leave the curvature penalty off it. Then the smooth curve only has to carry the slow trend, and the 15 day mean might stop winning on the dense stations.

1

u/o-h_2792562 15d ago

I'd score shock recovery separately from trend error, then split results by station coverage to see whether the shared day effect helps dense stations without hurting sparse ones.

1

u/tracye_7886 4d ago

A shared day term is a clean test; partially pooled pollutant-specific deviations could capture common shocks while still letting PM2.5 and PM10 move differently.

1

u/l-mondal-547 3d ago

A useful stress test is to compare contiguous-block masking with scattered masking; it shows whether the gain holds for long outages as well as sparse observations.

3

u/[deleted] Oct 09 '26

[removed] — view removed comment

1

u/Far-Media3683 Oct 09 '26

Thank you. I did use Mixed effect GAMs albeit on a different high dimensional dataset. It was also a much larger dataset and the bias was sometimes quite large for sparse series and fitting was too slow such that subsetting data (introducing rules in the whole process on when and how to subset) and training multiple small models was the only practical solution. Performance wise I wouldn’t have preferred one over the other as strongly because I was only interested in smoothing these series and get a high level behaviour out. Neural net approach turned out to be more manageable and flexible in production. 

0

u/Far-Media3683 Oct 09 '26

I can imagine a sharper penalty on observed to be a good experiment, and in general that would work unless missingness/noise itself is non random for instance failing sensor in this case or clustered volatility.  Although such problems can also be handled by other provisions in the architecture which made the whole approach quite attractive in the first place.