-
Notifications
You must be signed in to change notification settings - Fork 80
Add in_column
to plot_anomalies
, plot_anomalies_interactive
#618
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Script for test of import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from etna.analysis import get_anomalies_density
from etna.analysis import plot_anomalies
from etna.datasets import TSDataset
def main():
df = pd.read_csv("examples/data/example_dataset.csv", parse_dates=["timestamp"])
df_exog = df.copy()
df_exog.rename(columns={"target": "leak"}, inplace=True)
df_exog["leak"] = np.log1p(df_exog["leak"])
timestamp = df["timestamp"].sort_values().unique()
timestamp_train = timestamp[10:-10]
df = df[df["timestamp"].isin(timestamp_train)]
ts = TSDataset(df=TSDataset.to_dataset(df), df_exog=TSDataset.to_dataset(df_exog), freq="D", known_future="all")
# plot with target
outliers = get_anomalies_density(ts=ts, distance_coef=1.0, in_column="target")
plot_anomalies(ts=ts, in_column="target", anomaly_dict=outliers)
plt.savefig("anomaly_target")
# plot with not target
outliers = get_anomalies_density(ts=ts, distance_coef=1.0, in_column="leak")
plot_anomalies(ts=ts, in_column="leak", anomaly_dict=outliers)
plt.savefig("anomaly_exog")
if __name__ == "__main__":
main() |
Utility for testing import pathlib
import numpy as np
import pandas as pd
from etna.analysis import get_anomalies_density
from etna.analysis import plot_anomalies_interactive
from etna.datasets import TSDataset
ROOT_PATH = pathlib.Path(__file__).parent
def load_data():
df = pd.read_csv(ROOT_PATH.joinpath("examples/data/example_dataset.csv"), parse_dates=["timestamp"])
df_exog = df.copy()
df_exog.rename(columns={"target": "leak"}, inplace=True)
df_exog["leak"] = np.log1p(df_exog["leak"])
timestamp = df["timestamp"].sort_values().unique()
timestamp_train = timestamp[10:-10]
df = df[df["timestamp"].isin(timestamp_train)]
ts = TSDataset(df=TSDataset.to_dataset(df), df_exog=TSDataset.to_dataset(df_exog), freq="D", known_future="all")
return ts
def plot_target():
ts = load_data()
params_bounds = {"window_size": (5, 20, 1), "distance_coef": (0.1, 3, 0.25)}
method = get_anomalies_density
plot_anomalies_interactive(
ts=ts, in_column="target", segment="segment_a", method=method, params_bounds=params_bounds
)
def plot_leak():
ts = load_data()
params_bounds = {"window_size": (5, 20, 1), "distance_coef": (0.1, 3, 0.25)}
method = get_anomalies_density
plot_anomalies_interactive(ts=ts, in_column="leak", segment="segment_a", method=method, params_bounds=params_bounds) To use it just import |
julia-shenshina
approved these changes
Mar 23, 2022
Codecov Report
@@ Coverage Diff @@
## master #618 +/- ##
=======================================
Coverage 84.54% 84.54%
=======================================
Files 118 118
Lines 5973 5973
=======================================
Hits 5050 5050
Misses 923 923
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IMPORTANT: Please do not create a Pull Request without creating an issue first.
Before submitting (must do checklist)
Type of Change
Proposed Changes
Look #298.
Related Issue
#298.
Closing issues
Closes #298.