Skip to content
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

Fix analysis.forecast.plots.metric_per_segment_distribution_plot to handle None from metrics #543

Merged
merged 4 commits into from
Dec 24, 2024

Conversation

d-a-bunin
Copy link
Collaborator

@d-a-bunin d-a-bunin commented Dec 24, 2024

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?

Proposed Changes

See #533.

Closing issues

Closes #533.

@d-a-bunin d-a-bunin self-assigned this Dec 24, 2024
Copy link

github-actions bot commented Dec 24, 2024

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

@github-actions github-actions bot temporarily deployed to pull request December 24, 2024 06:56 Inactive
@d-a-bunin
Copy link
Collaborator Author

Example of plotting:

import pandas as pd
import matplotlib.pyplot as plt
from loguru import logger

from etna.analysis import metric_per_segment_distribution_plot


def get_metrics_df_with_folds() -> pd.DataFrame:
    df = pd.DataFrame(
        {
            "segment": ["segment_0"] * 3 + ["segment_1"] * 3 + ["segment_2"] * 3,
            "MAE": [1.0, 2.0, 3.0, 2.0, 3.0, 4.0, 3.0, 4.0, 5.0],
            "MSE": [None, 3.0, 4.0, 3.0, 4.0, 5.0, 5.0, 6.0, 7.0],
            "MAPE": [None, None, None, 20.0, 30.0, 40.0, 30.0, 40.0, 50.0],
            "SMAPE": [None, 20.0, 30.0, None, 50.0, 60.0, None, 70.0, 80.0],
            "RMSE": [None, None, None, None, None, None, None, None, None],
            "fold_number": [0, 1, 2, 0, 1, 2, 0, 1, 2],
        }
    )
    return df


def main():
    metrics_df = get_metrics_df_with_folds()

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="MAPE", per_fold_aggregation_mode=None, plot_type="hist")
    plt.savefig("mape_none_hist.png", bbox_inches="tight")

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="SMAPE", per_fold_aggregation_mode=None, plot_type="hist")
    plt.savefig("smape_none_hist.png", bbox_inches="tight")

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="SMAPE", per_fold_aggregation_mode="mean", plot_type="hist")
    plt.savefig("smape_mean_hist.png", bbox_inches="tight")

    try:
        metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="RMSE", per_fold_aggregation_mode=None, plot_type="hist")
        plt.savefig("rmse_none_hist.png", bbox_inches="tight")
    except ValueError:
        logger.info("No success with RMSE!")


if __name__ == "__main__":
    main()

mape_none_hist:
mape_none_hist

smape_none_hist
smape_none_hist

smape_mean_hist:
smape_mean_hist

@github-actions github-actions bot temporarily deployed to pull request December 24, 2024 07:06 Inactive
@d-a-bunin d-a-bunin requested a review from brsnw250 December 24, 2024 07:37
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.52%. Comparing base (7b37537) to head (bd87574).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #543      +/-   ##
==========================================
+ Coverage   90.48%   90.52%   +0.03%     
==========================================
  Files         256      256              
  Lines       17373    17375       +2     
==========================================
+ Hits        15720    15728       +8     
+ Misses       1653     1647       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@d-a-bunin
Copy link
Collaborator Author

Example without intersection:

import pandas as pd
import matplotlib.pyplot as plt
from loguru import logger

from etna.analysis import metric_per_segment_distribution_plot


def get_metrics_df_with_folds() -> pd.DataFrame:
    df = pd.DataFrame(
        {
            "segment": ["segment_0"] * 3 + ["segment_1"] * 3 + ["segment_2"] * 3,
            "MAE": [1.0, 2.0, 3.0, 2.0, 3.0, 4.0, 3.0, 4.0, 5.0],
            "MSE": [None, 3.0, 4.0, 3.0, 4.0, 5.0, 5.0, 6.0, 7.0],
            "MAPE": [None, None, None, 20.0, 50.0, 90.0, 30.0, 60.0, 100.0],
            "SMAPE": [None, 20.0, 60.0, None, 30.0, 70.0, None, 40.0, 80.0],
            "RMSE": [None, None, None, None, None, None, None, None, None],
            "fold_number": [0, 1, 2, 0, 1, 2, 0, 1, 2],
        }
    )
    return df


def main():
    metrics_df = get_metrics_df_with_folds()

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="MAPE", per_fold_aggregation_mode=None, plot_type="hist")
    plt.savefig("mape_none_hist.png", bbox_inches="tight")

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="SMAPE", per_fold_aggregation_mode=None, plot_type="hist")
    plt.savefig("smape_none_hist.png", bbox_inches="tight")

    metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="SMAPE", per_fold_aggregation_mode="mean", plot_type="hist")
    plt.savefig("smape_mean_hist.png", bbox_inches="tight")

    try:
        metric_per_segment_distribution_plot(metrics_df=metrics_df, metric_name="RMSE", per_fold_aggregation_mode=None, plot_type="hist")
        plt.savefig("rmse_none_hist.png", bbox_inches="tight")
    except ValueError:
        logger.info("No success with RMSE!")


if __name__ == "__main__":
    main()

mape_none_hist
mape_none_hist

smape_none_hist
smape_none_hist

smape_mean_hist
smape_mean_hist

@d-a-bunin d-a-bunin merged commit e73d138 into master Dec 24, 2024
17 checks passed
@d-a-bunin d-a-bunin deleted the issue-533 branch December 24, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix analysis.forecast.plots.metric_per_segment_distribution_plot to handle None from metrics
2 participants