►
From YouTube: Hot Gym Anomaly Tutorial
Description
Starting where the "One Hot Gym Prediction Tutorial" () left off, Matt shows how to convert a NuPIC prediction model into an anomaly detection model. See source code for this tutorial at https://github.com/numenta/nupic/tree/master/examples/opf/clients/hotgym/anomaly/one_gym.
A
A
But
if
you
have
not
gone
through
that
tutorial
or
at
least
watched
it,
you
probably
should
just
to
get
an
idea
of
where
we're
starting
from
so
that's
where
I
am
at
right
now,
I
am
in
the
nupoc
repository
in
the
examples:
folder
and
opf
clients,
hot
gem
prediction,
1
Jim,
so
that
is
the
the
hot
gem
tutorial
that
I
was
just
referring
to.
So
we're
going
to
start
with
this
and
move
onward
to
add
anomaly
detection
to
it.
A
That's
what
we're
going
to
do
so.
First,
I
am
just
going
to
copy
this
whole
directory
somewhere
into
my
sandbox
1
Jim
anomaly
and
then
we'll
hop
down
there
and
take
a
look
at
this
code.
So
this
is
the
stuff
that's
currently
in
the
repo
I'm
gonna
I'm
gonna
get
rid
of
some
of
this
stuff.
So
we
can
kind
of
start
fresh
things
that
we
don't
need.
A
We
don't
need
any
pyc
files.
We
don't
need
any
swarm
stuff.
So
now
we're
just
left
with
a
run
script.
There
is
a
model
parameters
file
in
here
and
model
params
and
then
just
the
input
file,
which
is
a
CSV
and
this
output
processor,
which
just
either
dumps
it
to
a
file
or
plots
on
screen.
This
should
run
just
the
way
it
is.
If
put
run
lot
there,
we
go,
we
get
a
plot.
So
this
is
the
old
prediction
tutorial
from
the
hot
gem.
A
Just
gonna
cancel
that
so
that
this
is
what
we're
going
to
be
updating,
so
I
don't
want
just
predictions.
I
also
want
anomalies.
So
let's
talk
about
how
we
want
to
get
that.
First
of
all,
let's
look
into
the
model
parameters
directory.
Let's
get
rid
of
that
pyc
file
and
all
we
have
is
this
rec
center,
our
lead
model
params.
Let's
take
a
look
at
this
rec
center
of
our
early
model
programs.
So
the
easiest-
and
it's
really
simple-
to
change
this
to
an
anomaly
model.
A
A
A
So
I
should
have
an
anomaly
score
here
at
this
point.
Let's
just
print
that
this,
so
you
can,
we
can
prove
to
ourselves
it's
actually
being
created.
So
now,
if
I
run
run
I'm
not
going
to
do
the
plot
option,
we
should
see
there.
It
is
a
whole
bunch
of
anomaly
scores
for
each
row
of
data
being
dumped
onto
the
screen
at
the
same
time
that
it's
writing
the
output
CSV
file,
just
let
that
run
through
or
I
could
just
kill.
It
doesn't
really
matter,
but
there
we
at
least
see
we're
getting
an
onlay
scores.
A
A
One
thing
I'm
going
to
do
here
is
get
rid
of
this
old
new
pic
output
pi.
This
is
the
the
Python
module,
that's
handling
all
of
the
output
from
new
pic.
It
takes
the
the
actual
values
and
the
predictions
and
either
plots
them
and
matplotlib
or
it
writes
them
to
a
file.
I
have
an
updated
version
of
this
I
think
it's
I
think
it
is
right
here
in
my
home,
we'll
just
copy
that
here
it's
called
new
pick
anomaly
output.
So
let's
take
a
quick
look
at
the
new
new
pick.
A
Anomaly,
output
pick
anomaly
output
that
operates
much
in
the
same
way
as
the
old
new
pic
output
that
was
used
in
the
first
tutorial,
but
it
has
simpler,
simpler
inputs,
simpler
interface,
so
it
assumes
you're
just
going
to
be
dealing
with
one
model
and
it
also
converts
an
anomaly
score
into
an
anomaly
likelihood
and
it
does
that
using
this
little
helper
guide.
That's
now
in
the
nucleic
library
you
go
back
to
the
top
here.
A
So
now,
in
new
pick,
algorithms,
there
is
a
module
called
anomaly
likelihood
and
that's
what
we're
doing
that's
what
we're
using
down
here
so
I'm,
creating
I'm,
just
calling
an
anomaly
likelihood
helper
and
that's
it
I'm,
just
creating
a
new
instance
of
this
anomaly
likelihood
class
and
then
down
in
the
where
is
it
not
only
likelihood
helper?
There
we
go
in
the
in
the
right
function
of
this,
where
I'm
sending
it
the
timestamp
value,
predicted
value
and
anomaly
score.
A
I
am
calling
a
method
on
it
called
the
anomaly
probability
based
on
the
current
value,
the
current
anomaly
score
and
the
current
timestamp,
and
that
will
get
me
an
anomaly
likelihood.
Then
that's
all
that
I'm!
That's
all
that
I'm
using
it
for
I'm
doing
the
same
thing
in
the
new
pic
plot
output
down
here
and
in
the
right
function,
except
that
I'm,
not
writing
it
out
to
a
CSV
file.
I
am
plotting
it.
So
there
was
the
anomaly
likelihood
and
I
am
have
a
line
for
the
anomaly
likelihood
and
that's
what's
getting
plotted.
A
A
Actually,
what
am
I
trying
to
do
import
import,
new
pic
anomaly,
and
now
they
spell
this
right
and
not
only
output
as
new
pic
pic
output,
there
we
go.
Ok,
new
pic
output
is
here's
where
it's
instantiated,
so
we've
got
a
little
logic
here.
So
if
there
is
a
plot
option,
we
instantiate
a
new
pic
plot
output.
There
was
a
file
option.
We
missed
an
idiot
in
another
class,
so
this
anomaly,
output
module
is
simplified
from
the
original
one
that
we
used
in
the
first
prediction.
A
Tutorial
I
had
plans
in
the
first
prediction,
tutorial
and
I
still
do
of
turning
it
into
a
multiple
model
tutorial,
so
I
formatted,
the
new
pic
output,
module
to
accept
mini
models
and
eventually
we'll
plot
or
write
many
model
outputs,
but
for
this
example,
which
is
just
going
to
really
be
a
singleton.
So,
for
example,
this
constructor
for
new,
quick
plot
output
was
taking
a
list
of
names
and
it
currently
now
only
takes
80
name.
So
that's
one
thing
that
needs
to
change
real,
quick
and
let's
go
to
I.
Think
it's
the
right
function.
A
It's
the
last
thing.
We
need
to
change
where
it
used
to
take
a
list
of
lists
of
values.
It
now
only
takes
one
value
and
there
is
an
additional
value:
anomaly
score.
Okay,
so
now
we're
going
to
write
out
the
timestamp,
the
energy
consumption,
new
pics
prediction
and
the
current
anomaly
score
for
that
prediction.
We'll
get
rid
of
the
print
statement.
A
And
this
may
be
the
only
thing
that
really
needs
to
be
done:
let's
find
out
okay,
so
I've
updated
my
run.
Let's
run
and
well,
let's
not
plot,
let's
just
run
it
first
and
make
sure
everything
writes
okay,
so
it's
it
is
a
running
through
the
input
feeding
every
line
into
new
pic
and
it
should
be
writing
an
output
file
that
contains
an
anomaly
score
and
an
anomaly
likelihood
and
I'll
get
into
that
in
just
a
minute.
A
So
there
we
have
it,
it
wrote
out
to
rec
center
our
layout
and
we
have
consumption
prediction,
anomaly,
score
and
anomaly
likelihood
and
I'll
explain
these
values
soon.
It
looks
a
little
bit
better
if
you
plot
this,
so
we
did.
This
is
just
CSV.
We
could
plot
this
in
a
spreadsheet,
but
let's
actually
just
run
this
with
the
plot
option
and
the
nupoc
output
will
take
care
of
everything
and
plot
it
using
MATLAB.
A
So
here
it
comes,
and
what
you're
seeing
here
on
the
top
graph
is
the
actual
and
predicted
values
the
blue
is
actual
values.
That's
the
truth.
Coming
in
from
the
input
CSV
file,
the
green
are
the
predicted
values,
the
values
nupoc
is
predicting
and
their
shifted,
so
they
are
aligned.
So
for
every
line
you
see
the
actual
value
and
the
value
new
pic
predicted
would
be
at
that
point
in
time.
So
these
yellow
bars
indicate
weekends.
A
So
this
this
data
I
think
is
in
15-minute
intervals
over
a
span
of
several
months
and
so
we're
looking
at
energy
consumption
in
a
building
in
a
gym-
and
you
remember
the
old
tutorial.
This
data
should
look
very
familiar,
but
I've
I've
done
a
little
bit
of
work
to
emphasize
where
the
weekends
are
in
this
data.
The
bottom
chart
is
where
we
are
plotting
the
anomaly
score,
which
is
the
magenta
line.
That's
the
one
that
is
not
a
flat
line
currently
and
the
anomaly
likelihood.
A
The
anomaly
score
is
kind
of
a
raw
indicator
that
comes
out
of
new
pic
and
the
anomaly
likelihood
is
a
kind
of
a
post
algorithm
that
is
being
run
outside
of
the
new
pic
model
entirely
new
Mentos
employees.
Super
Tom
odd
had
a
presentation
about
this
at
our
last
hackathon
and
there's
a
link
to
it
here
or
here,
and
if
you
want
to
know
how
this
anomaly
likelihood
is
calculated
used
to
take
a
look
at
that
the
code
is
now
in
new
pic,
so
it's
kind
of
just
a
helper
utility.
A
So
if
you
look
at
this
data,
you
can
see
that
the
weekend
energy
usage
is
definitely
different
from
the
weekday
energy
usage.
So
that
is
a
weekly
pattern.
If
you
look
at
the
model
params
that
we
got
from
our
swarm
in
the
first
prediction,
tutorial
you'll
see
that
the
encoders
in
that
model
parameters
included
day
of
a
week,
and
that
would
help
to
capture
weekly
patterns
in
the
data.
So
here
we're
still
seeing
a
here's.
An
another
high
anomaly
score
at
the
another
Friday
night
early
early
Sunday
morning.
A
So
this
could
indicate,
as
you
can
see,
the
the
total
energy
usage
for
this
weekend
is
much
higher
than
previous
weekend's.
So
I
believe
that
the
the
anomaly
scores
the
high
not
only
scores
in
this
period
of
time
are
likely
to
do
with
just
an
overall
jump
in
energy
consumption.
At
this
gym
it
could
be
that
they
added
more
machines
added
more
classes,
something
like
that.
Some
some
behavior
at
that
gym
changed
to
make
the
energy
consumption
increase
and
new
pic
call
mark
this
as
anomalous
for
quite
a
long
period
of
time.
A
But
as
with
anything
once
it
gets
used
to
the
new
patterns,
it
becomes
less
and
less
anomalous.
So,
after
a
while,
the
increased
energy
consumption
at
the
gym
is
now
the
new,
normal
and
new
pic
calms
down
and
goods
back
to
business
as
usual,
and
recognizes
that
these
are
the
new
patterns
and
adjusts
itself
to
match
those
patterns.
A
So
now
we
are
a
couple
of
months.
Almost
three
months
into
this
data
set
and
new
pic
has
become
pretty
comfortable
with
it.
At
this
point,
if
you
look
at
you
know,
you
look
at
the
peaks
and
valleys
of
the
the
daily
patterns,
its
it's
getting
pretty
good
at
these
daily
patterns.
It's
getting
the
spike
between
the
days
where
your
cleaning
crews
typically
come
in
and
clean.
It
recognizes
the
weekends,
have
a
different
pattern
than
the
weekdays.
It
still
sees
this
occasional
anomalous
period,
usually
on
Friday
evenings
early
Saturday
mornings.
A
So
I
don't
really
know
what
that
is,
but
be
interested
to
figure
out.
What
exactly
is
in
the
data
that
makes
nupoc
think
that's
something
strange
is
going
on
there.
It's
not
quite
comfortable
with
that
time
period
and
you
see
it
another.
You
know
a
little
bit
of
a
jump
here
and
you
not
only
score,
although
it
did
not,
it
wasn't
enough
to
set
off
the
anomaly
likelihood,
so
so
that's
an
overview,
pretty
much
of
anomaly
scores
with
a
nice
plot.
For
you
guys
now,
I
would
like
to
kind
of
run
a
an
experiment
here.
A
A
A
A
Okay
starts
with
ten:
there
we
go
alright,
so
we
are
in
October
now
I,
don't
know
what
day
is
what
but
I'm
just
going
to
go
down
until
I
see
a
nice
flat
there.
It
is.
This
must
be
a
Tuesday
first
Tuesday
in
October
is
the
5th
of
October.
As
you
can
see,
it's
just
flat
line
5
all
the
way
through
that
Tuesday
and
all
4
Tuesdays
with
in
October,
are
going
to
be
there's
another
flat
line
5.
So
that
is
our
new
data
and
we're
just
gonna
run
it
again.
A
Initially,
you
got
to
understand
that
new
peak
has
never
seen
the
state
of
before
this
model
is
brand
new
created
with
the
model
params
that
we
just
looked
at,
and
it's
never
seen
any
data
at
all,
so
initially
y'all,
it
kind
of
does
is
predict
what
it
just
saw
in
the
last
step
and
after
a
while,
it
gets
a
little
bit
better
a
little
bit
better
the
more
patterns
it
sees,
the
better
it
gets
so
one
other
thing,
you'll
notice
is
that
the
anomaly
likelihood
is
is
flat.
Initially
I
think
it
just
starts
off.
A
A
So
it's
gonna.
Take
it
a
little
bit
to
comprehend
this
as
a
weekly
pattern.
So
now
we've
got
two
Tuesdays,
so
the
anomaly
on
the
second
missing
Tuesday
was
lower,
and
here
we're
going
into
the
third
Tuesday
in
October,
where
there
is
no
energy
usage,
a
little
bit
of
an
anomaly
likelihood
there,
but
not
a
lot
and
I
would
expect
that
the
fourth
Tuesday
October
there
to
be
no
anomaly,
although,
as
you
might
notice,
new
pic
is
still
predicting
that
there
may
be
energy
usage
on
that
day.
A
So
here
we're
going
into
November
and
Tuesday
is
back
and
new
pics
fire
that
it
has
seen
that
pattern
before
that's
the
typical
pattern
it
saw
four
months
before
it
got
socked
over.
So
when
Tuesday
reappears,
it
is
not
anomalous.
This
is
a
sequence
that
it
has
seen
before
and
it
recognizes
so
there's
not
an
anomaly
spike
once
Tuesday
is
thrown
back
into
the
mix.
It
just
goes
on
recognizes
it's
back
on
the
same
pattern
and
was
before,
and
it's
doing
pretty
well
on
its
predictions.
A
A
So
that
was
me
showing
you
how
to
convert
a
temporal
multi-step
inference
type
nupoc
model
into
a
temporal
anomoly
model
and
take
that
anomaly
score
out
and
do
something
interesting
with
it.
So
I
hope
that
you
enjoyed
that,
and
you
learned
something
please
let
me
know
if
you
want
to
see
any
future
tutorials
on
new
pick
in
the
comments
below
feel
free
to
like
the
video
and
have
a
good
day.