Anomaly Detector v1.1

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 ML knowledge, either batch validation or real-time inference. It includes the following features:

  • Univariate Anomaly Detection - Detect different types of anomalies in single variable.
  • Multivariate Anomaly Detection - Detect different types of anomalies in multiple variables from your equipment or system.

Multivariate Anomaly Detection - Detect Multivariate Anomaly

Submit multivariate anomaly detection task with the modelId of trained model and inference data, the input schema should be the same with the training request. The request will complete asynchronously and return a resultId to query the detection result.The request should be a source link to indicate an externally accessible Azure storage Uri, either pointed to an Azure blob storage folder, or pointed to a CSV file in Azure blob storage.

Select the testing console in the region where you created your resource:

Open API testing console

Request URL

Request parameters

string

Format - uuid. Format - uuid. Model identifier.

Request headers

string
Media type of the body sent to the API.
string
Subscription key which provides access to this API. Found in your Cognitive Services accounts.

Request body

Detect anomaly request

{
  "dataSource": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv",
  "topContributorCount": 10,
  "startTime": "2022-04-01T00:15:00Z",
  "endTime": "2022-04-01T00:40:00Z"
}
{
  "required": [
    "dataSource",
    "endTime",
    "startTime",
    "topContributorCount"
  ],
  "properties": {
    "dataSource": {
      "type": "string",
      "description": "Source link to the input data to indicate an accessible Azure storage Uri, either pointed to an Azure blob storage folder, or pointed to a CSV file in Azure blob storage based on you data schema selection. The data schema should be exactly the same with those used in the training phase.",
      "example": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv"
    },
    "topContributorCount": {
      "type": "integer",
      "description": "An optional field, which is used to specify the number of top contributed variables for one anomalous timestamp in the response. The default number is 10.",
      "example": 10
    },
    "startTime": {
      "type": "string",
      "format": "date-time",
      "description": "A required field, indicating the start time of data for detection, which should be date-time of ISO 8601 format.",
      "example": "2022-04-01T00:15:00Z"
    },
    "endTime": {
      "type": "string",
      "format": "date-time",
      "description": "A required field, indicating the end time of data for detection, which should be date-time of ISO 8601 format.",
      "example": "2022-04-01T00:40:00Z"
    }
  },
  "type": "object",
  "description": "Detection request for batch inference. This is an asynchronous inference which will need another API to get detection results.",
  "example": {
    "dataSource": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv",
    "topContributorCount": 10,
    "startTime": "2022-04-01T00:15:00Z",
    "endTime": "2022-04-01T00:40:00Z"
  }
}

Response 202

Submit a multivariate model detection task successfully.

{
  "resultId": "45aad126-aafd-11ea-b8fb-d89ef3400c5f",
  "summary": {
    "status": "READY",
    "errors": [
      {
        "code": "string",
        "message": "string"
      }
    ],
    "variableStates": [
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_1"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_2"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_3"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_4"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_5"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_6"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_7"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_8"
      },
      {
        "effectiveCount": 1441,
        "lastTimestamp": "2022-04-02T00:00:00Z",
        "filledNARatio": 0,
        "firstTimestamp": "2022-04-01T00:00:00Z",
        "variable": "variable_9"
      }
    ],
    "setupInfo": {
      "dataSource": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv",
      "topContributorCount": 10,
      "startTime": "2022-04-01T00:15:00Z",
      "endTime": "2022-04-01T00:40:00Z"
    }
  },
  "results": [
    {
      "timestamp": "2022-01-01T00:00:00Z",
      "value": {
        "isAnomaly": true,
        "severity": 0.8,
        "score": 0.3,
        "interpretation": [
          {
            "variable": "variable_1",
            "contributionScore": 0.3324159383,
            "correlationChanges": {
              "changedVariables": [
                "variable_2",
                "variable_3"
              ]
            }
          }
        ]
      },
      "errors": [
        {
          "code": "string",
          "message": "string"
        }
      ]
    }
  ]
}
{
  "required": [
    "resultId",
    "results",
    "summary"
  ],
  "properties": {
    "resultId": {
      "type": "string",
      "format": "uuid",
      "description": "Result identifier, which is used to fetch the results of an inference call.",
      "example": "45aad126-aafd-11ea-b8fb-d89ef3400c5f"
    },
    "summary": {
      "required": [
        "setupInfo",
        "status"
      ],
      "properties": {
        "status": {
          "description": "Status of detection results. One of CREATED, RUNNING, READY, and FAILED.",
          "enum": [
            "CREATED",
            "RUNNING",
            "READY",
            "FAILED"
          ],
          "example": "READY",
          "type": "string",
          "x-ms-enum": {
            "modelAsString": false,
            "name": "DetectionStatus",
            "values": [
              {
                "value": "CREATED"
              },
              {
                "value": "RUNNING"
              },
              {
                "value": "READY"
              },
              {
                "value": "FAILED"
              }
            ]
          }
        },
        "errors": {
          "type": "array",
          "description": "Error message when detection is failed.",
          "items": {
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "The error code."
              },
              "message": {
                "type": "string",
                "description": "The message explaining the error reported by the service."
              }
            },
            "type": "object"
          }
        },
        "variableStates": {
          "type": "array",
          "example": [
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_1"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_2"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_3"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_4"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_5"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_6"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_7"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_8"
            },
            {
              "effectiveCount": 1441,
              "lastTimestamp": "2022-04-02T00:00:00Z",
              "filledNARatio": 0,
              "firstTimestamp": "2022-04-01T00:00:00Z",
              "variable": "variable_9"
            }
          ],
          "items": {
            "properties": {
              "variable": {
                "type": "string",
                "description": "Variable name in variable states."
              },
              "filledNARatio": {
                "type": "number",
                "description": "Proportion of missing values that need to be filled by fillNAMethod.",
                "minimum": 0,
                "maximum": 1
              },
              "effectiveCount": {
                "type": "integer",
                "description": "Number of effective data points before applying fillNAMethod."
              },
              "firstTimestamp": {
                "type": "string",
                "format": "date-time",
                "description": "First valid timestamp with value of input data."
              },
              "lastTimestamp": {
                "type": "string",
                "format": "date-time",
                "description": "Last valid timestamp with value of input data."
              }
            },
            "type": "object"
          }
        },
        "setupInfo": {
          "required": [
            "dataSource",
            "endTime",
            "startTime",
            "topContributorCount"
          ],
          "properties": {
            "dataSource": {
              "type": "string",
              "description": "Source link to the input data to indicate an accessible Azure storage Uri, either pointed to an Azure blob storage folder, or pointed to a CSV file in Azure blob storage based on you data schema selection. The data schema should be exactly the same with those used in the training phase.",
              "example": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv"
            },
            "topContributorCount": {
              "type": "integer",
              "description": "An optional field, which is used to specify the number of top contributed variables for one anomalous timestamp in the response. The default number is 10.",
              "example": 10
            },
            "startTime": {
              "type": "string",
              "format": "date-time",
              "description": "A required field, indicating the start time of data for detection, which should be date-time of ISO 8601 format.",
              "example": "2022-04-01T00:15:00Z"
            },
            "endTime": {
              "type": "string",
              "format": "date-time",
              "description": "A required field, indicating the end time of data for detection, which should be date-time of ISO 8601 format.",
              "example": "2022-04-01T00:40:00Z"
            }
          },
          "type": "object",
          "description": "Detection request for batch inference. This is an asynchronous inference which will need another API to get detection results.",
          "example": {
            "dataSource": "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv",
            "topContributorCount": 10,
            "startTime": "2022-04-01T00:15:00Z",
            "endTime": "2022-04-01T00:40:00Z"
          }
        }
      },
      "type": "object",
      "description": "Multivariate anomaly detection status."
    },
    "results": {
      "type": "array",
      "description": "Detection result for each timestamp.",
      "items": {
        "required": [
          "timestamp"
        ],
        "properties": {
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp for this anomaly.",
            "example": "2022-01-01T00:00:00Z"
          },
          "value": {
            "required": [
              "isAnomaly",
              "score",
              "severity"
            ],
            "properties": {
              "isAnomaly": {
                "type": "boolean",
                "description": "True if an anomaly is detected at the current timestamp.",
                "example": true
              },
              "severity": {
                "type": "number",
                "description": "Indicates the significance of the anomaly. The higher the severity, the more significant the anomaly is.",
                "example": 0.8,
                "minimum": 0,
                "maximum": 1
              },
              "score": {
                "type": "number",
                "description": "Raw anomaly score of severity, will help indicate the degree of abnormality as well.",
                "example": 0.3,
                "minimum": 0,
                "maximum": 2
              },
              "interpretation": {
                "type": "array",
                "items": {
                  "description": "Interpretation contains more details of the anomaly, which will help with root cause analysis.",
                  "allOf": [
                    {
                      "properties": {
                        "variable": {
                          "type": "string",
                          "description": "Variable.",
                          "example": "variable_1"
                        },
                        "contributionScore": {
                          "type": "number",
                          "description": "This score shows the percentage contributing to the anomalous timestamp. A number between 0 and 1.",
                          "example": 0.3324159383
                        },
                        "correlationChanges": {
                          "example": {
                            "changedVariables": [
                              "variable_2",
                              "variable_3"
                            ]
                          },
                          "properties": {
                            "changedVariables": {
                              "type": "array",
                              "description": "The correlated variables that have correlation changes under an anomaly.",
                              "example": [
                                "variable_2",
                                "variable_3"
                              ],
                              "items": {
                                "type": "string"
                              }
                            }
                          },
                          "type": "object"
                        }
                      },
                      "type": "object"
                    }
                  ]
                }
              }
            },
            "type": "object"
          },
          "errors": {
            "type": "array",
            "description": "Error message for the current timestamp.",
            "items": {
              "required": [
                "code",
                "message"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "description": "The error code."
                },
                "message": {
                  "type": "string",
                  "description": "The message explaining the error reported by the service."
                }
              },
              "type": "object"
            }
          }
        },
        "type": "object"
      }
    }
  },
  "type": "object",
  "description": "Detection results for the given resultId."
}

Response 500

Error response.

{
  "code": "string",
  "message": "string"
}
{
  "required": [
    "code",
    "message"
  ],
  "properties": {
    "code": {
      "type": "string",
      "description": "The error code."
    },
    "message": {
      "type": "string",
      "description": "The message explaining the error reported by the service."
    }
  },
  "type": "object"
}

Code samples

@ECHO OFF

curl -v -X POST "https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch"
-H "Content-Type: application/json"
-H "Ocp-Apim-Subscription-Key: {subscription key}"

--data-ascii "{body}" 
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }
        
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");

            var uri = "https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}	
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch");


            URI uri = builder.build();
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "application/json");
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");


            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
    $(function() {
        var params = {
            // Request parameters
        };
      
        $.ajax({
            url: "https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Content-Type","application/json");
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSString* path = @"https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"POST"];
    // Request headers
    [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [_request setValue:@"{subscription key}" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
    // Request body
    [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];

    if (nil != error)
    {
        NSLog(@"Error: %@", error);
    }
    else
    {
        NSError* error = nil;
        NSMutableDictionary* json = nil;
        NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", dataString);
        
        if (nil != _connectionData)
        {
            json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
        }
        
        if (error || !json)
        {
            NSLog(@"Could not parse loaded json with error:%@", error);
        }
        
        NSLog(@"%@", json);
        _connectionData = nil;
    }
    
    [pool drain];

    return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.urlencode({
})

try:
    conn = httplib.HTTPSConnection('*.cognitiveservices.azure.com')
    conn.request("POST", "/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
})

try:
    conn = http.client.HTTPSConnection('*.cognitiveservices.azure.com')
    conn.request("POST", "/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
require 'net/http'

uri = URI('https://*.cognitiveservices.azure.com/anomalydetector/v1.1/multivariate/models/{modelId}:detect-batch')


request = Net::HTTP::Post.new(uri.request_uri)
# Request headers
request['Content-Type'] = 'application/json'
# Request headers
request['Ocp-Apim-Subscription-Key'] = '{subscription key}'
# Request body
request.body = "{body}"

response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
end

puts response.body