Skip to content

Add metric_per_segment_distribution_plot #666

Merged
merged 6 commits into from Apr 29, 2022
Merged

Add metric_per_segment_distribution_plot #666

merged 6 commits into from Apr 29, 2022

Conversation

Mr-Geekman
Copy link
Contributor

@Mr-Geekman Mr-Geekman commented Apr 29, 2022

IMPORTANT: Please do not create a Pull Request without creating an issue first.

Before submitting (must do checklist)

  • Did you read the contribution guide?
  • Did you update the docs? We use Numpy format for all the methods and classes.
  • Did you write any new necessary tests?
  • Did you update the CHANGELOG?

Type of Change

  • Examples / docs / tutorials / contributors update
  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves an existing feature)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Proposed Changes

Look #654.

Related Issue

#654.

Closing issues

Closes #654.

@Mr-Geekman Mr-Geekman added the enhancement New feature or request label Apr 29, 2022
@Mr-Geekman Mr-Geekman self-assigned this Apr 29, 2022
@Mr-Geekman
Copy link
Contributor Author

Example script:

import matplotlib.pyplot as plt
import pandas as pd

from etna.analysis import metric_per_segment_distribution_plot
from etna.datasets import TSDataset
from etna.metrics import MAE
from etna.metrics import SMAPE
from etna.models import ProphetModel
from etna.pipeline import Pipeline


def main():
    df = pd.read_csv("examples/data/example_dataset.csv", parse_dates=["timestamp"])
    df_wide = TSDataset.to_dataset(df)
    ts = TSDataset(df=df_wide, freq="D")

    pipeline = Pipeline(model=ProphetModel(), horizon=10)
    metrics_df, _, _ = pipeline.backtest(ts=ts, n_folds=3, metrics=[MAE(), SMAPE()])

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df,
        metric_name="MAE",
        plot_type="hist",
        per_fold_aggregation_mode=None,
        seaborn_params=dict(multiple="stack"),
    )
    plt.savefig("plot_hist_no_agg")

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="box", per_fold_aggregation_mode=None
    )
    plt.savefig("plot_box_no_agg")

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="violin", per_fold_aggregation_mode=None
    )
    plt.savefig("plot_violin_no_agg")

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="hist", per_fold_aggregation_mode="mean"
    )
    plt.savefig("plot_hist_mean")

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="box", per_fold_aggregation_mode="mean"
    )
    plt.savefig("plot_box_mean")

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="violin", per_fold_aggregation_mode="mean"
    )
    plt.savefig("plot_violin_mean")

    # case of already aggregated metrics
    pipeline = Pipeline(model=ProphetModel(), horizon=10)
    metrics_df, _, _ = pipeline.backtest(ts=ts, n_folds=3, metrics=[MAE(), SMAPE()], aggregate_metrics=True)

    metric_per_segment_distribution_plot(
        metrics_df=metrics_df, metric_name="MAE", plot_type="hist", per_fold_aggregation_mode=None
    )
    plt.savefig("plot_hist_is_agg")


if __name__ == "__main__":
    main()

plot_hist_no_agg:
plot_hist_no_agg

plot_box_no_agg:
plot_box_no_agg

plot_violin_no_agg:
plot_violin_no_agg

plot_hist_mean:
plot_hist_mean

plot_box_mean:
plot_box_mean

plot_violin_mean:
plot_violin_mean

plot_hist_is_agg:
plot_hist_is_agg

@github-actions
Copy link

github-actions bot commented Apr 29, 2022

🚀 Deployed on https://deploy-preview-666--etna-docs.netlify.app

@github-actions github-actions bot temporarily deployed to pull request April 29, 2022 09:02 Inactive
@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2022

Codecov Report

Merging #666 (8a6de85) into master (c05a44a) will decrease coverage by 0.38%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##           master     #666      +/-   ##
==========================================
- Coverage   84.45%   84.06%   -0.39%     
==========================================
  Files         119      119              
  Lines        6322     6370      +48     
==========================================
+ Hits         5339     5355      +16     
- Misses        983     1015      +32     
Impacted Files Coverage Δ
etna/analysis/plotters.py 21.92% <31.91%> (+0.97%) ⬆️
etna/analysis/__init__.py 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

iKintosh
iKintosh previously approved these changes Apr 29, 2022
Copy link
Contributor

@iKintosh iKintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

d.a.bunin added 2 commits April 29, 2022 13:32
@github-actions github-actions bot temporarily deployed to pull request April 29, 2022 10:42 Inactive
@Mr-Geekman Mr-Geekman merged commit d0ed655 into master Apr 29, 2022
@Mr-Geekman Mr-Geekman deleted the issue-654 branch April 29, 2022 11:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics per-segment Distribution Plot
3 participants