Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.26k stars 4.6k forks source link

[BUG] AnomalyDetectorClient DetectUnivariateEntireSeries returns other response than comparable REST API call #37563

Open sandervandevelde opened 1 year ago

sandervandevelde commented 1 year ago

Library name and version

Azure.AI.AnomalyDetector 3.0.0-preview-7

Describe the bug

The output of the DetectUnivariateEntireSeries method returns another response than the Powershell equivalent and the Rest API (those two are on par).

I double-checked the used data set and (three) parameters (seen in the data file, next to the dataset).

Expected behavior

Compare it with this with the HTTPS Rest API call:

static readonly HttpClient client = new HttpClient();

...

client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "[secret]");

var bodyJson = File.ReadAllText("body.json");

var content = new StringContent(bodyJson);

using HttpResponseMessage response =
    await client.PostAsync(
        "https://anomalydetection-test-weu-ad.cognitiveservices.azure.com/anomalydetector/v1.0/timeseries/entire/detect",
        content);

response.EnsureSuccessStatusCode();

string responseBody = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseBody);

Which returns:

,"isAnomaly":[false,false,false,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,false,false,false,false,false,false,false,false],
"isNegativeAnomaly":[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false],
"isPositiveAnomaly":[false,false,false,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,false,false,false,false,false,false,false,false],

This is on par with the powershell example https://github.com/MicrosoftLearning/AI-900-AIFundamentals/blob/main/detect-anomalies.ps1

Only the 26th element is an anomaly

This is what I expect.

Actual behavior

I try to recreate the anomaly detection example as seen at https://github.com/MicrosoftLearning/AI-900-AIFundamentals (with the data found at https://github.com/MicrosoftLearning/AI-900-AIFundamentals/tree/main/data/anomaly)

I execute:

var client =
    new AnomalyDetectorClient(new Uri("https://anomalydetection-test-weu-ad.cognitiveservices.azure.com/"),
    new Azure.AzureKeyCredential("[secret]"));

var bodyJson = File.ReadAllText("body.json");

var content = JsonConvert.DeserializeObject<body>(bodyJson);

var request = new UnivariateDetectionOptions(content.series)
{
    Granularity = new TimeGranularity(content.granularity),
    Sensitivity = content.sensitivity,
    MaxAnomalyRatio = content.maxAnomalyRatio
};

UnivariateEntireDetectionResult result = client.DetectUnivariateEntireSeries(request);

It returns a response like:

Anomaly:
False; False; False; False; False; False; False; False; False; False; False; False; False; True; False; False; False; False; False; True; True; True; False; False; False; True; False; False; False; True; True; False; False; False; False; False; False; True; False; False; False; False; False; False; False; True; True; True;
Negative:
False; False; False; False; False; False; False; False; False; False; False; False; False; True; False; False; False; False; False; True; True; True; 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;
Positive:
False; False; False; 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; True; True; False; False; False; False; False; False; False; False; False; False; False; False; False; False; True; True; True;

The response is not comparable with the C# Rest API example or PowerShell example. More items than only the 26th element are anomalies.

Reproduction Steps

Create an Azure Anomaly detector instance (I did this yesterday morning) (free pricing tier).

Get the key and endpoint URI.

Use these variables for this powershell script: https://github.com/MicrosoftLearning/AI-900-AIFundamentals/blob/main/detect-anomalies.ps1

Remember the powershell output.

Use these variables for the REST API call.

Compare the output with the powershell output. These are on par.

Use the variables with the Nuget AnomalyDetectorClient DetectUnivariateEntireSeries code.

Compare the output with the powershell output. These are on not par.

Environment

Executed on Surface Pro 7 with Latest Visual Studio Enterprise 2022.


Microsoft Visual Studio Enterprise 2022 Version 17.6.4 VisualStudio.17.Release/17.6.4+33815.320 Microsoft .NET Framework Version 4.8.09032

Installed Version: Enterprise

Visual C++ 2022 00482-20600-04237-AA616 Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.6.326.62524 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.6.326.62524 Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.6.326.62524 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.23087.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

GitHub Copilot 1.94.0.0 (v1.94.0.0@6586dd2df) GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

GitHub Copilot Agent 1.94.220 (v1.94.0)

Linux Core Dump Debugging 1.0.9.33801 Enables debugging of Linux core dumps.

Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Django support 17.0.23087.1 Provides templates and integration for the Django web framework.

Python - Profiling support 17.0.23087.1 Profiling support for Python projects.

Python with Pylance 17.0.23087.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.6.0.2327201+a6a61fdfa748eaa65aab53dab583276e26af4a3e Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.6.13.0 Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 17.0.20329.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.6.0-3.23259.8+c3cc1d0ceeab1a65da0217e403851a1e8a30086a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Linux Development 1.0.9.33801 Visual C++ for Linux Development

Visual F# Tools 17.6.0-beta.23174.5+0207bea1afae48d9351ac26fb51afc8260de0a97 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

github-actions[bot] commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

navba-MSFT commented 1 year ago

Adding Service team to look into this.

github-actions[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @yingqunpku @bowgong @conhua @mengaims @juaduan @moreOver0.

sandervandevelde commented 1 year ago

Can you reproduce this using the same nuget package?

sandervandevelde commented 1 year ago

Are there any updates?