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

Univariate Anomaly Detection - Find trend change point for the entire series in batch.

This operation generates a model using an entire series, each point is detected with the same model. With this method, points before and after a certain point are used to determine whether it is a trend change point. The entire detection can detect all trend change points of the time series.

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

Time series points, granularity should be set in the request. Advanced model parameters can also be set in the request.

{
    "series": [{
            "value": 116168307,
            "timestamp": "2019-01-01T00:00:00Z"
        },
        {
            "value": 116195090,
            "timestamp": "2019-01-02T00:00:00Z"
        },
        {
            "value": 116219292,
            "timestamp": "2019-01-03T00:00:00Z"
        },
        {
            "value": 116218498,
            "timestamp": "2019-01-04T00:00:00Z"
        },
        {
            "value": 116217643,
            "timestamp": "2019-01-05T00:00:00Z"
        },
        {
            "value": 116234219,
            "timestamp": "2019-01-06T00:00:00Z"
        },
        {
            "value": 116291400,
            "timestamp": "2019-01-07T00:00:00Z"
        },
        {
            "value": 116326509,
            "timestamp": "2019-01-08T00:00:00Z"
        },
        {
            "value": 116323167,
            "timestamp": "2019-01-09T00:00:00Z"
        },
        {
            "value": 116360790,
            "timestamp": "2019-01-10T00:00:00Z"
        },
        {
            "value": 116367491,
            "timestamp": "2019-01-11T00:00:00Z"
        },
        {
            "value": 116371082,
            "timestamp": "2019-01-12T00:00:00Z"
        },
        {
            "value": 116380405,
            "timestamp": "2019-01-13T00:00:00Z"
        },
        {
            "value": 116393919,
            "timestamp": "2019-01-14T00:00:00Z"
        },
        {
            "value": 116443750,
            "timestamp": "2019-01-15T00:00:00Z"
        },
        {
            "value": 116467267,
            "timestamp": "2019-01-16T00:00:00Z"
        },
        {
            "value": 116497910,
            "timestamp": "2019-01-17T00:00:00Z"
        },
        {
            "value": 116499861,
            "timestamp": "2019-01-18T00:00:00Z"
        },
        {
            "value": 116500538,
            "timestamp": "2019-01-19T00:00:00Z"
        },
        {
            "value": 116532052,
            "timestamp": "2019-01-20T00:00:00Z"
        },
        {
            "value": 116559282,
            "timestamp": "2019-01-21T00:00:00Z"
        },
        {
            "value": 116597249,
            "timestamp": "2019-01-22T00:00:00Z"
        },
        {
            "value": 118036892,
            "timestamp": "2019-01-23T00:00:00Z"
        },
        {
            "value": 118090207,
            "timestamp": "2019-01-24T00:00:00Z"
        },
        {
            "value": 118105517,
            "timestamp": "2019-01-25T00:00:00Z"
        },
        {
            "value": 118107624,
            "timestamp": "2019-01-26T00:00:00Z"
        },
        {
            "value": 118138073,
            "timestamp": "2019-01-27T00:00:00Z"
        },
        {
            "value": 118164752,
            "timestamp": "2019-01-28T00:00:00Z"
        },
        {
            "value": 118150854,
            "timestamp": "2019-01-29T00:00:00Z"
        },
        {
            "value": 118168111,
            "timestamp": "2019-01-30T00:00:00Z"
        },
        {
            "value": 118281715,
            "timestamp": "2019-01-31T00:00:00Z"
        },
        {
            "value": 118255480,
            "timestamp": "2019-02-01T00:00:00Z"
        },
        {
            "value": 118256700,
            "timestamp": "2019-02-02T00:00:00Z"
        },
        {
            "value": 118256692,
            "timestamp": "2019-02-03T00:00:00Z"
        },
        {
            "value": 118261555,
            "timestamp": "2019-02-04T00:00:00Z"
        },
        {
            "value": 118271556,
            "timestamp": "2019-02-05T00:00:00Z"
        },
        {
            "value": 118304847,
            "timestamp": "2019-02-06T00:00:00Z"
        },
        {
            "value": 119575122,
            "timestamp": "2019-02-07T00:00:00Z"
        },
        {
            "value": 119575288,
            "timestamp": "2019-02-08T00:00:00Z"
        },
        {
            "value": 119577225,
            "timestamp": "2019-02-09T00:00:00Z"
        },
        {
            "value": 119687273,
            "timestamp": "2019-02-10T00:00:00Z"
        },
        {
            "value": 119696443,
            "timestamp": "2019-02-11T00:00:00Z"
        },
        {
            "value": 119708919,
            "timestamp": "2019-02-12T00:00:00Z"
        },
        {
            "value": 119742399,
            "timestamp": "2019-02-13T00:00:00Z"
        },
        {
            "value": 119783758,
            "timestamp": "2019-02-14T00:00:00Z"
        },
        {
            "value": 119778552,
            "timestamp": "2019-02-15T00:00:00Z"
        },
        {
            "value": 119777165,
            "timestamp": "2019-02-16T00:00:00Z"
        },
        {
            "value": 119839611,
            "timestamp": "2019-02-17T00:00:00Z"
        },
        {
            "value": 118478044,
            "timestamp": "2019-02-18T00:00:00Z"
        },
        {
            "value": 118510659,
            "timestamp": "2019-02-19T00:00:00Z"
        },
        {
            "value": 118536890,
            "timestamp": "2019-02-20T00:00:00Z"
        },
        {
            "value": 120377808,
            "timestamp": "2019-02-21T00:00:00Z"
        },
        {
            "value": 120379137,
            "timestamp": "2019-02-22T00:00:00Z"
        },
        {
            "value": 120380093,
            "timestamp": "2019-02-23T00:00:00Z"
        },
        {
            "value": 120409909,
            "timestamp": "2019-02-24T00:00:00Z"
        },
        {
            "value": 120481097,
            "timestamp": "2019-02-25T00:00:00Z"
        },
        {
            "value": 120525030,
            "timestamp": "2019-02-26T00:00:00Z"
        },
        {
            "value": 120554993,
            "timestamp": "2019-02-27T00:00:00Z"
        },
        {
            "value": 120396587,
            "timestamp": "2019-02-28T00:00:00Z"
        },
        {
            "value": 120389070,
            "timestamp": "2019-03-01T00:00:00Z"
        }
    ],
    "granularity": "daily",
    "customInterval": 1,
    "stableTrendWindow": 5,
    "threshold": 0.9,
    "period": 0
}
{
  "type": "object",
  "required": [
    "granularity",
    "series"
  ],
  "properties": {
    "series": {
      "type": "array",
      "description": "Time series data points. Points should be sorted by timestamp in ascending order to match the change point detection result.",
      "items": {
        "type": "object",
        "required": [
          "value"
        ],
        "properties": {
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Optional argument, timestamp of a data point (ISO8601 format)."
          },
          "value": {
            "type": "number",
            "format": "float",
            "description": "The measurement of that point, should be float."
          }
        }
      }
    },
    "granularity": {
      "type": "string",
      "description": "Can only be one of yearly, monthly, weekly, daily, hourly, minutely or secondly. Granularity is used for verify whether input series is valid.",
      "x-nullable": false,
      "x-ms-enum": {
        "name": "TimeGranularity",
        "modelAsString": false,
        "values": [
          {
            "value": "yearly"
          },
          {
            "value": "monthly"
          },
          {
            "value": "weekly"
          },
          {
            "value": "daily"
          },
          {
            "value": "hourly"
          },
          {
            "name": "perMinute",
            "value": "minutely"
          },
          {
            "name": "perSecond",
            "value": "secondly"
          },
          {
            "value": "microsecond"
          },
          {
            "value": "none"
          }
        ]
      },
      "enum": [
        "yearly",
        "monthly",
        "weekly",
        "daily",
        "hourly",
        "minutely",
        "secondly",
        "microsecond",
        "none"
      ]
    },
    "customInterval": {
      "description": "Custom Interval is used to set non-standard time interval, for example, if the series is 5 minutes, request can be set as {\"granularity\":\"minutely\", \"customInterval\":5}.",
      "type": "integer",
      "format": "int32",
      "x-nullable": false
    },
    "period": {
      "type": "integer",
      "format": "int32",
      "description": "Optional argument, periodic value of a time series. If the value is null or does not present, the API will determine the period automatically."
    },
    "stableTrendWindow": {
      "type": "integer",
      "format": "int32",
      "description": "Optional argument, advanced model parameter, a default stableTrendWindow will be used in detection."
    },
    "threshold": {
      "type": "number",
      "format": "float",
      "description": "Optional argument, advanced model parameter, between 0.0-1.0, the lower the value is, the larger the trend error will be which means less change point will be accepted."
    }
  }
}

Response 200

Successful operation.

{
  "confidenceScores": [
    0,
    0,
    0.00009806187784391992,
    0.0018271196069162686,
    0.0024024970102579477,
    0.0006698841513929579,
    0.005241021191331318,
    0.005608371938773833,
    0.0002582967339394681,
    0.0028641957214850305,
    0.0002086271545768578,
    0.002872596645208636,
    0.0038254365621415275,
    0.0037871087975867787,
    0.002551692781278267,
    0.002795581501682331,
    0.004242681998535293,
    0.0001668205733865953,
    0.0033500664222602655,
    0.0004736963490890601,
    0.0010909427701544395,
    0.004416975679466235,
    0.32811393206802303,
    3.3969062736306306e-15,
    0.0014439526026416374,
    0.0026356798731345843,
    0.00035229328015416554,
    0.0003425625371251363,
    0.004252803662198847,
    0.0026723666415576523,
    0.01203658322275258,
    0.0005797791524039205,
    0.002973159734217919,
    0.00563771188428345,
    0.006702942334305688,
    0.006560331486165724,
    0.0023713364333307675,
    0.28312612517142904,
    3.3969062736306306e-15,
    0.00006728693748012286,
    0.007474321161820017,
    0.0007402854911579185,
    0.0021427717111760516,
    0.0010456722259841228,
    0.0006710836684717039,
    0.004880561063393699,
    0.007855787427509102,
    0.00015617505084218866,
    0.2230962081216851,
    3.3969062736306306e-15,
    0.00024255212249064555,
    0.11668400494338521,
    6.793812547261261e-15,
    0.000014171670068597315,
    0.0019566935039425576,
    0.006387099509754672,
    0.005234041196046256,
    0.002723346117254897,
    0.02386583326609911,
    0.01847725899081154
  ],
  "isChangePoint": [
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    true,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    true,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    true,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false
  ],
  "period": 0
}
{
  "type": "object",
  "properties": {
    "period": {
      "type": "integer",
      "format": "int32",
      "readOnly": true,
      "description": "Frequency extracted from the series, zero means no recurrent pattern has been found."
    },
    "isChangePoint": {
      "type": "array",
      "description": "isChangePoint contains change point properties for each input point. True means an anomaly either negative or positive has been detected. The index of the array is consistent with the input series.",
      "items": {
        "type": "boolean",
        "readOnly": true,
        "x-nullable": false
      }
    },
    "confidenceScores": {
      "type": "array",
      "description": "the change point confidence of each point",
      "items": {
        "type": "number",
        "format": "float",
        "readOnly": true,
        "x-nullable": false
      }
    }
  }
}

Response 400

Possible Errors:

  • BadArgument
    Invalid json format, input data is Empty.
    The 'series' field is required in request.
    The 'granularity' field is required in request.
    The 'series' field cannot be empty.
    The 'series' field must be array/list type.
    'timestamp' or 'value' is malformed in 'series' Field.
    The 'series' field cannot have none values.
  • InvalidCustomInterval
    The 'customInterval' field must be an integer > 0.
  • InvalidGranularity
    The 'granularity' field can only be one of the following: ['daily', 'minutely', 'hourly', 'weekly', 'monthly', 'yearly', 'secondly'].
  • InvalidPeriod
    The 'period' field must be an integer >= 0.
  • InvalidModelArgument
    The 'maxAnomalyRatio' field must be less than 50% of the series points (0 < maxAnomalyRatio < 0.5).
    The 'sensitivity' field must be an integer between 0 and 99.
    The 'series' field must have more than 2 periods points.
  • InvalidSeries
    The 'series' field must be sorted by timestamp in ascending order.
    The 'series' field cannot have duplicated timestamp.
    Time points should be uniformly spaced in time in minutely granularity with 1 gran as interval, ratio of missing points should be less than 10%.
    The 'series' field must have at least 12 points.
    The 'series' field cannot have more than 8640 points.

{
  "code" : "InvalidSeries",
  "message" : "The 'series' field cannot be empty."
}

Response 403

The certificate you provided is not accepted by server.

Response 405

Method Not Allowed.

Response 500

Internal Server Error.

Code samples

@ECHO OFF

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


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


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