在Python中检测信号(时间序列)中的季节性的最佳方法是什么?我想为算法提供信号,输出应为1表示存在季节性,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到小值,或相反。还包括一些带参数限制的噪声检测,这应该限制接受的噪声量。