TimeSeriesCatalog.DetectSeasonality メソッド

定義

時系列データでは、季節性 (または周期性) は、週単位、月単位、四半期単位など、特定の一定の間隔で発生するバリエーションの存在です。

この方法では、フーリエ分析の手法を採用することで、この予測可能な間隔 (または期間) を検出します。 入力値の時間間隔が同じであると仮定すると (たとえば、タイムスタンプで並べ替えられた 1 秒ごとに収集されたセンサー データ)、このメソッドは時系列データの一覧を取得し、入力値全体でこの期間にわたって繰り返しまたは繰り返される予測可能な変動またはパターンが見つかった場合は、入力季節データの定期的な期間を返します。

そのようなパターンが見つからない場合、つまり、入力値が季節変動に従わない場合、-1 を返します。

public static int DetectSeasonality (this Microsoft.ML.AnomalyDetectionCatalog catalog, Microsoft.ML.IDataView input, string inputColumnName, int seasonalityWindowSize = -1, double randomnessThreshold = 0.95);
static member DetectSeasonality : Microsoft.ML.AnomalyDetectionCatalog * Microsoft.ML.IDataView * string * int * double -> int
<Extension()>
Public Function DetectSeasonality (catalog As AnomalyDetectionCatalog, input As IDataView, inputColumnName As String, Optional seasonalityWindowSize As Integer = -1, Optional randomnessThreshold As Double = 0.95) As Integer

パラメーター

catalog
AnomalyDetectionCatalog

季節性の検出カタログ。

input
IDataView

Input DataView.The data is an instance of IDataView.

inputColumnName
String

処理する列の名前。 列データは次の値にする Double必要があります。

seasonalityWindowSize
Int32

入力値で考慮される値の数の上限。 -1 に設定した場合は、入力全体をモデルに合わせて使用します。正の整数に設定すると、最初の windowSize 値の数のみが考慮されます。 既定値は -1 です。

randomnessThreshold
Double

入力値が季節データとして繰り返し予測可能なパターンにどの程度確実に従っているかを指定するランダム性のしきい値。 範囲は [0, 1] です。 既定では、0.95 に設定されています。

戻り値

季節データとしての入力の一定の間隔。それ以外の場合は -1 を返します。

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

namespace Samples.Dynamic
{
    public static class DetectSeasonality
    {
        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 mlContext = new MLContext();

            // Create a seasonal data as input: y = sin(2 * Pi + x)
            var seasonalData = Enumerable.Range(0, 100).Select(x => new TimeSeriesData(Math.Sin(2 * Math.PI + x)));

            // Load the input data as a DataView.
            var dataView = mlContext.Data.LoadFromEnumerable(seasonalData);

            /* Two option parameters:
             * seasonalityWindowSize: Default value is -1. When set to -1, use the whole input to fit model; 
             * when set to a positive integer, only the first windowSize number of values will be considered.
             * randomnessThreshold: Randomness threshold that specifies how confidence the input values follows 
             * a predictable pattern recurring as seasonal data. By default, it is set as 0.99. 
             * The higher the threshold is set, the more strict recurring pattern the 
             * input values should follow to be determined as seasonal data.
             */
            int period = mlContext.AnomalyDetection.DetectSeasonality(
                dataView,
                nameof(TimeSeriesData.Value),
                seasonalityWindowSize: 40);

            // Print the Seasonality Period result.
            Console.WriteLine($"Seasonality Period: #{period}");
        }

        private class TimeSeriesData
        {
            public double Value;

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

    }
}

適用対象