Skip to content

Commit 1395725

Browse files
authored
Update README.md of anomaly detector (Azure#32931)
* Update README.md * Update README.md * Update README.md * Update README.md * Update README.md @pshao25 Please help review,thx!
1 parent f4b02e2 commit 1395725

File tree

1 file changed

+179
-29
lines changed
  • sdk/anomalydetector/Azure.AI.AnomalyDetector

1 file changed

+179
-29
lines changed

sdk/anomalydetector/Azure.AI.AnomalyDetector/README.md

Lines changed: 179 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,101 @@
11
# Azure Cognitive Services Anomaly Detector client library for .NET
22

3-
Microsoft Azure Cognitive Services Anomaly Detector API enables you to monitor and detect abnormalities in your time series data with machine learning.
3+
[Anomaly Detector](https://learn.microsoft.com/azure/cognitive-services/Anomaly-Detector/overview) 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.
44

55
[Source code][anomalydetector_client_src] | [Package (NuGet)][anomalydetector_nuget_package] | [API reference documentation][anomalydetector_refdocs] | [Product documentation][anomalydetector_docs]
66

77
## Getting started
88

9+
### Prerequisites
10+
11+
- You need an [Azure subscription][azure_sub] to use this package.
12+
- An existing Cognitive Services Anomaly Detector instance.
13+
914
### Install the package
15+
1016
Install the Azure Anomaly Detector client library for .NET with [NuGet][nuget]:
1117

1218
```dotnetcli
1319
dotnet add package Azure.AI.AnomalyDetector --prerelease
1420
```
1521

16-
### Prerequisites
17-
* An [Azure subscription][azure_sub].
18-
* An existing Cognitive Services or Anomaly Detector resource.
22+
This table shows the relationship between SDK versions and supported API versions of the service:
1923

20-
For more information about creating the resource or how to get the location and sku information see [here][cognitive_resource_cli].
24+
|SDK version|Supported API version of service |
25+
|-------------|---------------|
26+
|3.0.0-preview.6| 1.1|
27+
|3.0.0-preview.4, 3.0.0-preview.5| 1.1-preview-1|
28+
|3.0.0-beta.3 | 1.1-preview|
29+
|3.0.0-preview.1, 3.0.0-preview.2 | 1.0 |
2130

2231
### Authenticate the client
23-
In order to interact with the Anomaly Detector service, you'll need to create an instance of the [`AnomalyDetectorClient`][anomaly_detector_client_class] class. You will need an **endpoint** and an **API key** to instantiate a client object.
2432

25-
#### Get API Key
33+
You can find the endpoint for your Anomaly Detector service resource using the
34+
[Azure Portal](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesAnomalyDetector)
35+
or [Azure CLI](https://learn.microsoft.com/cli/azure/):
36+
37+
```bash
38+
# Get the endpoint for the Anomaly Detector service resource
39+
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"
40+
```
2641

27-
You can obtain the endpoint and API key from the resource information in the [Azure Portal][azure_portal].
42+
#### Get the API Key
2843

29-
Alternatively, you can use the [Azure CLI][azure_cli] snippet below to get the API key from the Anomaly Detector resource.
44+
You can get the **API Key** from the Anomaly Detector service resource in the Azure Portal.
45+
Alternatively, you can use **Azure CLI** snippet below to get the API key of your resource.
3046

3147
```PowerShell
3248
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
3349
```
3450

3551
#### Create AnomalyDetectorClient with AzureKeyCredential
52+
3653
Once you have the value for the API key, create an `AzureKeyCredential`. With the endpoint and key credential, you can create the [`AnomalyDetectorClient`][anomaly_detector_client_class]:
3754

38-
```
55+
```C#
3956
string endpoint = "<endpoint>";
4057
string apiKey = "<apiKey>";
4158
var credential = new AzureKeyCredential(apiKey);
4259
var client = new AnomalyDetectorClient(new Uri(endpoint), credential);
4360
```
4461

45-
#### Create AnomalyDetectorClient with Azure Active Directory Credential
62+
## Key concepts
4663

47-
`AzureKeyCredential` authentication is used in the examples in this getting started guide, but you can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. Note that regional endpoints do not support AAD authentication. Create a [custom subdomain][custom_subdomain] for your resource in order to use this type of authentication.
64+
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**.
4865

49-
To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `Azure.Identity` package:
66+
|Feature |Description |
67+
|---------|---------|
68+
|Univariate Anomaly Detection | Detect anomalies in one variable, like revenue, cost, etc. The model was selected automatically based on your data pattern. |
69+
|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.|
5070

51-
```dotnetcli
52-
dotnet add package Azure.Identity
53-
```
71+
### Univariate Anomaly Detection
5472

55-
You will also need to [register a new AAD application][register_aad_app] and [grant access][aad_grant_access] to Anomaly Detector by assigning the `"Cognitive Services User"` role to your service principal.
73+
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.
5674

57-
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.
75+
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.
5876

59-
```
60-
string endpoint = "<endpoint>";
61-
var client = new AnomalyDetectorClient(new Uri(endpoint), new DefaultAzureCredential());
62-
```
77+
With the Univariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time.
6378

64-
## Key concepts
79+
|Feature |Description |
80+
|---------|---------|
81+
| 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. |
82+
| 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. |
83+
| 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. |
84+
85+
### Multivariate Anomaly Detection
86+
87+
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.
88+
89+
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.
90+
91+
- **Training**: Use Train Model API to create and train a model, then use Get Model Status API to get the status and model metadata.
92+
- **Inference**:
93+
- Use Async Inference API to trigger an asynchronous inference process and use Get Inference results API to get detection results on a batch of data.
94+
- You could also use Sync Inference API to trigger a detection on one timestamp every time.
95+
- **Other operations**: List Model API and Delete Model API are supported in Multivariate Anomaly Detection model for model management.
6596

6697
### Thread safety
98+
6799
We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.
68100

69101
### Additional concepts
@@ -77,9 +109,117 @@ We guarantee that all client instance methods are thread-safe and independent of
77109
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
78110
<!-- CLIENT COMMON BAR -->
79111

112+
## Examples
113+
114+
The following section provides several code snippets covering some of the most common Anomaly Detector service tasks, including:
115+
116+
- [Univariate Anomaly Detection - Batch detection](#batch-detection)
117+
- [Univariate Anomaly Detection - Streaming detection](#streaming-detection)
118+
- [Univariate Anomaly Detection - Detect change points](#detect-change-points)
119+
- [Multivariate Anomaly Detection](#multivariate-anomaly-detection-sample)
120+
121+
### Batch detection
122+
123+
```C# Snippet:DetectEntireSeriesAnomaly
124+
//detect
125+
Console.WriteLine("Detecting anomalies in the entire time series.");
126+
127+
try
128+
{
129+
UnivariateEntireDetectionResult result = client.DetectUnivariateEntireSeries(request);
130+
131+
bool hasAnomaly = false;
132+
for (int i = 0; i < request.Series.Count; ++i)
133+
{
134+
if (result.IsAnomaly[i])
135+
{
136+
Console.WriteLine("An anomaly was detected at index: {0}.", i);
137+
hasAnomaly = true;
138+
}
139+
}
140+
if (!hasAnomaly)
141+
{
142+
Console.WriteLine("No anomalies detected in the series.");
143+
}
144+
}
145+
catch (RequestFailedException ex)
146+
{
147+
Console.WriteLine(String.Format("Entire detection failed: {0}", ex.Message));
148+
throw;
149+
}
150+
catch (Exception ex)
151+
{
152+
Console.WriteLine(String.Format("Detection error. {0}", ex.Message));
153+
throw;
154+
}
155+
```
156+
157+
### Streaming Detection
158+
159+
```C# Snippet:DetectLastPointAnomaly
160+
//detect
161+
Console.WriteLine("Detecting the anomaly status of the latest point in the series.");
162+
163+
try
164+
{
165+
UnivariateLastDetectionResult result = client.DetectUnivariateLastPoint(request);
166+
167+
if (result.IsAnomaly)
168+
{
169+
Console.WriteLine("The latest point was detected as an anomaly.");
170+
}
171+
else
172+
{
173+
Console.WriteLine("The latest point was not detected as an anomaly.");
174+
}
175+
}
176+
catch (RequestFailedException ex)
177+
{
178+
Console.WriteLine(String.Format("Last detection failed: {0}", ex.Message));
179+
throw;
180+
}
181+
catch (Exception ex)
182+
{
183+
Console.WriteLine(String.Format("Detection error. {0}", ex.Message));
184+
throw;
185+
}
186+
```
187+
188+
### Detect change points
189+
190+
```C# Snippet:DetectChangePoint
191+
//detect
192+
Console.WriteLine("Detecting the change point in the series.");
193+
194+
UnivariateChangePointDetectionResult result = client.DetectUnivariateChangePoint(request);
195+
196+
if (result.IsChangePoint.Contains(true))
197+
{
198+
Console.WriteLine("A change point was detected at index:");
199+
for (int i = 0; i < request.Series.Count; ++i)
200+
{
201+
if (result.IsChangePoint[i])
202+
{
203+
Console.Write(i);
204+
Console.Write(" ");
205+
}
206+
}
207+
Console.WriteLine();
208+
}
209+
else
210+
{
211+
Console.WriteLine("No change point detected in the series.");
212+
}
213+
```
214+
215+
### Multivariate Anomaly Detection Sample
216+
217+
To see how to use Anomaly Detector library to conduct Multivariate Anomaly Detection, see this [sample](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample4_MultivariateDetect.cs).
218+
80219
## Troubleshooting
81220

82221
### Setting up console logging
222+
83223
The simplest way to see the logs is to enable the console logging.
84224
To create an Azure SDK log listener that outputs messages to console use the AzureEventSourceListener.CreateConsoleLogger method.
85225

@@ -90,6 +230,22 @@ using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsole
90230

91231
To learn more about other logging mechanisms see [Diagnostics Samples][logging].
92232

233+
## Next steps
234+
235+
These code samples show common scenario operations with the Azure Anomaly Detector library. More samples can be found under the [samples](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/) directory.
236+
237+
- Univariate Anomaly Detection - Batch Detection: [Sample1_DetectEntireSeriesAnomaly.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample1_DetectEntireSeriesAnomaly.cs)
238+
239+
- Univariate Anomaly Detection - Streaming Detection: [Sample2_DetectLastPointAnomaly.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample2_DetectLastPointAnomaly.cs)
240+
241+
- Univariate Anomaly Detection - Change Point Detection: [Sample3_DetectChangePoint.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample3_DetectChangePoint.cs)
242+
243+
- Multivariate Anomaly Detection: [Sample4_MultivariateDetect.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/tests/samples/Sample4_MultivariateDetect.cs)
244+
245+
### Additional documentation
246+
247+
For more extensive documentation on Azure Anomaly Detector, see the [Anomaly Detector documentation](https://learn.microsoft.com/azure/cognitive-services/anomaly-detector/overview) on docs.microsoft.com.
248+
93249
## Contributing
94250

95251
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][cla].
@@ -98,29 +254,23 @@ When you submit a pull request, a CLA-bot will automatically determine whether y
98254

99255
This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
100256

101-
102257
<!-- LINKS -->
103258
[anomalydetector_client_src]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/src
104259
[anomalydetector_docs]: https://docs.microsoft.com/azure/cognitive-services/anomaly-detector/
105260
[anomalydetector_refdocs]: https://azure.github.io/azure-sdk-for-net/anomalydetector.html
106261
[anomalydetector_nuget_package]: https://www.nuget.org/packages/Azure.AI.AnomalyDetector
107-
108262
[anomaly_detector_client_class]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/anomalydetector/Azure.AI.AnomalyDetector/src/Generated/AnomalyDetectorClient.cs
109263
[azure_identity]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity
110264
[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
111265
[aad_grant_access]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
112266
[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain
113267
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity/README.md
114268
[cognitive_resource_cli]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli
115-
116269
[logging]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/core/Azure.Core/samples/Diagnostics.md
117-
118-
119270
[azure_cli]: https://docs.microsoft.com/cli/azure
120271
[azure_sub]: https://azure.microsoft.com/free/dotnet/
121272
[nuget]: https://www.nuget.org/
122273
[azure_portal]: https://portal.azure.com
123-
124274
[cla]: https://cla.microsoft.com
125275
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
126276
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/

0 commit comments

Comments
 (0)