Share via


AnomalyDetectorClient.TrainMultivariateModel Method

Definition

Overloads

TrainMultivariateModel(ModelInfo, CancellationToken)

Train a Multivariate Anomaly Detection Model.

TrainMultivariateModel(RequestContent, RequestContext)

[Protocol Method] Train a Multivariate Anomaly Detection Model

TrainMultivariateModel(ModelInfo, CancellationToken)

Source:
AnomalyDetectorClient.cs

Train a Multivariate Anomaly Detection Model.

public virtual Azure.Response<Azure.AI.AnomalyDetector.AnomalyDetectionModel> TrainMultivariateModel (Azure.AI.AnomalyDetector.ModelInfo modelInfo, System.Threading.CancellationToken cancellationToken = default);
abstract member TrainMultivariateModel : Azure.AI.AnomalyDetector.ModelInfo * System.Threading.CancellationToken -> Azure.Response<Azure.AI.AnomalyDetector.AnomalyDetectionModel>
override this.TrainMultivariateModel : Azure.AI.AnomalyDetector.ModelInfo * System.Threading.CancellationToken -> Azure.Response<Azure.AI.AnomalyDetector.AnomalyDetectionModel>
Public Overridable Function TrainMultivariateModel (modelInfo As ModelInfo, Optional cancellationToken As CancellationToken = Nothing) As Response(Of AnomalyDetectionModel)

Parameters

modelInfo
ModelInfo

Model information.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

modelInfo is null.

Examples

This sample shows how to call TrainMultivariateModel with required parameters.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);

var modelInfo = new ModelInfo("<dataSource>", DateTimeOffset.UtcNow, DateTimeOffset.UtcNow)
{
    DataSchema = DataSchema.OneTable,
    DisplayName = "<DisplayName>",
    SlidingWindow = 1234,
    AlignPolicy = new AlignPolicy()
{
        AlignMode = AlignMode.Inner,
        FillNAMethod = FillNAMethod.Previous,
        PaddingValue = 3.14f,
    },
};
var result = client.TrainMultivariateModel(modelInfo);

Remarks

Create and train a multivariate anomaly detection model. The request must include a source parameter to indicate an Azure Blob Storage URI that's accessible to the service. There are two types of data input. The Blob Storage URI can point to an Azure Blob Storage folder that contains multiple CSV files, where each CSV file has two columns, time stamp and variable. Or the Blob Storage URI can point to a single blob that contains a CSV file that has all the variables and a time stamp column.

Applies to

TrainMultivariateModel(RequestContent, RequestContext)

Source:
AnomalyDetectorClient.cs

[Protocol Method] Train a Multivariate Anomaly Detection Model

public virtual Azure.Response TrainMultivariateModel (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member TrainMultivariateModel : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
override this.TrainMultivariateModel : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
Public Overridable Function TrainMultivariateModel (content As RequestContent, Optional context As RequestContext = Nothing) As Response

Parameters

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

This sample shows how to call TrainMultivariateModel with required request content, and how to parse the result.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);

var data = new {
    dataSource = "<dataSource>",
    startTime = "2022-05-10T14:57:31.2311892-04:00",
    endTime = "2022-05-10T14:57:31.2311892-04:00",
};

Response response = client.TrainMultivariateModel(RequestContent.Create(data));

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("modelId").ToString());
Console.WriteLine(result.GetProperty("createdTime").ToString());
Console.WriteLine(result.GetProperty("lastUpdatedTime").ToString());

This sample shows how to call TrainMultivariateModel with all request content, and how to parse the result.

var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);

var data = new {
    dataSource = "<dataSource>",
    dataSchema = "OneTable",
    startTime = "2022-05-10T14:57:31.2311892-04:00",
    endTime = "2022-05-10T14:57:31.2311892-04:00",
    displayName = "<displayName>",
    slidingWindow = 1234,
    alignPolicy = new {
        alignMode = "Inner",
        fillNAMethod = "Previous",
        paddingValue = 123.45f,
    },
};

Response response = client.TrainMultivariateModel(RequestContent.Create(data), new RequestContext());

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("modelId").ToString());
Console.WriteLine(result.GetProperty("createdTime").ToString());
Console.WriteLine(result.GetProperty("lastUpdatedTime").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("dataSource").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("dataSchema").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("startTime").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("endTime").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("displayName").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("slidingWindow").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("alignPolicy").GetProperty("alignMode").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("alignPolicy").GetProperty("fillNAMethod").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("alignPolicy").GetProperty("paddingValue").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("status").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("errors")[0].GetProperty("code").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("errors")[0].GetProperty("message").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("modelState").GetProperty("epochIds")[0].ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("modelState").GetProperty("trainLosses")[0].ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("modelState").GetProperty("validationLosses")[0].ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("modelState").GetProperty("latenciesInSeconds")[0].ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("variableStates")[0].GetProperty("variable").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("variableStates")[0].GetProperty("filledNARatio").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("variableStates")[0].GetProperty("effectiveCount").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("variableStates")[0].GetProperty("firstTimestamp").ToString());
Console.WriteLine(result.GetProperty("modelInfo").GetProperty("diagnosticsInfo").GetProperty("variableStates")[0].GetProperty("lastTimestamp").ToString());

Remarks

Create and train a multivariate anomaly detection model. The request must include a source parameter to indicate an externally accessible Azure blob storage URI.There are two types of data input: An URI pointed to an Azure blob storage folder which contains multiple CSV files, and each CSV file contains two columns, timestamp and variable. Another type of input is an URI pointed to a CSV file in Azure blob storage, which contains all the variables and a timestamp column.

Below is the JSON schema for the request and response payloads.

Request Body:

Schema for ModelInfo:

{
  dataSource: string, # Required.
  dataSchema: "OneTable" | "MultiTable", # Optional.
  startTime: string (date & time), # Required.
  endTime: string (date & time), # Required.
  displayName: string, # Optional.
  slidingWindow: number, # Optional.
  alignPolicy: {
    alignMode: "Inner" | "Outer", # Optional.
    fillNAMethod: "Previous" | "Subsequent" | "Linear" | "Zero" | "Fixed", # Optional.
    paddingValue: number, # Optional.
  }, # Optional.
  status: "CREATED" | "RUNNING" | "READY" | "FAILED", # Optional.
  errors: [
    {
      code: string, # Required.
      message: string, # Required.
    }
  ], # Optional.
  diagnosticsInfo: {
    modelState: {
      epochIds: [number], # Optional.
      trainLosses: [number], # Optional.
      validationLosses: [number], # Optional.
      latenciesInSeconds: [number], # Optional.
    }, # Optional.
    variableStates: [VariableState], # Optional.
  }, # Optional.
}

Response Body:

Schema for AnomalyDetectionModel:

{
  modelId: string, # Required.
  createdTime: string (date & time), # Required.
  lastUpdatedTime: string (date & time), # Required.
  modelInfo: {
    dataSource: string, # Required.
    dataSchema: "OneTable" | "MultiTable", # Optional.
    startTime: string (date & time), # Required.
    endTime: string (date & time), # Required.
    displayName: string, # Optional.
    slidingWindow: number, # Optional.
    alignPolicy: {
      alignMode: "Inner" | "Outer", # Optional.
      fillNAMethod: "Previous" | "Subsequent" | "Linear" | "Zero" | "Fixed", # Optional.
      paddingValue: number, # Optional.
    }, # Optional.
    status: "CREATED" | "RUNNING" | "READY" | "FAILED", # Optional.
    errors: [
      {
        code: string, # Required.
        message: string, # Required.
      }
    ], # Optional.
    diagnosticsInfo: {
      modelState: {
        epochIds: [number], # Optional.
        trainLosses: [number], # Optional.
        validationLosses: [number], # Optional.
        latenciesInSeconds: [number], # Optional.
      }, # Optional.
      variableStates: [VariableState], # Optional.
    }, # Optional.
  }, # Optional.
}

Applies to