The following code is analyzed under jupyter, the process
import pandas as pd
from prophet import Prophet
Read data using pandas
df = pd.read_csv('./examples/example_wp_log_peyton_manning.csv')
Create a Prophet() object
m = Prophet()
Initialize the data, the fit method builds a model through the given data
m.fit(df)
Specify the prediction range
future = m.make_future_dataframe(periods=365)
Execute forecast
forecast = m.predict(future)
Display the forecast results for the original data
fig1 = m.plot(forecast)
Because the x coordinates, that is, the ds column, are in datetime format, this function is divided according to time
Trend, holiday, week, season time periods for analysis
fig2 = m.plot_components(forecast)
display data
View all column data
in jupyter
forecast
forecast = Prophet object.fit(df).predict(future)
display
fig = Prophet object.plot_components(forecast)
View data changes throughout the year
from prophet.plot import plot_yearly
m = Prophet().fit(df)
a = plot_yearly(m)
def plot_yearly(m, ax=None, uncertainty=True,
yearly_start=0, figsize=(10, 6), name=‘yearly’):
Plot the annual components of the forecast.
参数
----------
m:先知模型。
ax:要绘制的可选 matplotlib 轴。 一个将被创建,如果
这不提供。
不确定性:可选布尔值来绘制不确定性区间,这将
仅在 m.uncertainty_samples > 0 时执行。
yearly_start: 可选 int 指定每年的开始日期
季节性图。 0(默认)从 1 月 1 日开始这一年。1 次轮班
从 1 天到 1 月 2 日,依此类推。
figsize: 可选的元组宽度,以英寸为单位的高度。
name:季节性组件的名称(如果之前从默认的“每年”更改)。
-------
Simply look at the data, showing the uncertainty interval
df = pd.read_csv('.../examples/example_wp_log_R_outliers1.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=1096)
forecast = m.predict (future)
fig = m.plot(forecast)