Even if you don't have any knowledge about Facebook's time series prediction library Prophet and time series prediction, it is wonderful to be able to plot day of the week fluctuations, overall trend trends, etc. Regarding the plot, I just wrote in the official manual that "I can visualize it more interactively using plotly", but after playing around with it, I got the following points.
I hope it helps someone, and I will share the solution of the addiction point.
macOS 10.15 Python 3.7.6 Prophet 0.6 Plotly 4.6.0
It has been uploaded below. https://github.com/nekodango/prophet_plotly_sample
As per the Official Tutorial, here /examples/example_wp_log_peyton_manning.csv) Download and load "example_wp_log_peyton_manning.csv" from.
import pandas as pd
from fbprophet import Prophet
df = pd.read_csv('example_wp_log_peyton_manning.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
The following code will display a normal plot.
fig = m.plot(forecast)
In this state
from fbprophet.plot import plot_plotly, plot_components_plotly
import plotly.offline as py
py.init_notebook_mode()
after
fig = plot_plotly(m, forecast)
py.iplot(fig)
Then, the plot using Plotly is displayed.
Similarly, plot_components
fig = m.plot_components(forecast)
To
fig = plot_components_plotly(m, forecast)
py.iplot(fig)
If you rewrite it to, the display using Plotly will appear.
When I'm muzzling the plot, I'm wondering if such a useful thing is really free. Prophet terrifying.
Must be specified with the trend
and changepoints
options when calling plot_plotly
.
plot_plotly(m, forecast, trend=True, changepoints=True)
I referred to the post on stackoverflow. https://stackoverflow.com/a/57903750
Import plotly.io
and set renderers.default
to colab
.
from fbprophet.plot import plot_plotly, plot_components_plotly
import plotly.io as pio
pio.renderers.default = "colab"
So, when drawing, fig.show ()
.
fig = plot_plotly(m, forecast)
fig.show()
We have uploaded a notebook below so that you can try it out on Colab right away. https://github.com/nekodango/prophet_plotly_sample/blob/master/prophet_plotly_colab.ipynb
If you want to give your Plotly plot a title, you can:
fig.update_layout(title="plpt_plotly")
I tried it later and was surprised, but even if I set Japanese as the title, it was displayed normally without any garbled characters. Prophet terrifying. (I said it twice because it's important)
It is convenient to be able to easily muzzle time series data on Colab. Please do try that out.
Recommended Posts