Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sdk/anomalydetector/azure-ai-anomalydetector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Release History

## 3.0.0b4 (Unreleased)
## 3.0.0b4 (2021-12-20)

# TODO: Service team fill out
**Features**
- Introduced the new API: `AnomalyDetectorClientOperationsMixin.last_detect_anomaly`.
- Added 2 new optional properties: `impute_mode` & `impute_fixed_value` to `DetectRequest` object.
- Added 1 new optional property: `severity` to the `EntireDetectResponse` & `LastDetectResponse` objects.
- Removed the optional property `errors` from the `VariableState` object.
- Refactored the optional property `contributors` to `interpretation` from the `AnomalyValue` object.
- Modified the `FillNAMethod` object into an extensible enum.

## 3.0.0b3 (2021-04-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These sample programs show common scenarios for the Anomaly Detector client's of
|[sample_detect_entire_series_anomaly.py][sample_detect_entire_series_anomaly] |Detecting anomalies in the entire time series.|
|[sample_detect_last_point_anomaly.py][sample_detect_last_point_anomaly] |Detecting the anomaly status of the latest data point.|
|[sample_detect_change_point.py][sample_detect_change_point] |Detecting change points in the entire time series.|
|[sample_multivariate_detect.py][sample_multivariate_detect] |Detecting anomalies in the multivariate time series.|

## Prerequisites
* Python 2.7 or 3.5 or higher is required to use this package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ def detect_change_point(self):

try:
response = client.detect_change_point(request)
except AnomalyDetectorError as e:
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))

except Exception as e:
print(e)
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))

if any(response.is_change_point):
print('An change point was detected at index:')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ def detect_entire_series(self):

try:
response = client.detect_entire_series(request)
except AnomalyDetectorError as e:
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))
except Exception as e:
print(e)
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))

if any(response.is_anomaly):
print('An anomaly was detected at index:')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ def detect_last_point(self):

try:
response = client.detect_last_point(request)
except AnomalyDetectorError as e:
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))
except Exception as e:
print(e)
print('Error code: {}'.format(e.error.code), 'Error message: {}'.format(e.error.message))

if response.is_anomaly:
print('The latest point is detected as anomaly.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
from datetime import datetime, timezone

from azure.ai.anomalydetector import AnomalyDetectorClient
from azure.ai.anomalydetector.models import DetectionRequest, ModelInfo
from azure.ai.anomalydetector.models import DetectionRequest, ModelInfo, LastDetectionRequest
from azure.ai.anomalydetector.models import ModelStatus, DetectionStatus
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import HttpResponseError


class MultivariateSample:

def __init__(self, subscription_key, anomaly_detector_endpoint, data_source=None):
Expand Down Expand Up @@ -142,6 +141,14 @@ def delete_model(self, model_id):
print("{:d} available models after deletion.".format(len(model_list_after_delete)))


def last_detect(self, model_id, variables, detecting_points):

# Detect anomaly by sync api
last_detection_req = LastDetectionRequest(variables=variables, detecting_points=detecting_points)
r = self.ad_client.last_detect_anomaly(model_id, last_detection_req)
print("Get last detection result")
return r

if __name__ == '__main__':
SUBSCRIPTION_KEY = os.environ["ANOMALY_DETECTOR_KEY"]
ANOMALY_DETECTOR_ENDPOINT = os.environ["ANOMALY_DETECTOR_ENDPOINT"]
Expand All @@ -159,7 +166,7 @@ def delete_model(self, model_id):
datetime(2021, 1, 2, 12, 0, 0, tzinfo=timezone.utc))
assert model_id is not None

# Reference
# Inference
result = sample.detect(model_id, datetime(2021, 1, 2, 12, 0, 0, tzinfo=timezone.utc),
datetime(2021, 1, 3, 0, 0, 0, tzinfo=timezone.utc))
assert result is not None
Expand All @@ -173,3 +180,32 @@ def delete_model(self, model_id):

# Delete model
sample.delete_model(model_id)

# *******************************************************************************************************************
# use your own inference data sending to last detection api, you should define your own variables and detectingPoints
# *****************************************************************************************************************
# define "<YOUR OWN variables>"
variables = [
{
"name": "variables_name1",
"timestamps": ['2021-01-01T00:00:00Z', '2021-01-01T00:01:00Z', ...],
"values": [0, 0, ...]
},
{
"name": "variables_name2",
"timestamps": ['2021-01-01T00:00:00Z', '2021-01-01T00:01:00Z', ...],
"values": [0, 0, ...]
}
]
# define <YOUR OWN number of detectingPoints>"
detectingPoints = 10

# Last detection
last_detect_result = sample.last_detect(model_id, variables, detectingPoints)

assert last_detect_result is not None

print("Variable States:\t", last_detect_result.variable_states)
print("Variable States length:\t", len(last_detect_result.variable_states))
print("Results:\t", last_detect_result.results)
print("Results length:\t", len(last_detect_result.results))