2021年7月4日追記
Google Colabを利用してProphetを利用するエントリーを書いたので、今試される方はこちらのやり方のほうがよいかもしれないです。
同僚が試していたので自分も少しさわってみることにした。
Prophetはfacebookが公開している過去の時系列のデータから長期的なトレンドと周期成分、突発的な成分を踏まえて以後の動向予測ができるツールで、自分が試してみようと思ったのは現在単純に線形予測だったり回帰予測でおこなっているところの置き換えができたりするのかなというところがモチベーション。
pyenvでPythonとpipをインストールする
以下のエントリのmatplotlibの手前までを実施してPythonをインストールした。
Prophetの素振り
以下のエントリに倣って試してみる。
qiita.com
m.plot(forecast)
で以下のエラーが出てくる。
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
これを解決するには先のエントリにある通り、 ~/.matplotlib/matplotlibrc
を新規に作成して設置する。
backend : TkAgg
こうすると上のエントリで書かれている様なProphetを試す一連の流れを再現できる。
import pandas as pd import numpy as np from fbprophet import Prophet df = pd.read_csv('example_wp_peyton_manning.csv') df['y'] = np.log(df['y']) m = Prophet() m.fit(df) future = m.make_future_dataframe(periods=365) forecast = m.predict(future) m.plot(forecast).show()
ちなみにCSVに落としたかったら forecast.to_csv("file.csv")
といった具合。
実際に手元にあった時系列のデータを読み込ませてみた所かなりカジュアルに周期成分と長期トレンドを予測することができて最初の印象としてはとてもよさそうなのでもう少しいろいろ扱ってみたい。