>> In this episode of the AI Show,
we hear from Qun Ying,
Senior Program Manager on
the Microsoft Azure Cognitive Services Team.
Qun will show us how to use the anomaly detector with
simple rest API calls that you can put into your own application,
today. Make sure you tune in.
>> [MUSIC]
>> Hi, I'm Qun, Program Manager in Microsoft.
I'm going to use 10 minutes to share you
this exciting AI powered API service Anomaly Detector,
which is able to detect anomalies from
time series using just a simple rest API course.
Hopefully after this 10 minutes,
you'll walk away with a basic understanding of how you could build
your time series monitoring solutions with anomaly detector,
and more importantly, where to find more resources.
I'll start with a really quick overview,
and then spend most time on code demos,
and I'll wrap up my video with the links to more resources.
Anomaly detector is detecting anomalies from time series using AI.
But you don't need to know AI to use it,
because it just three rest APIs.
What you do is, just to call
the APIs with an array of time series data points.
The APIs will immediately respond with,
which data points are anomalous,
which ones are change points.
No training with labeled data is needed,
no model selection, no model deployment.
Anomaly detector exposes that simplicity by hiding complexity.
It is leveraging a collection of
cutting edge in models and mechanism,
that automatically select
the best-performing algorithm in symbols,
by some of the hidden patterns in your data,
no matter its seasonality,
chanting, random spikes and so on and so forth, it just works.
It could adapt to all those data patterns.
Now, let's just jump to the code demo.
The first step is to create an anomaly detector resource,
a session for anomaly detector on Microsoft in Azure Marketplace,
and then you just create the anomaly detection resource.
I've already created one.
The point here is, you need to go to the resource portal and copy
the endpoint as well as one of the API keys.
You would need to use them in your code.
I've mentioned the three rest APIs.
Now, I'm going to show you three Jupyter Notebooks, namely;
the anomaly detection for batch data
and the anomaly detection for streaming data,
and the change point detection.
I'm going to walk you through the code.
Previously, we've copied the API key and endpoint.
Now, you need to replace that in order to run this code.
I have replaced the API key and the endpoint.
Now, let's look at the code.
So this is the function that's coding the rest API.
As defined by this endpoint,
it is posting data to the endpoint with the API key in the header.
Then let's check how the data is being passed into this function.
Basically, it's just loading JSON data from file,
add some parameter here and call this build figure function,
which starts with calling this detect function with the data.
The code here is basically taking the result,
which is the return from the API call and draw a chart with it.
Let me just run everything.
In this first sample,
we can see that, although the trend is changing,
but these are not detected as anomalies,
whereas this spikes, are carefully marked as anomalies.
In the second example,
although they are seasonality,
the API service is able to adapt to the seasonality,
understand the seasonality and take
these data points as normal ones,
while this one doesn't really conform to the regular pattern,
is detected as anomaly.
This is very useful when your data has
something like seven days seasonality.
You will notice that there are multiple charts for each dataset.
The difference is about the sensitivity.
Here we're using 95.
This is making the service really sensitive to anomalies.
So this blue shade here,
which is the boundary,
the lower bound and the upper bound is
very narrow comparing to the next one,
which is using 90 sensitivity,
and the last one which is using 85.
Now let's jump to the second Jupyter Notebook.
This is the latest point anomaly detection
with stashed slashed API.
The same as before,
we need to replace the right API key at endpoint here.
I will replace those.
Now let's run and check the code.
In this Notebook, data is loaded here and
then this code is trying to build a sliding window of data points,
in total, 29 data points are used
to call the detached function and to detect anomalies.
The result is only about whether,
the last data point being passed in is anomalous or not.
As you can see, there's no result before this point.
This is because these points are basically used as
the side window and this is the first window of data.
The sensitivity parameter, could be still used in this case.
To better help you understand this,
I'm going to show you a demo application instead of code,
to help you understand what a sliding window really is.
When you want to build and measure
monitoring solution that's monitoring your streaming data,
this is the Demo Web app built upon anomaly detector APIs.
I've already replaced the endpoint and the API key here.
Now, I'm selecting the Sample 1 and am going to click "Start."
As you can see, this a gray shade,
gray moving window here,
and this is the sliding window that I'm talking about.
As you can see, in this request input,
an array of data points is being passed to the API endpoint.
This is exactly what's in this sliding window.
The response is only about whether,
the last data point is anomalous or not.
Now let's look at the third Jupyter Notebook,
which is the change point detection example.
For the sake of time,
I've already replaced the endpoint and the API key here.
This sample also, for instance,
loads data from the JSON file and then
call the finger function and this finger function,
of course, call this detect function,
where is the API key and the data.
This detect function is just simple achieved via call.
The starting point of a change is detected and marked as green.
Now, in all those samples,
we're loading data from JSON files.
What do those JSON files look like?
This is just one sample and
the other ones are pretty much the same.
The main part of it is really an array
of timestamp and the value pairs.
Requesting a few other parameters,
granularity is one of them.
For details, you need to check the API specification.
Now what about Container?
I'm not going to do a comprehensive demo on
container because it's pretty much the same thing,
at least the same usage.
I have a Docker container of anomaly detector that's running
in my laptop with the API key and the build endpoint,
exactly the same that I'm using for the other demos.
Now, I'm going to change the endpoint in the Jupyter Notebook.
First, it should be HTTP instead of HTTPS,
and the API endpoint, I'll change to this.
I'm going to create output and run again. Here we go.
This is, remember to replace this.
API key doesn't matter really.
I can input anything,
because this Container in the back-end
is already using the API key of your anomaly detection resource.
Therefore, in your code, you can use anything
and it doesn't change the result whatsoever.
So much for the demo.
These are the resources that you could
find useful after this session.
Knowing when something really goes off
the rails is incredibly important,
and now it could be easily done with just a simple API course.
I'm really excited about our service.
What about you?
Let us know and feel free to try out
anomaly detector and start to
build with anomaly detector. Thank you.
>> [MUSIC]