RのサンプルデータAir Passenger を用い、自己相関(AFC)と偏自己相関(PAFC)のコレログラムを描画しようと思っていますが、自己相関は描画されますが、偏自己相関が描画されません。
環境:Python3.x,Jupyternotebook
Python3
1# ライブラリの読み込み 2import pandas as pd 3import numpy as np 4import matplotlib.pyplot as plt 5%matplotlib inline 6import statsmodels.api as sm 7 8# データ(csv)の読み込みと確認 9df = pd.read_csv('AirPassengers.csv') 10pd.read_csv("AirPassengers.csv") 11 12# データ整形 13# pd.Series()を使って、データはDataFrameに取り込んだ乗客数(#Passengers)を指定して、dtypeにfloatに設定 14passengers = pd.Series(df['#Passengers'], 15 dtype='float' 16 ) 17 18# インデックスに日付を設定 19passengers.index = pd.to_datetime(df['Month']) 20 21#データ格納の可否を確認 22print(passengers.index.dtype) 23print(len(passengers)) 24passengers.head() 25 26# 自己相関(ACF)のグラフ(コレログラム)自動作成 27fig = plt.figure(figsize=(12,4)) 28ax1 = fig.add_subplot(111) 29 30# 飛行乗客数データ、ラグ40、 31sm.graphics.tsa.plot_acf(passengers, 32 lags=40, 33 ax=ax1 34 ) 35 36plt.show() 37 38# 自己相関(ACF)と偏自己相関(PACF)のグラフを縦に並べ比較 39# 自己相関(ACF)のグラフ 40ax1 = fig.add_subplot(211) 41sm.graphics.tsa.plot_acf(passengers, 42 lags=40, 43 ax=ax1 44 ) 45plt.show() 46 47# 偏自己相関(PACF)のグラフ 48ax2 = fig.add_subplot(212) 49sm.graphics.tsa.plot_pacf(passengers, 50 lags=40, 51 ax=ax2 52 ) 53 54 55plt.tight_layout() 56
偏自己相関のコレログラムが描かれず、以下のメッセージが出ます。
(自己相関のコレログラムは描かれます)
C:\Users\User name\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1283: RuntimeWarning: invalid value encountered in sqrt
return rho, np.sqrt(sigmasq)
教えて下さると助かります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/21 01:13
2019/01/21 04:40
2019/01/21 06:39