共用方式為


TimeSeriesCatalog.DetectSeasonality 方法

定義

在時間序列資料中,季節性 (或週期性) 是特定定期發生的變化,例如每週、每月或每季。

這個方法會採用四位分析技術,以偵測這個可預測的間隔 (或期間) 。 假設輸入值有相同的時間間隔 (例如,依時間戳記) 排序每秒所收集的感應器資料,此方法會採用時間序列資料的清單,並傳回輸入季節性資料的一般期間,如果可預測的波動或模式可在整個輸入值期間內遞迴或重複。

如果找不到這類模式,則傳回 -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

輸入 DataView。資料是 的 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;
            }
        }

    }
}

適用於