突变点检测:Pettitt突变点检测(python)
生活随笔
收集整理的這篇文章主要介紹了
突变点检测:Pettitt突变点检测(python)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
該算法依據Pettitt突變檢測相關理論以及R代碼。不過。。。。。。沒有P值(R中的P值是通過蒙特卡洛方法估計,該方法是封裝的)
import numpy as np import pandas as pddef Pettitt_change_point_detection(inputdata):inputdata = np.array(inputdata)n = inputdata.shape[0]k = range(n)inputdataT = pd.Series(inputdata)r = inputdataT.rank()Uk = [2*np.sum(r[0:x])-x*(n + 1) for x in k]Uka = list(np.abs(Uk))U = np.max(Uka)K = Uka.index(U)pvalue = 2 * np.exp((-6 * (U**2))/(n**3 + n**2))if pvalue <= 0.05:change_point_desc = '顯著'else:change_point_desc = '不顯著'#Pettitt_result = {'突變點位置':K,'突變程度':change_point_desc}return K #,Pettitt_result測試(同樣是對比):
dt = [2413.291, 2201.967, 2363.555, 2086.259, 2070.092, 2242.442, 3091.346, 1326.768, 1595.619, 1631.493, 1797.879, 2044.798, 1904.171, 1746.416, 1875.368 ,1826.619, 1853.982, 1887.834, 1802.647 ,1783.050,1925.268, 1777.375, 1970.239 ,1782.715] plt.plot(dt) plt.plot([0,5],[np.mean(dt[0:6]),np.mean(dt[0:6])],'m--',color='r') plt.plot([7,23],[np.mean(dt[7:]),np.mean(dt[7:])],'m--',color='r') print("Mann-Kendall:",Kendall_change_point_detection(dt)) print("Pettitt:",Pettitt_change_point_detection(dt)) print("Buishand U Test:",Buishand_U_change_point_detection(dt)) print("Standard Normal Homogeneity Test (SNHT):",SNHT_change_point_detection(dt))總結
以上是生活随笔為你收集整理的突变点检测:Pettitt突变点检测(python)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么要进行结构体内存对齐
- 下一篇: JVM-浅堆和深堆的区别?