Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Anomaly Detector is an AI service with a set of APIs, which enables you to monitor and detect anomalies in your time series data with little machine learning (ML) knowledge, either batch validation or real-time inference.
Source code | Package (NuGet) | API reference documentation | Product documentation
Install the Azure Anomaly Detector client library for .NET with NuGet:
dotnet add package Azure.AI.AnomalyDetector --prerelease
This table shows the relationship between SDK versions and supported API versions of the service:
SDK version | Supported API version of service |
---|---|
3.0.0-preview.6 | 1.1 |
3.0.0-preview.4, 3.0.0-preview.5 | 1.1-preview-1 |
3.0.0-beta.3 | 1.1-preview |
3.0.0-preview.1, 3.0.0-preview.2 | 1.0 |
You can find the endpoint for your Anomaly Detector service resource using the Azure Portal or Azure CLI:
# Get the endpoint for the Anomaly Detector service resource
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"
You can get the API Key from the Anomaly Detector service resource in the Azure Portal. Alternatively, you can use Azure CLI snippet below to get the API key of your resource.
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
Once you have the value for the API key, create an AzureKeyCredential
. With the endpoint and key credential, you can create the AnomalyDetectorClient
:
string endpoint = "<endpoint>";
string apiKey = "<apiKey>";
var credential = new AzureKeyCredential(apiKey);
var client = new AnomalyDetectorClient(new Uri(endpoint), credential);
With the Anomaly Detector, you can either detect anomalies in one variable using Univariate Anomaly Detection, or detect anomalies in multiple variables with Multivariate Anomaly Detection.
Feature | Description |
---|---|
Univariate Anomaly Detection | Detect anomalies in one variable, like revenue, cost, etc. The model was selected automatically based on your data pattern. |
Multivariate Anomaly Detection | Detect anomalies in multiple variables with correlations, which are usually gathered from equipment or other complex system. The underlying model used is Graph attention network. |
The Univariate Anomaly Detection API enables you to monitor and detect abnormalities in your time series data without having to know machine learning. The algorithms adapt by automatically identifying and applying the best-fitting models to your data, regardless of industry, scenario, or data volume. Using your time series data, the API determines boundaries for anomaly detection, expected values, and which data points are anomalies.
Using the Anomaly Detector doesn't require any prior experience in machine learning, and the REST API enables you to easily integrate the service into your applications and processes.
With the Univariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time.
Feature | Description |
---|---|
Streaming detection | Detect anomalies in your streaming data by using previously seen data points to determine if your latest one is an anomaly. This operation generates a model using the data points you send, and determines if the target point is an anomaly. By calling the API with each new data point you generate, you can monitor your data as it's created. |
Batch detection | Use your time series to detect any anomalies that might exist throughout your data. This operation generates a model using your entire time series data, with each point analyzed with the same model. |
Change points detection | Use your time series to detect any trend change points that exist in your data. This operation generates a model using your entire time series data, with each point analyzed with the same model. |
The Multivariate Anomaly Detection APIs further enable developers by easily integrating advanced AI for detecting anomalies from groups of metrics, without the need for machine learning knowledge or labeled data. Dependencies and inter-correlations between up to 300 different signals are now automatically counted as key factors. This new capability helps you to proactively protect your complex systems such as software applications, servers, factory machines, spacecraft, or even your business, from failures.
With the Multivariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time. There are three processes to use Multivariate Anomaly Detection.
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
The following section provides several code snippets covering some of the most common Anomaly Detector service tasks, including:
//detect
Console.WriteLine("Detecting anomalies in the entire time series.");
try
{
UnivariateEntireDetectionResult result = client.DetectUnivariateEntireSeries(request);
bool hasAnomaly = false;
for (int i = 0; i < request.Series.Count; ++i)
{
if (result.IsAnomaly[i])
{
Console.WriteLine($"An anomaly was detected at index: {i}.");
hasAnomaly = true;
}
}
if (!hasAnomaly)
{
Console.WriteLine("No anomalies detected in the series.");
}
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Entire detection failed: {ex.Message}");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"Detection error. {ex.Message}");
throw;
}
//detect
Console.WriteLine("Detecting the anomaly status of the latest point in the series.");
try
{
UnivariateLastDetectionResult result = client.DetectUnivariateLastPoint(request);
if (result.IsAnomaly)
{
Console.WriteLine("The latest point was detected as an anomaly.");
}
else
{
Console.WriteLine("The latest point was not detected as an anomaly.");
}
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Last detection failed: {ex.Message}");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"Detection error. {ex.Message}");
throw;
}
//detect
Console.WriteLine("Detecting the change point in the series.");
UnivariateChangePointDetectionResult result = client.DetectUnivariateChangePoint(request);
if (result.IsChangePoint.Contains(true))
{
Console.WriteLine("A change point was detected at index:");
for (int i = 0; i < request.Series.Count; ++i)
{
if (result.IsChangePoint[i])
{
Console.Write(i);
Console.Write(" ");
}
}
Console.WriteLine();
}
else
{
Console.WriteLine("No change point detected in the series.");
}
To see how to use Anomaly Detector library to conduct Multivariate Anomaly Detection, see this sample.
The simplest way to see the logs is to enable the console logging. To create an Azure SDK log listener that outputs messages to console use the AzureEventSourceListener.CreateConsoleLogger method.
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
To learn more about other logging mechanisms see Diagnostics Samples.
These code samples show common scenario operations with the Azure Anomaly Detector library. More samples can be found under the samples directory.
Univariate Anomaly Detection - Batch Detection: Sample1_DetectEntireSeriesAnomaly.cs
Univariate Anomaly Detection - Streaming Detection: Sample2_DetectLastPointAnomaly.cs
Univariate Anomaly Detection - Change Point Detection: Sample3_DetectChangePoint.cs
Multivariate Anomaly Detection: Sample4_MultivariateDetect.cs
For more extensive documentation on Azure Anomaly Detector, see the Anomaly Detector documentation on docs.microsoft.com.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Azure SDK for .NET feedback
Azure SDK for .NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now