close
Ref:
https://github.com/shey/changepoint
需要的套件:numpy
依需求修改:bootstrap(重複抽樣) 預設為1000次目的:不想看極端區域加入以下程式碼
# Get normal block avg=numpy.average(data) std=numpy.std(data) print 'avg:%f std:%f'%(avg,std) print '' cut=0 normalData=[] for i in points: if i>cut: print 'ChangePoint:%d'%i blockAVG=numpy.average(data[cut:i]) print '%d ~ %d, block avg:%f'%(cut,i-1,blockAVG), if (blockAVG > (avg-std)) and (blockAVG < (avg+std)): print ', Get Normal Block [%d:%d]'%(cut,i-1) normalData.extend(data[cut:i]) else: print ', Skip Extreme Block [%d:%d]'%(cut,i-1) cut=i print '' print 'normal avg:%f'%numpy.average(normalData)
output:
avg:53.935015 std:81.504027
ChangePoint:941
0 ~ 940, block avg:377.180659 , Skip Extreme Block [0:940]
ChangePoint:10434
941 ~ 10433, block avg:38.574634 , Get Normal Block [941:10433]
ChangePoint:13387
10434 ~ 13386, block avg:27.919404 , Get Normal Block [10434:13386]
ChangePoint:17238
13387 ~ 17237, block avg:41.136848 , Get Normal Block [13387:17237]
ChangePoint:17626
17238 ~ 17625, block avg:26.123711 , Get Normal Block [17238:17625]
ChangePoint:18020
17626 ~ 18019, block avg:16.406091 , Get Normal Block [17626:18019]
ChangePoint:18073
18020 ~ 18072, block avg:11.547170 , Get Normal Block [18020:18072]
ChangePoint:18091
18073 ~ 18090, block avg:5.333333 , Get Normal Block [18073:18090]
ChangePoint:18133
18091 ~ 18132, block avg:1.333333 , Get Normal Block [18091:18132]
normal avg:36.320207
全站熱搜