series_seasonal()series_seasonal()

根据检测到的或给定的周期,计算序列的周期性组件。Calculates the seasonal component of a series, according to the detected or given seasonal period.

语法Syntax

series_seasonal(series [, period])series_seasonal(series [, period])

参数Arguments

  • series:输入数值动态数组series: Input numeric dynamic array
  • period(可选):每个周期的整数 bin 数,可能值:period (optional): Integer number of bins in each seasonal period, possible values:
    • -1(默认值):使用阈值为 0.7 的 series_periods_detect() 自动检测期间。-1 (default): Autodetects the period by using series_periods_detect() with a threshold of 0.7. 如果未检测到周期性,则返回零Returns zeroes if seasonality isn't detected
    • 正整数:用作周期性组件的期间Positive integer: Used as the period for the seasonal component
    • 任何其他值:忽略周期性,返回一系列零Any other value: Ignores seasonality and returns a series of zeroes

返回Returns

长度与 series 输入相同的动态数组,其中包含序列的计算出的周期性组件。Dynamic array of the same length as the series input that contains the calculated seasonal component of the series. 周期性组件将计算为所有期间中与 bin 位置相对应的所有值的中值。The seasonal component is calculated as the median of all the values that correspond to the location of the bin, across the periods.

示例Examples

自动检测期间Auto detect the period

在下面的示例中,将自动检测序列的期间。In the following example, the series' period is automatically detected. 检测到第一个序列的期间为六个 bin,第二个序列的周期为五个 bin。第三个序列的期间因太短而检测不到,因此会返回一系列零。The first series' period is detected to be six bins and the second five bins. The third series' period is too short to be detected and returns a series of zeroes. 请参阅下一个有关如何强制使用期间的示例。See the next example on how to force the period.

print s=dynamic([2,5,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1])
| union (print s=dynamic([8,12,14,12,10,10,12,14,12,10,10,12,14,12,10,10,12,14,12,10]))
| union (print s=dynamic([1,3,5,2,4,6,1,3,5,2,4,6]))
| extend s_seasonal = series_seasonal(s)
ss s_seasonals_seasonal
[2,5,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1][2,5,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1,2,3,4,3,2,1] [1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0][1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0,2.0,3.0,4.0,3.0,2.0,1.0]
[8,12,14,12,10,10,12,14,12,10,10,12,14,12,10,10,12,14,12,10][8,12,14,12,10,10,12,14,12,10,10,12,14,12,10,10,12,14,12,10] [10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0][10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0,10.0,12.0,14.0,12.0,10.0]
[1,3,5,2,4,6,1,3,5,2,4,6][1,3,5,2,4,6,1,3,5,2,4,6] [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0][0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]

强制使用期间Force a period

在此示例中,序列的期间太短,无法通过 series_periods_detect() 检测到,因此我们显式地强制使用期间来获取周期模式。In this example, the series' period is too short to be detected by series_periods_detect(), so we explicitly force the period to get the seasonal pattern.

print s=dynamic([1,3,5,1,3,5,2,4,6]) 
| union (print s=dynamic([1,3,5,2,4,6,1,3,5,2,4,6]))
| extend s_seasonal = series_seasonal(s,3)
ss s_seasonals_seasonal
[1,3,5,1,3,5,2,4,6][1,3,5,1,3,5,2,4,6] [1.0,3.0,5.0,1.0,3.0,5.0,1.0,3.0,5.0][1.0,3.0,5.0,1.0,3.0,5.0,1.0,3.0,5.0]
[1,3,5,2,4,6,1,3,5,2,4,6][1,3,5,2,4,6,1,3,5,2,4,6] [1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5][1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5,1.5,3.5,5.5]

后续步骤Next steps