TimeSeriesCatalog.DetectEntireAnomalyBySrCnn 方法

定義

多載

DetectEntireAnomalyBySrCnn(AnomalyDetectionCatalog, IDataView, String, String, SrCnnEntireAnomalyDetectorOptions)

建立 Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetector ,它會使用 SRCNN 演算法偵測整個輸入的逾時異常狀況。

DetectEntireAnomalyBySrCnn(AnomalyDetectionCatalog, IDataView, String, String, Double, Int32, Double, SrCnnDetectMode)

建立 Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetector ,它會使用 SRCNN 演算法偵測整個輸入的逾時異常狀況。

DetectEntireAnomalyBySrCnn(AnomalyDetectionCatalog, IDataView, String, String, SrCnnEntireAnomalyDetectorOptions)

建立 Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetector ,它會使用 SRCNN 演算法偵測整個輸入的逾時異常狀況。

public static Microsoft.ML.IDataView DetectEntireAnomalyBySrCnn (this Microsoft.ML.AnomalyDetectionCatalog catalog, Microsoft.ML.IDataView input, string outputColumnName, string inputColumnName, Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetectorOptions options);
static member DetectEntireAnomalyBySrCnn : Microsoft.ML.AnomalyDetectionCatalog * Microsoft.ML.IDataView * string * string * Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetectorOptions -> Microsoft.ML.IDataView
<Extension()>
Public Function DetectEntireAnomalyBySrCnn (catalog As AnomalyDetectionCatalog, input As IDataView, outputColumnName As String, inputColumnName As String, options As SrCnnEntireAnomalyDetectorOptions) As IDataView

參數

catalog
AnomalyDetectionCatalog

AnomalyDetectionCatalog。

input
IDataView

輸入 DataView。

outputColumnName
String

由 資料處理 inputColumnName 所產生的資料行名稱。 資料行資料是 的 Double 向量。 此向量的長度會根據 options.DetectMode.DetectMode 而有所不同。

inputColumnName
String

要處理的資料行名稱。 資料行資料必須是 Double

options
SrCnnEntireAnomalyDetectorOptions

定義載入作業的設定。

傳回

範例

using System;
using System.Collections.Generic;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.TimeSeries;

namespace Samples.Dynamic
{
    public static class DetectEntireAnomalyBySrCnn
    {
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, 
            // as well as the source of randomness.
            var ml = new MLContext();

            // Generate sample series data with an anomaly
            var data = new List<TimeSeriesData>();
            for (int index = 0; index < 20; index++)
            {
                data.Add(new TimeSeriesData { Value = 5 });
            }
            data.Add(new TimeSeriesData { Value = 10 });
            for (int index = 0; index < 5; index++)
            {
                data.Add(new TimeSeriesData { Value = 5 });
            }

            // Convert data to IDataView.
            var dataView = ml.Data.LoadFromEnumerable(data);

            // Setup the detection arguments
            string outputColumnName = nameof(SrCnnAnomalyDetection.Prediction);
            string inputColumnName = nameof(TimeSeriesData.Value);

            // Do batch anomaly detection
            var outputDataView = ml.AnomalyDetection.DetectEntireAnomalyBySrCnn(dataView, outputColumnName, inputColumnName,
                threshold: 0.35, batchSize: 512, sensitivity: 90.0, detectMode: SrCnnDetectMode.AnomalyAndMargin);

            // Getting the data of the newly created column as an IEnumerable of
            // SrCnnAnomalyDetection.
            var predictionColumn = ml.Data.CreateEnumerable<SrCnnAnomalyDetection>(
                outputDataView, reuseRowObject: false);

            Console.WriteLine("Index\tData\tAnomaly\tAnomalyScore\tMag\tExpectedValue\tBoundaryUnit\tUpperBoundary\tLowerBoundary");

            int k = 0;
            foreach (var prediction in predictionColumn)
            {
                PrintPrediction(k, data[k].Value, prediction);
                k++;
            }
            //Index Data    Anomaly AnomalyScore    Mag ExpectedValue   BoundaryUnit UpperBoundary   LowerBoundary
            //0       5.00    0               0.00    0.21            5.00            5.00            5.01            4.99
            //1       5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //2       5.00    0               0.00    0.03            5.00            5.00            5.01            4.99
            //3       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //4       5.00    0               0.00    0.03            5.00            5.00            5.01            4.99
            //5       5.00    0               0.00    0.06            5.00            5.00            5.01            4.99
            //6       5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //7       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //8       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //9       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //10      5.00    0               0.00    0.00            5.00            5.00            5.01            4.99
            //11      5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //12      5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //13      5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //14      5.00    0               0.00    0.07            5.00            5.00            5.01            4.99
            //15      5.00    0               0.00    0.08            5.00            5.00            5.01            4.99
            //16      5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //17      5.00    0               0.00    0.05            5.00            5.00            5.01            4.99
            //18      5.00    0               0.00    0.12            5.00            5.00            5.01            4.99
            //19      5.00    0               0.00    0.17            5.00            5.00            5.01            4.99
            //20      10.00   1               0.50    0.80            5.00            5.00            5.01            4.99
            //21      5.00    0               0.00    0.16            5.00            5.00            5.01            4.99
            //22      5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //23      5.00    0               0.00    0.05            5.00            5.00            5.01            4.99
            //24      5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //25      5.00    0               0.00    0.19            5.00            5.00            5.01            4.99
        }

        private static void PrintPrediction(int idx, double value, SrCnnAnomalyDetection prediction) =>
            Console.WriteLine("{0}\t{1:0.00}\t{2}\t\t{3:0.00}\t{4:0.00}\t\t{5:0.00}\t\t{6:0.00}\t\t{7:0.00}\t\t{8:0.00}",
                idx, value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2],
                prediction.Prediction[3], prediction.Prediction[4], prediction.Prediction[5], prediction.Prediction[6]);

        private class TimeSeriesData
        {
            public double Value { get; set; }
        }

        private class SrCnnAnomalyDetection
        {
            [VectorType]
            public double[] Prediction { get; set; }
        }
    }
}

適用於

DetectEntireAnomalyBySrCnn(AnomalyDetectionCatalog, IDataView, String, String, Double, Int32, Double, SrCnnDetectMode)

建立 Microsoft.ML.TimeSeries.SrCnnEntireAnomalyDetector ,它會使用 SRCNN 演算法偵測整個輸入的逾時異常狀況。

public static Microsoft.ML.IDataView DetectEntireAnomalyBySrCnn (this Microsoft.ML.AnomalyDetectionCatalog catalog, Microsoft.ML.IDataView input, string outputColumnName, string inputColumnName, double threshold = 0.3, int batchSize = 1024, double sensitivity = 99, Microsoft.ML.TimeSeries.SrCnnDetectMode detectMode = Microsoft.ML.TimeSeries.SrCnnDetectMode.AnomalyOnly);
static member DetectEntireAnomalyBySrCnn : Microsoft.ML.AnomalyDetectionCatalog * Microsoft.ML.IDataView * string * string * double * int * double * Microsoft.ML.TimeSeries.SrCnnDetectMode -> Microsoft.ML.IDataView
<Extension()>
Public Function DetectEntireAnomalyBySrCnn (catalog As AnomalyDetectionCatalog, input As IDataView, outputColumnName As String, inputColumnName As String, Optional threshold As Double = 0.3, Optional batchSize As Integer = 1024, Optional sensitivity As Double = 99, Optional detectMode As SrCnnDetectMode = Microsoft.ML.TimeSeries.SrCnnDetectMode.AnomalyOnly) As IDataView

參數

catalog
AnomalyDetectionCatalog

AnomalyDetectionCatalog。

input
IDataView

輸入 DataView。

outputColumnName
String

由 資料處理 inputColumnName 所產生的資料行名稱。 資料行資料是 的 Double 向量。 此向量的長度會根據 detectMode 而有所不同。

inputColumnName
String

要處理的資料行名稱。 資料行資料必須是 Double

threshold
Double

判斷異常的臨界值。 當指定點的計算 SR 原始分數超過設定的臨界值時,就會偵測到異常。 此閾值必須介於 [0,1] 之間,且其預設值為 0.3。

batchSize
Int32

將輸入資料分割成批次以符合 srcnn 模型。 當設定為 -1 時,請使用整個輸入來容納模型,而不是批次,當設定為正整數時,請使用這個數位作為批次大小。 必須是 -1 或正整數,不小於 12。 預設值為 1024。

sensitivity
Double

界限的敏感度,只有在 srCnnDetectMode 為 AnomalyAndMargin 時才有用。 必須位於 [0,100]。 預設值為 99。

detectMode
SrCnnDetectMode

SrCnnDetectMode 列舉類型。 當設定為 AnomalyOnly 時,輸出向量會是 3 元素 Double 向量, (IsAnomaly、RawScore、Mag) 。 當設定為 AnomalyAndExpectedValue 時,輸出向量會是 (IsAnomaly、RawScore、Mag、ExpectedValue) 的 4 元素 Double 向量。 當設定為 AnomalyAndMargin 時,輸出向量會是 (IsAnomaly、AnomalyScore、Mag、ExpectedValue、BoundaryUnit、UpperBoundary、LowerBoundary) 的 7 元素 Double 向量。 RawScore 是由 SR 輸出,以判斷某個點是否為異常,在 AnomalyAndMargin 模式下,當某個點為異常時,系統會根據敏感度設定來計算 AnomalyScore。 預設值為 AnomalyOnly。

傳回

範例

using System;
using System.Collections.Generic;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.TimeSeries;

namespace Samples.Dynamic
{
    public static class DetectEntireAnomalyBySrCnn
    {
        public static void Example()
        {
            // Create a new ML context, for ML.NET operations. It can be used for
            // exception tracking and logging, 
            // as well as the source of randomness.
            var ml = new MLContext();

            // Generate sample series data with an anomaly
            var data = new List<TimeSeriesData>();
            for (int index = 0; index < 20; index++)
            {
                data.Add(new TimeSeriesData { Value = 5 });
            }
            data.Add(new TimeSeriesData { Value = 10 });
            for (int index = 0; index < 5; index++)
            {
                data.Add(new TimeSeriesData { Value = 5 });
            }

            // Convert data to IDataView.
            var dataView = ml.Data.LoadFromEnumerable(data);

            // Setup the detection arguments
            string outputColumnName = nameof(SrCnnAnomalyDetection.Prediction);
            string inputColumnName = nameof(TimeSeriesData.Value);

            // Do batch anomaly detection
            var outputDataView = ml.AnomalyDetection.DetectEntireAnomalyBySrCnn(dataView, outputColumnName, inputColumnName,
                threshold: 0.35, batchSize: 512, sensitivity: 90.0, detectMode: SrCnnDetectMode.AnomalyAndMargin);

            // Getting the data of the newly created column as an IEnumerable of
            // SrCnnAnomalyDetection.
            var predictionColumn = ml.Data.CreateEnumerable<SrCnnAnomalyDetection>(
                outputDataView, reuseRowObject: false);

            Console.WriteLine("Index\tData\tAnomaly\tAnomalyScore\tMag\tExpectedValue\tBoundaryUnit\tUpperBoundary\tLowerBoundary");

            int k = 0;
            foreach (var prediction in predictionColumn)
            {
                PrintPrediction(k, data[k].Value, prediction);
                k++;
            }
            //Index Data    Anomaly AnomalyScore    Mag ExpectedValue   BoundaryUnit UpperBoundary   LowerBoundary
            //0       5.00    0               0.00    0.21            5.00            5.00            5.01            4.99
            //1       5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //2       5.00    0               0.00    0.03            5.00            5.00            5.01            4.99
            //3       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //4       5.00    0               0.00    0.03            5.00            5.00            5.01            4.99
            //5       5.00    0               0.00    0.06            5.00            5.00            5.01            4.99
            //6       5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //7       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //8       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //9       5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //10      5.00    0               0.00    0.00            5.00            5.00            5.01            4.99
            //11      5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //12      5.00    0               0.00    0.01            5.00            5.00            5.01            4.99
            //13      5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //14      5.00    0               0.00    0.07            5.00            5.00            5.01            4.99
            //15      5.00    0               0.00    0.08            5.00            5.00            5.01            4.99
            //16      5.00    0               0.00    0.02            5.00            5.00            5.01            4.99
            //17      5.00    0               0.00    0.05            5.00            5.00            5.01            4.99
            //18      5.00    0               0.00    0.12            5.00            5.00            5.01            4.99
            //19      5.00    0               0.00    0.17            5.00            5.00            5.01            4.99
            //20      10.00   1               0.50    0.80            5.00            5.00            5.01            4.99
            //21      5.00    0               0.00    0.16            5.00            5.00            5.01            4.99
            //22      5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //23      5.00    0               0.00    0.05            5.00            5.00            5.01            4.99
            //24      5.00    0               0.00    0.11            5.00            5.00            5.01            4.99
            //25      5.00    0               0.00    0.19            5.00            5.00            5.01            4.99
        }

        private static void PrintPrediction(int idx, double value, SrCnnAnomalyDetection prediction) =>
            Console.WriteLine("{0}\t{1:0.00}\t{2}\t\t{3:0.00}\t{4:0.00}\t\t{5:0.00}\t\t{6:0.00}\t\t{7:0.00}\t\t{8:0.00}",
                idx, value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2],
                prediction.Prediction[3], prediction.Prediction[4], prediction.Prediction[5], prediction.Prediction[6]);

        private class TimeSeriesData
        {
            public double Value { get; set; }
        }

        private class SrCnnAnomalyDetection
        {
            [VectorType]
            public double[] Prediction { get; set; }
        }
    }
}

適用於