Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pythonで解く計量時系列分析1

 Pythonで解く計量時系列分析1

Pythonで解く計量時系列分析1
みんなのpython勉強会#48
https://startpython.connpass.com
Github:https://github.com/betashort/Time_Series_Analysis

betashort

August 08, 2019
Tweet

More Decks by betashort

Other Decks in Technology

Transcript

  1. Pythonあるある ifrom statsmodels.stats.diagnostic import acorr_ljungbox ・・・ ImportError: cannot import name

    'datetools' • ライブラリのバージョン違い Pandasの旧バージョンに対応? statsmodelsをアップデート? statsmodelsは使わない!!
  2. ⾃⼰相関のグラフ 期待値 def time_mean(t_data): return np.mean(t_data) ⾃⼰共分散 def time_acv(t_data, k):

    T = len(t_data) t = k + 1 n = T - t mu = time_mean(t_data[1:]) gamma = np.sum((t_data[t:] - mu) * (t_data[1:n+1] - mu)) / T return gamma
  3. ⾃⼰相関の検定 def portmanteau_test(t_data, m): T = len(t_data) tmp = 0

    Q = T*(T+2) for i in range(m): k = i+1 rho_k = time_acr(t_data, k) tmp += rho_k ** 2 / (T - k) Q = Q * tmp alpha = chi2.ppf(0.95, m) p = chi2.pdf(Q, m) if Q > alpha: print("lag:", m, "データは有意な⾃⼰相関を持つ") return rho_k, Q, p カイ2乗分布に従う