TimeSeriesCatalog.DetectSeasonality 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在時間序列資料中,季節性 (或週期性) 是特定定期發生的變化,例如每週、每月或每季。
這個方法會採用四位分析技術,以偵測這個可預測的間隔 (或期間) 。 假設輸入值有相同的時間間隔 (例如,依時間戳記) 排序每秒所收集的感應器資料,此方法會採用時間序列資料的清單,並傳回輸入季節性資料的一般期間,如果可預測的波動或模式可在整個輸入值期間內遞迴或重複。
如果找不到這類模式,則傳回 -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
偵測季節性目錄。
- seasonalityWindowSize
- Int32
輸入值中要考慮的值數目上限。 當設定為 -1 時,請使用整個輸入來符合模型;當設定為正整數時,只會考慮第一個 windowSize 值數目。 預設值為 -1。
傳回
輸入為季節性資料的定期間隔,否則會傳回 -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;
}
}
}
}