Skip to content

Commit

Permalink
Added visualization plots (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCarpentier42 authored Dec 2, 2024
1 parent 662bdec commit f74788f
Show file tree
Hide file tree
Showing 10 changed files with 3,447 additions and 5,755 deletions.
1 change: 1 addition & 0 deletions docs/additional_information/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Added
``RobustPrincipalComponentAnalysis`` anomaly detectors.
- Implemented ``HistogramBasedOutlierScore`` anomaly detector.
- Implemented ``OneClassSupportVectorMachine`` anomaly detector.
- Implemented methods to visualize time series and anomalies: ``plot_demarcated_anomalies``, ``plot_with_zoom``, and ``plot_anomaly_scores``.

Changed
^^^^^^^
Expand Down
85 changes: 84 additions & 1 deletion docs/api/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,89 @@ Visualization module

.. automodule:: dtaianomaly.visualization

.. plot::
:context: reset
:include-source: False

import matplotlib.pyplot as plt
plt.rcParams.update({
'figure.autolayout': True,
'figure.titlesize': 18
})


.. autofunction:: dtaianomaly.visualization.plot_demarcated_anomalies

.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_demarcated_anomalies
>>> X, y = demonstration_time_series()
>>> fig = plot_demarcated_anomalies(X, y, figsize=(10, 3))
>>> fig.suptitle("Example of 'plot_demarcated_anomalies'") # doctest: +SKIP


.. autofunction:: dtaianomaly.visualization.plot_time_series_colored_by_score

.. autofunction:: dtaianomaly.visualization.plot_time_series_anomalies
.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_time_series_colored_by_score
>>> X, y = demonstration_time_series()
>>> fig = plot_time_series_colored_by_score(X, y, figsize=(10, 3))
>>> fig.suptitle("Example of 'plot_time_series_colored_by_score' on the ground truth") # doctest: +SKIP

.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_time_series_colored_by_score
>>> from dtaianomaly.anomaly_detection import IsolationForest
>>> X, _ = demonstration_time_series()
>>> y_pred = IsolationForest(window_size=100).fit(X).predict_proba(X)
>>> fig = plot_time_series_colored_by_score(X, y_pred, figsize=(10, 3))
>>> fig.suptitle("Example of 'plot_time_series_colored_by_score' on predictions") # doctest: +SKIP


.. autofunction:: dtaianomaly.visualization.plot_anomaly_scores

.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_anomaly_scores, plot_time_series_colored_by_score
>>> from dtaianomaly.anomaly_detection import IsolationForest
>>> X, y = demonstration_time_series()
>>> y_pred = IsolationForest(window_size=100).fit(X).predict_proba(X)
>>> fig = plot_anomaly_scores(X, y, y_pred, figsize=(10, 3), method_to_plot=plot_time_series_colored_by_score)
>>> fig.suptitle("Example of 'plot_anomaly_scores'") # doctest: +SKIP


.. autofunction:: dtaianomaly.visualization.plot_time_series_anomalies

.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_time_series_anomalies
>>> from dtaianomaly.anomaly_detection import IsolationForest
>>> from dtaianomaly.thresholding import FixedCutoff
>>> X, _ = demonstration_time_series()
>>> y_pred = IsolationForest(window_size=100).fit(X).predict_proba(X)
>>> y_pred_binary = FixedCutoff(cutoff=0.9).threshold(y_pred)
>>> fig = plot_time_series_anomalies(X, y, y_pred_binary, figsize=(10, 3))
>>> fig.suptitle("Example of 'plot_time_series_anomalies'") # doctest: +SKIP


.. autofunction:: dtaianomaly.visualization.plot_with_zoom

.. plot::
:context: close-figs

>>> from dtaianomaly.data import demonstration_time_series
>>> from dtaianomaly.visualization import plot_with_zoom
>>> X, y = demonstration_time_series()
>>> fig = plot_with_zoom(X, y, start_zoom=700, end_zoom=1200, figsize=(10, 3))
>>> fig.suptitle("Example of 'plot_with_zoom'") # doctest: +SKIP
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'numpydoc'
'numpydoc',
'matplotlib.sphinxext.plot_directive'
]

numpydoc_show_class_members = False

# Default settings for matplotlib.sphinxext.plot_directive
plot_include_source = True
plot_html_show_source_link = False
plot_html_show_formats = False

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
9 changes: 6 additions & 3 deletions dtaianomaly/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
along with the ground truth or predicted anomalies.
"""

from .visualization import plot_time_series_colored_by_score, plot_time_series_anomalies
from .visualization import plot_time_series_colored_by_score, plot_time_series_anomalies, plot_demarcated_anomalies, plot_with_zoom, plot_anomaly_scores, format_time_steps

__all__ = [
'plot_time_series_colored_by_score',
'plot_time_series_anomalies'
'plot_time_series_anomalies',
'plot_demarcated_anomalies',
'plot_with_zoom',
'plot_anomaly_scores',
'format_time_steps'
]

Loading

0 comments on commit f74788f

Please sign in to comment.