前提・実現したいこと
#プログラム初心者です#
Python3で変化点検出を実現したいです。
用いたライブラリは「ChangeFinder」です。
温度データから一次階差をとったもの(y_diff)を取得して、それに対してChangeFinderを適応したものをグラフで出力したいです。
ご回答・ご助言よろしくお願いいたします。
発生している問題・エラーメッセージ
グラフが出力されず、エラーメッセージが表示されてしまいます。
ValueError: view limit minimum -36868.78052083334 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
該当のソースコード
Python3
1import pylab 2from statsmodels.tsa.ar_model import AR 3import numpy as np 4import pandas as pd 5import matplotlib.pyplot as plt 6from statsmodels.tsa import stattools 7from statsmodels.tsa import ar_model 8from statsmodels.graphics import tsaplots 9import changefinder as cf 10 11#温度生データ 12df_templeture = pd.read_csv('templeture_data_.csv') 13y = pd.Series(df_templeture.templeture.values, index=pd.date_range(start='2019-11-11 22:00:00', periods=len(df_templeture),freq='min')) 14 15#一次階差をとる 16y_diff = y.diff() 17 18#変化点検出 19# r:忘却パラメタ 20# order:ARモデルの次数 21# smooth:スコアの平滑化のウィンドウ幅 22cf = changefinder.ChangeFinder(r=0.01, order=1, smooth=7) 23 24result = np.empty(len(y_diff)) 25for i, d in enumerate(y_diff): 26 # スコア 27 result[i] = cf.update(d) 28fig = plt.figure() 29ax = fig.add_subplot(111) 30ax.plot(result, label="score") 31ax2 = ax.twinx() 32ax2.plot(y_diff, alpha=0.3, label="observation")
補足情報(FW/ツールのバージョンなど)
numpy 1.17.3
pandas 0.25.2
matplotlib 3.1.1
あなたの回答
tips
プレビュー