Skip to content

Commit 6736583

Browse files
committed
Update docs metadata
1 parent a1f0cc9 commit 6736583

File tree

2 files changed

+269
-19
lines changed

2 files changed

+269
-19
lines changed

docs-ref-services/preview/ai-anomalydetector-readme.md

Lines changed: 266 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,283 @@ title:
33
keywords: Azure, python, SDK, API, azure-ai-anomalydetector, anomalydetector
44
author: conhua
55
ms.author: conhua
6-
ms.date: 03/31/2022
6+
ms.date: 12/09/2022
77
ms.topic: reference
8-
ms.prod: azure
9-
ms.technology: azure
108
ms.devlang: python
119
ms.service: anomalydetector
1210
---
13-
# Microsoft Azure Anomaly Detector SDK for Python
11+
# Cognitive Services Anomaly Detector client library for Python
1412

15-
This is the Microsoft Azure Cognitive Services Anomaly Detector Client Library.
16-
This package has been tested with Python 2.7, 3.5, 3.6, 3.7 and 3.8.
13+
[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.
1714

18-
For a more complete set of Azure libraries, see the
19-
[azure sdk python release](https://aka.ms/azsdk/python/all).
15+
## Getting started
2016

21-
## Usage
17+
### Prerequisites
2218

23-
For code examples, see [Cognitive Services Anomaly Detector](https://docs.microsoft.com/python/api/overview/azure/cognitive-services)
24-
on docs.microsoft.com.
19+
- Python 3.7 or later is required to use this package.
20+
- You need an [Azure subscription][azure_sub] to use this package.
21+
- An existing Cognitive Services Anomaly Detector instance.
2522

23+
### Install the package
2624

27-
## Provide Feedback
25+
```bash
26+
python -m pip install azure-ai-anomalydetector
27+
```
2828

29-
If you encounter any bugs or have suggestions, please file an issue in the
30-
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
31-
section of the project.
29+
> Note: This version of the client library defaults to the `3.0.0b6` version of the service.
3230
31+
This table shows the relationship between SDK versions and supported API versions of the service:
3332

34-
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-cognitiveservices-anomalydetector%2FREADME.png)
33+
|SDK version|Supported API version of service |
34+
|-------------|---------------|
35+
|3.0.0b6 | 1.1|
36+
|3.0.0b4, 3.0.0b5| 1.1-preview-1|
37+
|3.0.0b3 | 1.1-preview|
38+
|3.0.0b1, 3.0.0b2 | 1.0 |
39+
40+
### Authenticate the client
41+
42+
#### Get the endpoint
43+
44+
You can find the endpoint for your Anomaly Detector service resource using the
45+
[Azure Portal](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesAnomalyDetector)
46+
or [Azure CLI](https://learn.microsoft.com/cli/azure/):
47+
48+
```bash
49+
# Get the endpoint for the Anomaly Detector service resource
50+
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"
51+
```
52+
53+
#### Get the API Key
54+
55+
You can get the **API Key** from the Anomaly Detector service resource in the Azure Portal.
56+
Alternatively, you can use **Azure CLI** snippet below to get the API key of your resource.
57+
58+
```PowerShell
59+
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>
60+
```
61+
62+
#### Create a AnomalyDetectorClient with an API Key Credential
63+
64+
Once you have the value for the API key, you can pass it as a string into an instance of **AzureKeyCredential**. Use the key as the credential parameter
65+
to authenticate the client:
66+
67+
```python
68+
from azure.core.credentials import AzureKeyCredential
69+
from azure.ai.anomalydetector import AnomalyDetectorClient
70+
71+
credential = AzureKeyCredential("<api_key>")
72+
client = AnomalyDetectorClient(endpoint="https://<resource-name>.cognitiveservices.azure.com/", credential=credential)
73+
```
74+
75+
## Key concepts
76+
77+
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**.
78+
79+
|Feature |Description |
80+
|---------|---------|
81+
|Univariate Anomaly Detection | Detect anomalies in one variable, like revenue, cost, etc. The model was selected automatically based on your data pattern. |
82+
|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.|
83+
84+
### Univariate Anomaly Detection
85+
86+
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.
87+
88+
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.
89+
90+
With the Univariate Anomaly Detection, you can automatically detect anomalies throughout your time series data, or as they occur in real-time.
91+
92+
|Feature |Description |
93+
|---------|---------|
94+
| 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. |
95+
| 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. |
96+
| 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. |
97+
98+
### Multivariate Anomaly Detection
99+
100+
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.
101+
102+
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.
103+
104+
- **Training**: Use Train Model API to create and train a model, then use Get Model Status API to get the status and model metadata.
105+
- **Inference**:
106+
- 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.
107+
- You could also use Sync Inference API to trigger a detection on one timestamp every time.
108+
- **Other operations**: List Model API and Delete Model API are supported in Multivariate Anomaly Detection model for model management.
109+
110+
### Thread safety
111+
112+
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.
113+
114+
## Examples
115+
116+
The following section provides several code snippets covering some of the most common Anomaly Detector service tasks, including:
117+
118+
- [Univariate Anomaly Detection - Batch detection](#batch-detection)
119+
- [Univariate Anomaly Detection - Streaming detection](#streaming-detection)
120+
- [Univariate Anomaly Detection - Detect change points](#detect-change-points)
121+
- [Multivariate Anomaly Detection](#multivariate-anomaly-detection-sample)
122+
123+
### Batch detection
124+
125+
```python
126+
from azure.ai.anomalydetector import AnomalyDetectorClient
127+
from azure.core.credentials import AzureKeyCredential
128+
from azure.ai.anomalydetector.models import *
129+
130+
131+
SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"]
132+
ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
133+
TIME_SERIES_DATA_PATH = os.path.join("sample_data", "request-data.csv")
134+
client = AnomalyDetectorClient(ANOMALY_DETECTOR_ENDPOINT, AzureKeyCredential(SUBSCRIPTION_KEY))
135+
136+
series = []
137+
data_file = pd.read_csv(TIME_SERIES_DATA_PATH, header=None, encoding="utf-8", parse_dates=[0])
138+
for index, row in data_file.iterrows():
139+
series.append(TimeSeriesPoint(timestamp=row[0], value=row[1]))
140+
141+
request = UnivariateDetectionOptions(
142+
series=series,
143+
granularity=TimeGranularity.DAILY,
144+
)
145+
146+
147+
if any(response.is_anomaly):
148+
print("An anomaly was detected at index:")
149+
for i, value in enumerate(response.is_anomaly):
150+
if value:
151+
print(i)
152+
else:
153+
print("No anomalies were detected in the time series.")
154+
155+
```
156+
157+
### Streaming Detection
158+
159+
```python
160+
from azure.ai.anomalydetector import AnomalyDetectorClient
161+
from azure.core.credentials import AzureKeyCredential
162+
from azure.ai.anomalydetector.models import *
163+
164+
165+
SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"]
166+
ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
167+
TIME_SERIES_DATA_PATH = os.path.join("sample_data", "request-data.csv")
168+
client = AnomalyDetectorClient(ANOMALY_DETECTOR_ENDPOINT, AzureKeyCredential(SUBSCRIPTION_KEY))
169+
170+
series = []
171+
data_file = pd.read_csv(TIME_SERIES_DATA_PATH, header=None, encoding="utf-8", parse_dates=[0])
172+
for index, row in data_file.iterrows():
173+
series.append(TimeSeriesPoint(timestamp=row[0], value=row[1]))
174+
175+
request = UnivariateDetectionOptions(
176+
series=series,
177+
granularity=TimeGranularity.DAILY,
178+
)
179+
print("Detecting the anomaly status of the latest data point.")
180+
181+
if response.is_anomaly:
182+
print("The latest point is detected as anomaly.")
183+
else:
184+
print("The latest point is not detected as anomaly.")
185+
```
186+
187+
### Detect change points
188+
189+
```python
190+
from azure.ai.anomalydetector import AnomalyDetectorClient
191+
from azure.core.credentials import AzureKeyCredential
192+
from azure.ai.anomalydetector.models import *
193+
194+
195+
SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"]
196+
ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
197+
TIME_SERIES_DATA_PATH = os.path.join("sample_data", "request-data.csv")
198+
client = AnomalyDetectorClient(ANOMALY_DETECTOR_ENDPOINT, AzureKeyCredential(SUBSCRIPTION_KEY))
199+
200+
series = []
201+
data_file = pd.read_csv(TIME_SERIES_DATA_PATH, header=None, encoding="utf-8", parse_dates=[0])
202+
for index, row in data_file.iterrows():
203+
series.append(TimeSeriesPoint(timestamp=row[0], value=row[1]))
204+
205+
request = UnivariateChangePointDetectionOptions(
206+
series=series,
207+
granularity=TimeGranularity.DAILY,
208+
)
209+
210+
211+
if any(response.is_change_point):
212+
print("An change point was detected at index:")
213+
for i, value in enumerate(response.is_change_point):
214+
if value:
215+
print(i)
216+
else:
217+
print("No change point were detected in the time series.")
218+
219+
```
220+
221+
### Multivariate Anomaly Detection Sample
222+
223+
To see how to use Anomaly Detector library to conduct Multivariate Anomaly Detection, see this [sample](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py).
224+
225+
To get more details of Anomaly Detector package, refer to this [azure.ai.anomalydetector package](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-ai-anomalydetector/latest/azure.ai.anomalydetector.html#).
226+
227+
## Troubleshooting
228+
229+
### General
230+
231+
Anomaly Detector client library will raise exceptions defined in [Azure Core](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html#module-azure.core.exceptions).
232+
233+
### Logging
234+
235+
This library uses the standard [logging](https://docs.python.org/3/library/logging.html) library for logging.
236+
237+
Basic information about HTTP sessions (URLs, headers, etc.) is logged at `INFO` level.
238+
239+
Detailed `DEBUG` level logging, including request/response bodies and **unredacted**
240+
headers, can be enabled on the client or per-operation with the `logging_enable` keyword argument.
241+
242+
See full SDK logging documentation with examples [here](https://learn.microsoft.com/azure/developer/python/sdk/azure-sdk-logging).
243+
244+
### Optional Configuration
245+
246+
Optional keyword arguments can be passed in at the client and per-operation level.
247+
The azure-core [reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-core/latest/azure.core.html) describes available configurations for retries, logging, transport protocols, and more.
248+
249+
## Next steps
250+
251+
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-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/) directory.
252+
253+
- Univariate Anomaly Detection - Batch Detection: [sample_detect_entire_series_anomaly.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_entire_series_anomaly.py)
254+
255+
- Univariate Anomaly Detection - Streaming Detection: [sample_detect_last_point_anomaly.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_last_point_anomaly.py)
256+
257+
- Univariate Anomaly Detection - Change Point Detection: [sample_detect_change_point.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_detect_change_point.py)
258+
259+
- Multivariate Anomaly Detection: [sample_multivariate_detect.py](https://github.com/Azure/azure-sdk-for-python/blob/azure-ai-anomalydetector_3.0.0b6/sdk/anomalydetector/azure-ai-anomalydetector/samples/sample_multivariate_detect.py)
260+
261+
### Additional documentation
262+
263+
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.
264+
265+
## Contributing
266+
267+
This project welcomes contributions and suggestions. Most contributions require
268+
you to agree to a Contributor License Agreement (CLA) declaring that you have
269+
the right to, and actually do, grant us the rights to use your contribution.
270+
For details, visit [CLA homepage](https://cla.microsoft.com).
271+
272+
When you submit a pull request, a CLA-bot will automatically determine whether
273+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
274+
comment). Simply follow the instructions provided by the bot. You will only
275+
need to do this once across all repos using our CLA.
276+
277+
This project has adopted the
278+
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
279+
see the Code of Conduct FAQ or contact [email protected] with any
280+
additional questions or comments.
281+
282+
<!-- LINKS -->
283+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
284+
[azure_sub]: https://azure.microsoft.com/free/
35285

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "azure-ai-anomalydetector",
3-
"Version": "3.0.0a20220330002",
4-
"DevVersion": "3.0.0a20220330002",
3+
"Version": "3.0.0b6",
4+
"DevVersion": null,
55
"DirectoryPath": "sdk/anomalydetector/azure-ai-anomalydetector",
66
"ServiceDirectory": "anomalydetector",
77
"ReadMePath": "sdk/anomalydetector/azure-ai-anomalydetector/README.md",
@@ -10,5 +10,5 @@
1010
"SdkType": "client",
1111
"IsNewSdk": true,
1212
"ArtifactName": "azure-ai-anomalydetector",
13-
"ReleaseStatus": "Unreleased"
13+
"ReleaseStatus": "2022-12-08"
1414
}

0 commit comments

Comments
 (0)