TimeSeriesCatalog.DetectAnomalyBySrCnn 메서드

정의

SRCNN 알고리즘을 사용하여 시간 변칙을 검색하는 Create SrCnnAnomalyEstimator.

public static Microsoft.ML.Transforms.TimeSeries.SrCnnAnomalyEstimator DetectAnomalyBySrCnn (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName, int windowSize = 64, int backAddWindowSize = 5, int lookaheadWindowSize = 5, int averagingWindowSize = 3, int judgementWindowSize = 21, double threshold = 0.3);
public static Microsoft.ML.Transforms.TimeSeries.SrCnnAnomalyEstimator DetectAnomalyBySrCnn (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName, int windowSize = 64, int backAddWindowSize = 5, int lookaheadWindowSize = 5, int averageingWindowSize = 3, int judgementWindowSize = 21, double threshold = 0.3);
static member DetectAnomalyBySrCnn : Microsoft.ML.TransformsCatalog * string * string * int * int * int * int * int * double -> Microsoft.ML.Transforms.TimeSeries.SrCnnAnomalyEstimator
static member DetectAnomalyBySrCnn : Microsoft.ML.TransformsCatalog * string * string * int * int * int * int * int * double -> Microsoft.ML.Transforms.TimeSeries.SrCnnAnomalyEstimator
<Extension()>
Public Function DetectAnomalyBySrCnn (catalog As TransformsCatalog, outputColumnName As String, inputColumnName As String, Optional windowSize As Integer = 64, Optional backAddWindowSize As Integer = 5, Optional lookaheadWindowSize As Integer = 5, Optional averagingWindowSize As Integer = 3, Optional judgementWindowSize As Integer = 21, Optional threshold As Double = 0.3) As SrCnnAnomalyEstimator
<Extension()>
Public Function DetectAnomalyBySrCnn (catalog As TransformsCatalog, outputColumnName As String, inputColumnName As String, Optional windowSize As Integer = 64, Optional backAddWindowSize As Integer = 5, Optional lookaheadWindowSize As Integer = 5, Optional averageingWindowSize As Integer = 3, Optional judgementWindowSize As Integer = 21, Optional threshold As Double = 0.3) As SrCnnAnomalyEstimator

매개 변수

catalog
TransformsCatalog

변환의 카탈로그입니다.

outputColumnName
String

의 변환에서 생성된 열의 inputColumnName이름입니다. 열 데이터는 벡터입니다 Double. 벡터에는 경고(1은 변칙을 의미하고 0은 정상을 의미함), 원시 점수 및 분광 잔류의 크기라는 세 가지 요소가 포함됩니다.

inputColumnName
String

변환할 열의 이름입니다. 열 데이터는 이어야 Single합니다.

windowSize
Int32

스펙트럼 잔류를 계산하기 위한 슬라이딩 윈도우의 크기입니다.

backAddWindowSize
Int32

학습 창을 다시 추가할 지점 수입니다. windowSize일반적으로 기본값을 유지합니다.

lookaheadWindowSize
Int32

예측에 사용되는 다양한 포인트의 수입니다. windowSize일반적으로 기본값을 유지합니다.

averagingWindowSizeaverageingWindowSize
Int32

계열에 대한 살리엔시 맵을 생성할 슬라이딩 윈도우의 크기입니다. windowSize일반적으로 기본값을 유지합니다.

judgementWindowSize
Int32

각 데이터 요소에 대한 변칙 점수를 계산할 슬라이딩 윈도우의 크기입니다. 보다 windowSize더 이상 없습니다.

threshold
Double

임계값보다 큰 비정상 점수를 결정하는 임계값은 변칙으로 간주됩니다. 에 있어야 합니다(0,1)

반환

예제

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

namespace Samples.Dynamic
{
    public static class DetectAnomalyBySrCnn
    {
        // This example creates a time series (list of Data with the i-th element
        // corresponding to the i-th time slot). The estimator is applied then to
        // identify spiking points in the series.
        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(5));
            }
            data.Add(new TimeSeriesData(10));
            for (int index = 0; index < 5; index++)
            {
                data.Add(new TimeSeriesData(5));
            }

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

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

            // The transformed model.
            ITransformer model = ml.Transforms.DetectAnomalyBySrCnn(
                outputColumnName, inputColumnName, 16, 5, 5, 3, 8, 0.35).Fit(
                dataView);

            // Create a time series prediction engine from the model.
            var engine = model.CreateTimeSeriesEngine<TimeSeriesData,
                SrCnnAnomalyDetection>(ml);

            Console.WriteLine($"{outputColumnName} column obtained post-" +
                $"transformation.");

            Console.WriteLine("Data\tAlert\tScore\tMag");

            // Prediction column obtained post-transformation.
            // Data	Alert	Score	Mag

            // Create non-anomalous data and check for anomaly.
            for (int index = 0; index < 20; index++)
            {
                // Anomaly detection.
                PrintPrediction(5, engine.Predict(new TimeSeriesData(5)));
            }

            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.00    0.00
            //5   0   0.03    0.18
            //5   0   0.03    0.18
            //5   0   0.03    0.18
            //5   0   0.03    0.18
            //5   0   0.03    0.18

            // Anomaly.
            PrintPrediction(10, engine.Predict(new TimeSeriesData(10)));

            //10	1	0.47	0.93    <-- alert is on, predicted anomaly

            // Checkpoint the model.
            var modelPath = "temp.zip";
            engine.CheckPoint(ml, modelPath);

            // Load the model.
            using (var file = File.OpenRead(modelPath))
                model = ml.Model.Load(file, out DataViewSchema schema);

            for (int index = 0; index < 5; index++)
            {
                // Anomaly detection.
                PrintPrediction(5, engine.Predict(new TimeSeriesData(5)));
            }

            //5   0   0.31    0.50
            //5   0   0.05    0.30
            //5   0   0.01    0.23
            //5   0   0.00    0.21
            //5   0   0.01    0.25
        }

        private static void PrintPrediction(float value, SrCnnAnomalyDetection
            prediction) =>
            Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", value, prediction
            .Prediction[0], prediction.Prediction[1], prediction.Prediction[2]);

        private class TimeSeriesData
        {
            public float Value;

            public TimeSeriesData(float value)
            {
                Value = value;
            }
        }

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

적용 대상