...
/Multivariate Anomaly Detection - Testing and Best Practices
Multivariate Anomaly Detection - Testing and Best Practices
Learn to build and perform anomaly detection on multi-variate data using the Azure Anomaly Detectors.
To recap, in the previous lesson, we prepared and uploaded the dataset to Azure blob storage and generated the SAS URL. Then, we submitted a request for model training to detect the multi-variate anomalies in the dataset. After that, we have checked the status of the model.
Detecting anomalies using the trained model
Once the model is trained successfully, it’s ready to detect the anomalies in the dataset.
Press + to interact
anomaly_detector_key
Not Specified...
anomaly_detector_endpoint
Not Specified...
multi_variate_trained_model_id
Not Specified...
blob_data_sas_url = "<YOUR_BLOB_SAS_URL_FOR_ZIP_FILE>"start_time = datetime(2021, 1, 1, 0, 0, 0)end_time = datetime(2021, 1, 2, 12, 0, 0)detection_req = DetectionRequest(source = blob_data_sas_url, start_time = start_time, end_time = end_time)response_header = anomaly_detector_client.detect_anomaly(multi_variate_trained_model_id,detection_req,cls = lambda *args: [args[i] for i in range(len(args))])[-1]result_id = response_header['Location'].split("/")[-1]results = anomaly_detector_client.get_detection_result(result_id)while results.summary.status != DetectionStatus.READY and results.summary.status != DetectionStatus.FAILED:results = anomaly_detector_client.get_detection_result(result_id)time.sleep(1)if results.summary.status == DetectionStatus.FAILED:if results.summary.errors:for error in results.summary.errors:print("The Error code: {}. ".format(error.code))print("The Error Message: {}".format(error.message))anomaly_detect_results = []for res in results.results:anomaly = {}if res.value is not None:value = res.valueis_anomaly = value.is_anomalyif is_anomaly is True:anomaly["timestamp"] = res.timestamp.strftime("%m/%d/%Y, %H:%M:%S")anomaly["variable_contributing"] = []anomaly["severity"] = value.severityfor contributing_factor in value.contributors:anomaly["variable_contributing"].append(contributing_factor.variable)anomaly_detect_results.append(anomaly)print("Total number of anomalies identified: ", len(anomaly_detect_results))print("Anomaly Identified:")for anomaly in anomaly_detect_results:print(anomaly)
...