Skip to content

Add seasonal plot #548

Closed
1 task
iKintosh opened this issue Feb 18, 2022 · 0 comments · Fixed by #628
Closed
1 task

Add seasonal plot #548

iKintosh opened this issue Feb 18, 2022 · 0 comments · Fixed by #628
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@iKintosh
Copy link
Contributor

iKintosh commented Feb 18, 2022

🚀 Feature Request

seasonplot1-1
Add plot function that allows to create plots similar to the above one.

Motivation

Seasonal plot allows to analyse and extract useful info from time series.

Proposal

def seasonal_plot(
    ts: "TSDataset",
    freq: Optional[str] = None
    cycle: Union[Literal["hour"], Literal["day"], Literal["week"], Literal["month"], Literal["quarter"], Literal["year"], int] = "yearly",
    align: Union[Literal["first"], Literal["last"]] = "last"
    aggregation: Union[Literal["sum'], Literal["mean"] = sum,
    in_column: str = "target",
    segments: Optional[List[str]] = None,
    columns_num: int = 2,
    figsize: Tuple[int, int] = (10, 5),
    **plot_kwargs
):

Where:

ts - the data
freq - if not None then resample data to it.
cycle - is a period of X axis
align - used only when cycle is int. Defines if last or first period should be full. 
aggregation - how to aggregate data when resampling
target - defines what column to plot
segments - allows to specify segments to plot, if None plot all the segments
columns_num - number of graphics columns
figsize - size of the figure per subplot with one segment in inches
**plot_kwargs - additional arguments that will be passed to inner plotting function

Notes on cycle and freq:
if cycle == int and freq == None then consider freq current and just split the data by chunks of cycle size. Use align parameter to fill first or last period.

if cycle == int and freq != None then resample data using freq and split the data by chunks of cycle size. Use align parameter to fill first or last period.

if cycle == Literal and freq == None then consider freq current and split the data using information about time:

hour - starts at 00 minutes ends at 59 minutes
day - starts at 00:00, ends at 23:59
week starts at Monday 00:00 ends at Sunday 23:59
and so on

Also consider adding custom X axis such as Weekdays[Mon, Tue, Wed, etc], Months[Jan, Feb, Mar, Apr, etc] and check if data allows using it.

if cycle == Literal and freq != None then resample first using freq and split the data using information about time just as in the above case.

Example

If data has freq = "D" then to plot weekly seasonality we need to call
seasonal_plot(ts, cycle="week")
it should plot a graph that will start at Monday and end on Sunday.

Note that seasonal_plot(ts, cycle=7) may not start Monday because time series can start and end at any weekday possible.

If data has freq = "D" then to plot yearly seasonality as above example we need to call:
seasonal_plot(ts, freq="M", cycle="year")

Test cases

Should test, that split by season works correctly

Alternatives

No response

Additional context

Examples:

Checklist

  • I discussed this issue with ETNA Team
@iKintosh iKintosh added the enhancement New feature or request label Feb 18, 2022
@alex-hse-repository alex-hse-repository added this to the EDA milestone Feb 18, 2022
@Mr-Geekman Mr-Geekman self-assigned this Mar 25, 2022
@Mr-Geekman Mr-Geekman mentioned this issue Mar 29, 2022
9 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants