Skip to content

Add in_column to plot_anomalies, plot_anomalies_interactive #618

Merged
merged 3 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
-
-
-
- Add in_column to plot_anomalies, plot_anomalies_interactive ([#618](https://github.com/tinkoff-ai/etna/pull/618))
-

### Fixed
Expand Down
14 changes: 10 additions & 4 deletions etna/analysis/plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def plot_backtest_interactive(

def plot_anomalies(
ts: "TSDataset",
anomaly_dict: Dict[str, List[np.datetime64]],
anomaly_dict: Dict[str, List[pd.Timestamp]],
in_column: str = "target",
segments: Optional[List[str]] = None,
columns_num: int = 2,
figsize: Tuple[int, int] = (10, 5),
Expand All @@ -455,6 +456,8 @@ def plot_anomalies(
TSDataset of timeseries that was used for detect anomalies
anomaly_dict:
dictionary derived from anomaly detection function
in_column:
column to plot
segments:
segments to plot
columns_num:
Expand All @@ -472,10 +475,10 @@ def plot_anomalies(
anomaly = anomaly_dict[segment]

ax[i].set_title(segment)
ax[i].plot(segment_df.index.values, segment_df["target"].values, c="b")
ax[i].plot(segment_df.index.values, segment_df[in_column].values, c="b")

anomaly = sorted(anomaly) # type: ignore
ax[i].scatter(anomaly, segment_df[segment_df.index.isin(anomaly)]["target"].values, c="r")
ax[i].scatter(anomaly, segment_df[segment_df.index.isin(anomaly)][in_column].values, c="r")

ax[i].tick_params("x", rotation=45)

Expand Down Expand Up @@ -553,6 +556,7 @@ def plot_anomalies_interactive(
segment: str,
method: Callable[..., Dict[str, List[pd.Timestamp]]],
params_bounds: Dict[str, Tuple[Union[int, float], Union[int, float], Union[int, float]]],
in_column: str = "target",
figsize: Tuple[int, int] = (20, 10),
):
"""Plot a time series with indicated anomalies.
Expand All @@ -569,6 +573,8 @@ def plot_anomalies_interactive(
Method for outliers detection
params_bounds:
Parameters ranges of the outliers detection method. Bounds for the parameter are (min,max,step)
in_column:
column to plot
figsize:
size of the figure in inches

Expand All @@ -594,7 +600,7 @@ def plot_anomalies_interactive(

from etna.datasets import TSDataset

df = ts[:, segment, "target"]
df = ts[:, segment, in_column]
ts = TSDataset(ts[:, segment, :], ts.freq)
x, y = df.index.values, df.values
cache = {}
Expand Down