How can I use numerical values instead of yhat values in a plot?
Hello fellow prophets I have a stock data which contains the following price data..
`ds,y 03/23/2016,742 03/28/2016,755 03/29/2016,742 03/30/2016,734.5
03/31/2016,750`
I know that forecast1[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail() produces the predicted values that are used when you do a plot. However, is there a way to use predicted numerical values when plotting?
If I do this..
np.exp(forecast[['yhat','yhat_lower','yhat_upper']].tail())
I get the predicted numerical values instead of yhat values..how can I use that when I do a plot?
Thanks in advance.
I have absolutely no idea of what the values in the forecast mean... Even with np.exp() the values are not correct : they are in a good scale, but for real input data, the result of np.exp() is quite different.
You were so near to answer to my question in #139
For what causes you don't like np.exp()? np.log it is reverse operation for it.
Well, as input data, I have for example August 2016 : 2176 In the forecast I can find august 2016 : 7.715123 So I have a data for august 2016 : 2241 ... So the forecasted data for a past data is different than the original data... how can I presume the forecasted data in the future ?
@arvindacumos if I understand correctly you have log-transformed your data, fit with Prophet, and now want to plot the forecast in the real (exponentiated) space. There unfortunately isn't any way to do this automatically. Built-in support for log-transforms is on the roadmap for the next version.
In the meantime, the code for plotting is pretty simple
https://github.com/facebookincubator/prophet/blob/b999dd4aa4ff91b2f6501979c192743a7fc5e9b9/python/fbprophet/forecaster.py#L848-L876
If you replace self with m and put exp around things then it should work!
@bletham is this correct?
` def plot(m, fcst, uncertainty=True, xlabel='ds', ylabel='y'):
ax.plot(np.exp(m.history['ds'].values), np.exp(m.history['y']), 'k.') `
Please confirm
Just exponents around the y's. Something like this:
def plot(m, fcst, uncertainty=True, xlabel='ds', ylabel='y'):
fig = plt.figure(facecolor='w', figsize=(10, 6))
ax = fig.add_subplot(111)
ax.plot(m.history['ds'].values, np.exp(m.history['y']), 'k.')
ax.plot(fcst['ds'].values, np.exp(fcst['yhat']), ls='-', c='#0072B2')
if 'cap' in fcst:
ax.plot(fcst['ds'].values, np.exp(fcst['cap']), ls='--', c='k')
if uncertainty:
ax.fill_between(fcst['ds'].values, np.exp(fcst['yhat_lower']),
np.exp(fcst['yhat_upper']), color='#0072B2',
alpha=0.2)
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
fig.tight_layout()
return fig
@bletham thanks allot will try that one out.
@bletham that worked thanks allot!!! am closing the issue