Skip to content

Commit

Permalink
feat(potdetector_plot): implement plotting for diosplaying datasets d…
Browse files Browse the repository at this point in the history
…istributions
ninopleno committed Dec 4, 2023
1 parent fae30f2 commit 40159c7
Showing 3 changed files with 109 additions and 3 deletions.
103 changes: 103 additions & 0 deletions src/anomalytics/models/peaks_over_threshold.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions src/anomalytics/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__all__ = ["plot_gen_pareto", "plot_hist", "plot_line"]

from anomalytics.plots.plot import plot_gen_pareto, plot_hist, plot_line
6 changes: 3 additions & 3 deletions src/anomalytics/plots/plot.py
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 40159c7

Please sign in to comment.