antoinecarme / pyaf

PyAF is an Open Source Python library for Automatic Time Series Forecasting built on top of popular pydata modules.
BSD 3-Clause "New" or "Revised" License
458 stars 73 forks source link

Analyze Business Seasonals (HourOfWeek and derivatives) #131

Closed antoinecarme closed 4 years ago

antoinecarme commented 4 years ago

For business hourly data the signal may be better analyzed by crossing dayOfWeek and Hour.

This can be made by dividing the work week in hours and analyzing HourOfWeek.

HourOfWeek = dayOfWeek * 24 + Hour

Some patterns like week-end, night, sunrise, AM , PM, Monday morning, lunch time etc can be captured this way and improve the explainability of the model.

antoinecarme commented 4 years ago

A usual pattern like 'morning' is not really well defined. Besides the original HourOfWeek seasonal , we will define increasing discrete patterns covering every two hours, every three hours, etc.

The 'morning' pattern can be approximated by something like the first six or eight hours of every day according to the business.

antoinecarme commented 4 years ago
class eDatePart(IntEnum):
    Second = 1
    Minute = 2
    Hour = 3
    DayOfWeek = 4
    DayOfMonth = 5
    MonthOfYear = 6
    WeekOfYear = 7
    DayOfYear = 8
    HourOfWeek = 9
    TwoHourOfWeek = 10
    ThreeHourOfWeek = 11
    FourHourOfWeek = 12
    SixHourOfWeek = 13
    EightHourOfWeek = 14
    TwelveHourOfWeek = 15
antoinecarme commented 4 years ago
TwoHourOfWeek =  dayOfWeek * 12 + Hour // 2
ThreeHourOfWeek =  dayOfWeek * 8 + Hour // 3
FourHourOfWeek =  dayOfWeek * 6 + Hour // 4
SixHourOfWeek =  dayOfWeek * 4 + Hour // 6
EightHourOfWeek =  dayOfWeek * 3 + Hour // 8
TwelveHourOfWeek =  dayOfWeek * 2 + Hour // 12

with

0 <= dayOfWeek <= 6 #  0 means Monday, 6 means Sunday
0 <= Hour <= 23
antoinecarme commented 4 years ago

Closing