diff --git a/src/anomalytics/models/peaks_over_threshold.py b/src/anomalytics/models/peaks_over_threshold.py index bd30b1a..a84b8bb 100644 --- a/src/anomalytics/models/peaks_over_threshold.py +++ b/src/anomalytics/models/peaks_over_threshold.py @@ -9,6 +9,7 @@ from anomalytics.evals.kolmogorv_smirnov import ks_1sample from anomalytics.evals.qq_plot import visualize_qq_plot from anomalytics.models.abstract import Detector +from anomalytics.plots.plot import plot_gen_pareto, plot_hist, plot_line from anomalytics.stats.peaks_over_threshold import ( get_anomaly, get_anomaly_score, @@ -192,5 +193,107 @@ def return_dataset( ) return dataset + def plot( + self, + plot_type: typing.Literal["l", "l+eth", "l+ath", "hist", "gpd", "gpd+ov"], + title: str, + xlabel: str, + ylabel: str, + bins: typing.Optional[int] = 50, + plot_width: int = 13, + plot_height: int = 8, + plot_color: str = "black", + th_color: str = "red", + th_type: str = "dashed", + th_line_width: int = 2, + alpha: float = 0.8, + ): + if plot_type == "l": + plot_line( + dataset=self.__dataset, + threshold=None, + title=title, + xlabel=xlabel, + ylabel=ylabel, + is_threshold=False, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + th_color=th_color, + th_type=th_type, + th_line_width=th_line_width, + alpha=alpha, + ) + elif plot_type == "l+ath": + plot_line( + dataset=self.__exceedance, + threshold=self.__anomaly_threshold, + title=title, + xlabel=xlabel, + ylabel=ylabel, + is_threshold=True, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + th_color=th_color, + th_type=th_type, + th_line_width=th_line_width, + alpha=alpha, + ) + elif plot_type == "l+eth": + plot_line( + dataset=self.__dataset, + threshold=self.__exceedance_threshold.values, + title=title, + xlabel=xlabel, + ylabel=ylabel, + is_threshold=True, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + th_color=th_color, + th_type=th_type, + th_line_width=th_line_width, + alpha=alpha, + ) + elif plot_type == "hist": + plot_hist( + dataset=self.__dataset, + title=title, + xlabel=xlabel, + ylabel=ylabel, + bins=bins, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + alpha=alpha, + ) + elif plot_type == "gpd": + plot_gen_pareto( + dataset=self.__exceedance, + title=title, + xlabel=xlabel, + ylabel=ylabel, + bins=bins, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + alpha=alpha, + params=None, + ) + elif plot_type == "gpd+ov": + plot_gen_pareto( + dataset=self.__exceedance, + title=title, + xlabel=xlabel, + ylabel=ylabel, + bins=bins, + plot_width=plot_width, + plot_height=plot_height, + plot_color=plot_color, + alpha=alpha, + params=self.__params, + ) + def __str__(self) -> str: return "POT" diff --git a/src/anomalytics/plots/__init__.py b/src/anomalytics/plots/__init__.py index e69de29..ea06c8b 100644 --- a/src/anomalytics/plots/__init__.py +++ b/src/anomalytics/plots/__init__.py @@ -0,0 +1,3 @@ +__all__ = ["plot_gen_pareto", "plot_hist", "plot_line"] + +from anomalytics.plots.plot import plot_gen_pareto, plot_hist, plot_line diff --git a/src/anomalytics/plots/plot.py b/src/anomalytics/plots/plot.py index 973ef80..d05b844 100644 --- a/src/anomalytics/plots/plot.py +++ b/src/anomalytics/plots/plot.py @@ -8,7 +8,7 @@ def plot_line( dataset: typing.Union[pd.DataFrame, pd.Series], - threshold: typing.Union[pd.DataFrame, pd.Series, float], + threshold: typing.Union[pd.DataFrame, pd.Series, typing.List[typing.Union[float, int]], int, float, None], title: str, xlabel: str, ylabel: str, @@ -39,7 +39,7 @@ def plot_hist( title: str, xlabel: str, ylabel: str, - bins: int = 50, + bins: typing.Optional[int] = 50, plot_width: int = 13, plot_height: int = 8, plot_color: str = "black", @@ -60,7 +60,7 @@ def plot_gen_pareto( title: str, xlabel: str, ylabel: str, - bins: int = 50, + bins: typing.Optional[int] = 50, plot_width: int = 13, plot_height: int = 8, plot_color: str = "black",