prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Weekly plot

Open beloteloff opened this issue 9 years ago • 5 comments

Hi! I saw,that days don't match in weekly plots with real days of the week, in source code I didn't saw the reference to the calendar. What day is the first in weekly decomposition plot?

beloteloff avatar Apr 04 '17 10:04 beloteloff

This is a bug, fixed in #28. Can you install the latest version from Github and check if it is working for you?

bletham avatar Apr 04 '17 23:04 bletham

oh,no. I'm just trying to understand how exactly determines the day of the week in the weekly chart. As I correctly understand,fbrophet automatically defines which day of the week is the first in my data. For example, if my 1st value in time series by ds field is '2017-04-05' wednesday, what days it will be in weekly plot? I have the same views in each weekly plot: ferer May be my question is begotten, because I don't fully understand def plot_weekly(self, fcst, ax=None, uncertainty=True): """Plot the weekly component of the forecast. Parameters ---------- fcst: pd.DataFrame output of self.predict. ax: Optional matplotlib Axes to plot on. One will be created if this is not provided. uncertainty: Optional boolean to plot uncertainty intervals. Returns ------- a list of matplotlib artists """ artists = [] if not ax: fig = plt.figure(facecolor='w', figsize=(10, 6)) ax = fig.add_subplot(111) df_s = fcst.copy() df_s['dow'] = df_s['ds'].dt.weekday_name df_s = df_s.groupby('dow').first() days = pd.date_range(start='2017-01-01', periods=7).weekday_name y_weekly = [df_s.loc[d]['weekly'] for d in days] y_weekly_l = [df_s.loc[d]['weekly_lower'] for d in days] y_weekly_u = [df_s.loc[d]['weekly_upper'] for d in days] artists += ax.plot(range(len(days)), y_weekly, ls='-', c='#0072B2') if uncertainty: artists += [ax.fill_between(range(len(days)), y_weekly_l, y_weekly_u, color='#0072B2', alpha=0.2)] ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) ax.set_xticks(range(len(days))) in source code

Or, I can't understand correctly, how you can do weekly plot, if I have only 1st values for each month. In this case, weekly plots is a good choice for time series analysis?

Thanks for your job!

beloteloff avatar Apr 05 '17 07:04 beloteloff

The weekly plot always starts on Sunday.

Except there is a bug in the version on pip which is affecting your plot so that the axes are shifted by one - You can see that there is a tick at the end with no label. That one should be Saturday, and all of the other ticks should be shifted one to the right, and then the first tick is Sunday. This is a bug only in the plot labels, everything else is correct.

I'd really recommend installing the latest version from Github to fix this. Download the code, and then in the python directory run sudo python setup.py install. We're planning to push a bugfix update to pip once we squash out a couple more issues.

#119 is to be able to customize the starting day of the weekly seasonality plot rather than being fixed at Sunday, so that will happen in a future version.

bletham avatar Apr 05 '17 17:04 bletham

ok, last question about weekly plots, I hope: why values can be negative? what it mean? Log from value?Thanks!

beloteloff avatar Apr 06 '17 07:04 beloteloff

It's an additive model, so the value in the weekly seasonality plot is the difference in the value on that day. So, -0.2 on Monday means that on Tuesdays we subtract 0.2 from the time series, whereas on Sunday we add 0.1.

bletham avatar Apr 07 '17 03:04 bletham