-
Notifications
You must be signed in to change notification settings - Fork 17
[ML-42739] Add custom forecasting data splits for automl_runtime #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
8dbc9aa
f1a8eb2
58b5bd0
b51dd4a
7c5f972
c970429
18adfb5
082ae81
e371457
86b4a96
ff04448
ec0a675
e2f998c
65510c4
874fc2f
9b4aee0
8d8008c
41266f8
275980b
a32492f
4aaee3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,33 @@ def generate_cutoffs(df: pd.DataFrame, horizon: int, unit: str, | |
) | ||
return list(reversed(result)) | ||
|
||
def generate_custom_cutoffs(df: pd.DataFrame, horizon: int, unit: str, | ||
split_cutoff: pd.Timestamp) -> List[pd.Timestamp]: | ||
""" | ||
Generate custom cutoff times for cross validation based on user-specified split cutoff. | ||
Period (step size) is 1. | ||
Lanz-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:param df: pd.DataFrame of the historical data. | ||
:param horizon: int number of time into the future for forecasting. | ||
:param unit: frequency unit of the time series, which must be a pandas offset alias. | ||
:param split_cutoff: the user-specified cutoff, as the starting point of cutoffs | ||
Lanz-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:return: list of pd.Timestamp cutoffs for cross-validation. | ||
""" | ||
period = 1 | ||
period_dateoffset = pd.DateOffset(**DATE_OFFSET_KEYWORD_MAP[unit])*period | ||
horizon_dateoffset = pd.DateOffset(**DATE_OFFSET_KEYWORD_MAP[unit])*horizon | ||
|
||
cutoff = split_cutoff | ||
result = [cutoff] | ||
while result[-1] <= max(df["ds"]) - horizon_dateoffset: | ||
Lanz-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cutoff += period_dateoffset | ||
if not (((df["ds"] > cutoff) & (df["ds"] <= cutoff + horizon_dateoffset)).any()): | ||
if cutoff < df["ds"].max(): | ||
Lanz-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
closest_date = df[df["ds"] > cutoff].min()["ds"] | ||
cutoff = closest_date - horizon_dateoffset | ||
result.append(cutoff) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add comments like those in L173-182? Would be very helpful for review and when we look back in the future. E.g. is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also i'm not completely sure whether simply reverting -= to += is just correct. I'll take a deeper look later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments added. |
||
result = result[:-1] | ||
return result | ||
|
||
def is_quaterly_alias(freq: str): | ||
return freq in QUATERLY_OFFSET_ALIAS | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.