-
Notifications
You must be signed in to change notification settings - Fork 80
Fix plot_backtest
and plot_backtest_interactive
on one-step forecast
#1260
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Script for plotting: import matplotlib.pyplot as plt
import pandas as pd
from etna.analysis import plot_backtest, plot_backtest_interactive
from etna.datasets import TSDataset
from etna.metrics import MAE
from etna.models import ProphetModel
from etna.pipeline import FoldMask
from etna.pipeline import Pipeline
def main():
df = pd.read_csv("examples/data/example_dataset.csv")
df = TSDataset.to_dataset(df)
ts = TSDataset(df, freq="D")
# plot with horizon=1, n_folds=1
pipeline = Pipeline(model=ProphetModel(), horizon=1)
metrics_df, forecast_df, fold_info_df = pipeline.backtest(ts=ts, metrics=[MAE()], n_folds=1)
plot_backtest(forecast_df=forecast_df, ts=ts, history_len=10)
plt.savefig("plot_horizon_1_folds_1.png")
fig = plot_backtest_interactive(forecast_df=forecast_df, ts=ts, history_len=10)
fig.write_image("plot_int_horizon_1_folds_1.png")
# plot with horizon=1, n_folds=3
pipeline = Pipeline(model=ProphetModel(), horizon=1)
metrics_df, forecast_df, fold_info_df = pipeline.backtest(ts=ts, metrics=[MAE()], n_folds=3)
plot_backtest(forecast_df=forecast_df, ts=ts, history_len=10)
plt.savefig("plot_horizon_1_folds_3.png")
fig = plot_backtest_interactive(forecast_df=forecast_df, ts=ts, history_len=10)
fig.write_image("plot_int_horizon_1_folds_3.png")
# plot with horizon=7, n_folds=3
pipeline = Pipeline(model=ProphetModel(), horizon=7)
metrics_df, forecast_df, fold_info_df = pipeline.backtest(ts=ts, metrics=[MAE()], n_folds=3)
plot_backtest(forecast_df=forecast_df, ts=ts, history_len=10)
plt.savefig("plot_horizon_7_folds_3.png")
fig = plot_backtest_interactive(forecast_df=forecast_df, ts=ts, history_len=10)
fig.write_image("plot_int_horizon_7_folds_3.png")
# fold mask example
pipeline = Pipeline(model=ProphetModel(), horizon=14)
folds = [
FoldMask(
first_train_timestamp=None,
last_train_timestamp=pd.Timestamp("2019-10-19"),
target_timestamps=[pd.Timestamp("2019-10-26"), pd.Timestamp("2019-10-27"), pd.Timestamp("2019-11-01")],
),
FoldMask(
first_train_timestamp=None,
last_train_timestamp=pd.Timestamp("2019-11-02"),
target_timestamps=[pd.Timestamp("2019-11-06"), pd.Timestamp("2019-11-08"), pd.Timestamp("2019-11-10")],
),
FoldMask(
first_train_timestamp=None,
last_train_timestamp=pd.Timestamp("2019-11-16"),
target_timestamps=[pd.Timestamp("2019-11-20"), pd.Timestamp("2019-11-22"), pd.Timestamp("2019-11-24")],
),
]
metrics_df, forecast_df, fold_info_df = pipeline.backtest(ts=ts, metrics=[MAE()], n_folds=folds)
plot_backtest(forecast_df=forecast_df, ts=ts, history_len=50)
plt.savefig("plot_masks.png")
fig = plot_backtest_interactive(forecast_df=forecast_df, ts=ts, history_len=50)
fig.write_image("plot_int_masks.png")
if __name__ == "__main__":
main() |
🚀 Deployed on https://deploy-preview-1260--etna-docs.netlify.app |
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## master #1260 +/- ##
==========================================
- Coverage 87.99% 87.97% -0.03%
==========================================
Files 186 186
Lines 10749 10747 -2
==========================================
- Hits 9459 9455 -4
- Misses 1290 1292 +2
... and 4 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
alex-hse-repository
suggested changes
May 11, 2023
alex-hse-repository
approved these changes
May 12, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting (must do checklist)
Proposed Changes
horizon=1
and 1 fold separatelypd.date_range
Closing issues
Closes #1122.