Talk to an engineer
cd ../work

An autoencoder to find anomalous energy bills

How do you trust a model that finds things you didn't know to look for? We put it next to one you can follow line by line.

case.yaml
client:
Energy company
industry:
Energy · billing
engagement:
Proof of concept
stack:
Python · pandas · scipy · Keras · PyOD

26,002

bills analysed

24

linear fits, one per month and class

99

parameters in the network

The Energy company work.

01 The problem

An energy company had years of consumption and billing history from its meters, and suspected errors in it: charges that didn't match the usage, readings loaded wrong, tariffs applied wrong.

Checking them one by one wasn't an option. And a fixed rule like "warn me if the cost goes over X" doesn't work either: what is normal for one service class in January is not normal for another in July.

We started from 26,175 records of some 400 meters. We dropped 65 from a marginal service class and 108 with no cost: 26,002 were left, almost half and half between two service classes.

service classrecordsclass Aclass Bmarginalbefore cleaningafter cleaningdropped

02 Two methods, two questions

First, a baseline anyone can audit. If the tariff is stable, cost grows in a straight line with usage. We fitted a line of cost against usage for every month and every service class (scipy curve_fit), 24 fits in all, and gave each bill a score: how far it sits from its line, in units of the fit's own uncertainty.

usagecostone month, one classfar from its line

With a strict threshold it flagged 45 bills out of 26,002, under 0.2 %. It can be explained in one sentence. But it only finds the kind of anomaly you already knew existed.

Then, a network that learns what normal is. An autoencoder takes a bill in, compresses it and rebuilds it; nobody tells it what an anomaly is. Ours took four variables (usage, cost, service class and month) through a bottleneck of a single neuron, nine layers and 99 parameters, in Keras. With so little room it can only keep the general pattern: normal bills come back well, odd ones come back badly, and that rebuild error is the score.

inputcompressedrebuilterror high= anomaly

One model per service class, trained on 75 % of the data and validated on the other 25 %. The two loss curves fall together and flatten near epoch 10: it learns the pattern without memorising the data.

epoch (45)loss~ epoch 10training (75 %)validation (25 %)

With PyOD we tried three architectures and averaged their scores. In one of the service classes, the ensemble set 50 bills apart out of 3,228 in validation, about 1.5 %, with usage and cost some 5.5 standard deviations above the mean.

anomaly scorebillsfixed cutthe few to look atmost bills are normal

03 The detail that matters

EZEnergy.ipynb · Oct 2020 EZEnergy.ipynb · Oct 2020
# We must design the NN architecture accordingly to the symmetries of the problem
# In this case months are similar as we apart from July (for instance May is similar to October)
# and also there a periodic symmetry (December is close to January).
# Therefore we convert the month number into a month code that summarizes this fact
# by computing the difference in absolute value to month 7,
data['month_code'] = data['month'].map(lambda x: abs(x-7))

To a network, December (12) and January (1) sit at opposite ends, though for energy use they are almost the same. Distance to July fixes both things at once: May and September become the same value, and December lands next to January. The network doesn't have to learn the symmetry, because it already comes in the data.

JanFebMarAprMayJunJulAugSepOctNovDec0123456May and September: 2December 5, January 6: neighboursmonth_code = |month − 7|

04 How we knew it worked

We put the two scores side by side, bill by bill. Where the linear fit flags a strong anomaly, the autoencoder flags it too. The network got there on its own, without anyone explaining how cost relates to usage: the same place as the analysis done by hand.

linear-fit indicatorautoencoder indicatorboth flag itonly the autoencodernormal bills

It also flagged bills the line considered normal: it detects "what doesn't fit", not one error in particular. Since it agrees where we can check it, its own flags are where to start reviewing.

05 When

October 2020, two years before ChatGPT. Doing AI meant cleaning data, designing a network, training it and checking it against a baseline. The tools have changed; the order hasn't: first understand the problem, then pick the model.

Oct 2020this autoencoderNov 2022ChatGPT comes outtodayagents in production
mail — hello@easytech.com.ar — 80×24

Talk to an engineer

No sales funnel. The person who answers is the person who'd do the work.

need:

Or write to hello@easytech.com.ar

or write hello@easytech.com.ar
Talk to an engineer about this