Anomaly Detector v1.1-preview

The Anomaly Detection service detects anomalies automatically in time series data. It supports several functionalities, one is for detecting anomalies in single time-series, including entire, last and change point detection. The other is detecting anomalies in multiple time-series. With univariate anomaly detection ability, business customers can discover incidents and establish a logic flow for root cause analysis. The multivariate anomaly detection APIs in Anomaly Detector analyze dependencies and inter-correlations between different signals. It enables customers to gather a group of related time-series and detect failures with a wholistic view. To ensure online service quality is one of the main reasons we developed this service. Our team is dedicated to continuing to improve the anomaly detection service to provide precise results.

This Multivariate Anomaly Detection is currently available in:

  • East US - eastus.api.cognitive.microsoft.com
  • East US 2 - eastus2.api.cognitive.microsoft.com
  • South Central US - southcentralus.api.cognitive.microsoft.com
  • UK South - uksouth.api.cognitive.microsoft.com
  • West Europe - westeurope.api.cognitive.microsoft.com
  • West US 2 - westus2.api.cognitive.microsoft.com

Multivariate Anomaly Detection - Train a Multivariate Anomaly Detection Model

Create and train a multivariate anomaly detection model. The request must include a source parameter to indicate an externally accessible Azure storage Uri (preferably a Shared Access Signature Uri). All time-series used in generate the model must be zipped into one single file. Each time-series will be in a single CSV file in which the first column is timestamp and the second column is value.

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

Open API testing console

Request URL

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

Training request

{
    "slidingWindow": 200,
    "alignPolicy": {
        "alignMode": "Outer",
        "fillNAMethod": "Linear",
        "paddingValue": 0
    },
    "source": "{your_sas_url}",
    "startTime": "2019-04-09T00:00:00Z",
    "endTime": "2019-04-21T00:00:00Z",
    "displayName": "SampleRequest"
}
{
  "required": [
    "endTime",
    "source",
    "startTime"
  ],
  "properties": {
    "slidingWindow": {
      "type": "integer",
      "description": "An optional field, indicates how many history points will be used to determine the anomaly score of one subsequent point.",
      "example": 28
    },
    "alignPolicy": {
      "description": "An optional field, since those multivariate need to be aligned in the same timestamp before starting the detection.",
      "properties": {
        "alignMode": {
          "type": "string",
          "description": "An optional field, indicates how we align different variables into the same time-range which is required by the model.{Inner, Outer}",
          "example": "Outer",
          "enum": [
            "Inner",
            "Outer"
          ],
          "x-ms-enum": {
            "name": "alignMode",
            "modelAsString": false
          }
        },
        "fillNAMethod": {
          "type": "string",
          "description": "An optional field, indicates how missed values will be filled with. Can not be set to NotFill, when alignMode is Outer.{Previous, Subsequent, Linear, Zero, Fix, NotFill}",
          "example": "Linear",
          "enum": [
            "Previous",
            "Subsequent",
            "Linear",
            "Zero",
            "Pad",
            "NotFill"
          ],
          "x-ms-enum": {
            "name": "fillNAMethod",
            "modelAsString": false
          }
        },
        "paddingValue": {
          "type": "integer",
          "description": "optional field, only be useful if FillNAMethod is set to Pad."
        }
      },
      "type": "object"
    },
    "source": {
      "type": "string",
      "description": "The blob link to the input data. It should be a zipped folder containing csv files. Each csv file should has two columns with header 'timestamp' and 'value' (case sensitive). The file name will be used as the variable name. Please refer to the sample data to prepare your own data accordingly.",
      "example": "{your_sas_url}"
    },
    "startTime": {
      "type": "string",
      "format": "date-time",
      "description": "required field, start time of data to be used for generating multivariate anomaly detection model, should be date-time",
      "example": "2019-04-01T00:00:00Z"
    },
    "endTime": {
      "type": "string",
      "format": "date-time",
      "description": "required field, end time of data to be used for generating multivariate anomaly detection model, should be date-time",
      "example": "2019-04-02T00:00:00Z"
    },
    "displayName": {
      "type": "string",
      "description": "optional field, name of the model",
      "example": "DevOps-MultiAD",
      "maxLength": 24
    },
    "status": {
      "type": "string",
      "description": "Model training status.",
      "x-nullable": false,
      "x-ms-enum": {
        "name": "modelStatus",
        "modelAsString": false
      },
      "example": "READY",
      "enum": [
        "CREATED",
        "RUNNING",
        "READY",
        "FAILED"
      ],
      "readOnly": true
    },
    "errors": {
      "type": "array",
      "description": "Error message when fails to create a model.",
      "readOnly": true,
      "items": {
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "x-nullable": false,
            "description": "The error Code"
          },
          "message": {
            "type": "string",
            "x-nullable": false,
            "description": "A message explaining the error reported by the service."
          }
        },
        "type": "object"
      }
    },
    "diagnosticsInfo": {
      "properties": {
        "modelState": {
          "properties": {
            "epochIds": {
              "type": "array",
              "description": "Epoch id",
              "example": [
                10,
                20,
                30,
                40,
                50,
                60,
                70,
                80,
                90,
                100
              ],
              "items": {
                "type": "integer"
              }
            },
            "trainLosses": {
              "type": "array",
              "example": [
                0.62913280725479126,
                0.16713269054889679,
                0.12354248017072678,
                0.10259664058685303,
                0.095849275588989258,
                0.090699523687362671,
                0.086860164999961853,
                0.086030229926109314,
                0.082873545587062836,
                0.082355380058288574
              ],
              "items": {
                "type": "number"
              }
            },
            "validationLosses": {
              "type": "array",
              "example": [
                0.95734274387359619,
                0.31822299957275391,
                0.34026464819908142,
                0.27653488516807556,
                0.25740143656730652,
                0.26928603649139404,
                0.26372304558753967,
                0.25908330082893372,
                0.2597166895866394,
                0.25973501801490784
              ],
              "items": {
                "type": "number"
              }
            },
            "latenciesInSeconds": {
              "type": "array",
              "example": [
                0.3398594856262207,
                0.3659665584564209,
                0.37360644340515137,
                0.35134077072143555,
                0.33703041076660156,
                0.31876277923583984,
                0.32833099365234375,
                0.35035872459411621,
                0.30800247192382813,
                0.3327946662902832
              ],
              "items": {
                "type": "number"
              }
            }
          },
          "type": "object"
        },
        "variableStates": {
          "type": "array",
          "example": [
            {
              "variable": "ad_input",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "ad_on_timer_output",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "ingestion",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "data_in_speed",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "cpu",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "ad_series_init",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "F-Link_last_check_point_duration",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "data_out_speed",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            },
            {
              "variable": "ad_output",
              "filledNARatio": 0.0,
              "effectiveCount": 1441,
              "startTime": "2019-04-01T00:00:00Z",
              "endTime": "2019-04-02T00:00:00Z",
              "errors": []
            }
          ],
          "items": {
            "properties": {
              "variable": {
                "type": "string",
                "description": "Variable name."
              },
              "filledNARatio": {
                "type": "number",
                "description": "Merged NA ratio of a variable.",
                "minimum": 0,
                "maximum": 1
              },
              "effectiveCount": {
                "type": "integer",
                "description": "Effective time-series points count."
              },
              "startTime": {
                "type": "string",
                "format": "date-time",
                "description": "Start time of a variable"
              },
              "endTime": {
                "type": "string",
                "format": "date-time",
                "description": "End time of a variable"
              },
              "errors": {
                "type": "array",
                "description": "Error message when parse variable",
                "items": {
                  "required": [
                    "code",
                    "message"
                  ],
                  "properties": {
                    "code": {
                      "type": "string",
                      "x-nullable": false,
                      "description": "The error Code"
                    },
                    "message": {
                      "type": "string",
                      "x-nullable": false,
                      "description": "A message explaining the error reported by the service."
                    }
                  },
                  "type": "object"
                }
              }
            },
            "type": "object"
          }
        }
      },
      "type": "object",
      "readOnly": true,
      "description": "Used for deep analysis model and variables"
    }
  },
  "type": "object",
  "description": "Train result of a model including status, errors and diagnose info for model and variables."
}

Response 201

Submit a multivariate model training task successfully.

Response 500

Internal Server Error.

Response 400

Possible Errors:

  • TooManyModel
    This subscription has reached the maximum number of models.
  • TooManyRunningModel
    This subscription has reached the maximum number of running models.
  • InvalidSlidingWindow
    The 'slidingWindow' field must be an integer between 28 and 2880.
  • BadArgument
    The 'source' field is required in the request.
    The 'startTime' field is required in the request.
    The 'endTime' field is required in the request.
    Invalid Timestamp format.
    The displayName length exceeds maximum allowed length 24."
  • VariableNotExist
    The corresponding file of the variable does not exist.
  • MergeDataFailed
    Data provided could be merged into a dataframe. Possibly due to wrong folder structure or data format, invalid column names.
    Folder structure may be changed after compression. Please check the structure is desired after extraction.
    Please refer to the sample data to prepare your own data.
  • ColumnNotFound
    Could not find column "timestamp" in the merged dataframe.
  • NumColumnsMismatch
    Number of columns of merged data does not match the number of variables.
  • CorruptedData
    Data provided could be processed. Possibly due to wrong folder structure or data format, invalid column names.
    Folder structure may be changed after compression. Please check the structure is desired after extraction.
    Please refer to the sample data to prepare your own data.

{  "code" : "TooManyModel",  "message" : "This subscription has reached the maximum number of models."}
{
  "required": [
    "code",
    "message"
  ],
  "properties": {
    "code": {
      "type": "string",
      "x-nullable": false,
      "description": "The error Code"
    },
    "message": {
      "type": "string",
      "x-nullable": false,
      "description": "A message explaining the error reported by the service."
    }
  },
  "type": "object"
}

Response 403

The certificate you provided is not accepted by server.

Response 405

Method Not Allowed.

Code samples

@ECHO OFF

curl -v -X POST "https://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models"
-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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models?" + 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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models");


            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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models?" + $.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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models";
    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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models');
$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('uaenorth.api.cognitive.microsoft.com')
    conn.request("POST", "/anomalydetector/v1.1-preview/multivariate/models?%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('uaenorth.api.cognitive.microsoft.com')
    conn.request("POST", "/anomalydetector/v1.1-preview/multivariate/models?%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://uaenorth.api.cognitive.microsoft.com/anomalydetector/v1.1-preview/multivariate/models')


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