Python季节性检测

时间:2017-10-28 01:28:11

标签: time-series signals detection

在Python中检测信号(时间序列)中的季节性的最佳方法是什么?我想为算法提供信号,输出应为1,表示存在季节性,0表示不存在。

1 个答案:

答案 0 :(得分:0)

希望对一些基本用法有所帮助,但对于复杂的问题,我仍然不建议这样做。我编写的一个简单的季节性检测代码:

def check_repetition(arr, limit, index_start, index_end):
    """
    Checks repetition in data so that we can apply de-noising.
    """
    length = index_start

    # length is the length we want to apply the checking
    # check how many periods there are with that kind of length
    for i in range(0, int( len(array)/length)):

        # if the difference in seasons is not smaller than the limit
        condition  = np.array( arr[i:int(i+length)]) - np.array( arr[int( i+length):int( i+2*length)])
        condition  = np.sum([abs(number) for number in condition])

        if condition >= limit :
            # check if the length is still bigger than the limit
            # increase the length to check 
            if length + 1 <= index_end:
                #print( "Checked for length:" + str( length))
                return check_repetition(arr, limit, length + 1, index_end)

            # if not than no more computations needed
            else:
                return 0

        # if it passed the for loop for one cycle of i then return the number of entries per cycle
        if i == int( len(array)/length)-2:
            return(length)

    # if nothing worked
    return 0

这将返回季节性长度。您可以从数组长度/ 2到较小值(或相反)的季节性开始使用它。还包括一些带有参数限制的噪声检测,这应该限制接受的噪声量。