tsadmetrics 0.1.15__py3-none-any.whl → 0.1.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docs_api/conf.py +90 -0
- docs_manual/conf.py +90 -0
- tests/test_binary.py +194 -7
- tests/test_non_binary.py +138 -59
- tests/test_utils.py +49 -0
- tsadmetrics/__init__.py +1 -1
- tsadmetrics/binary_metrics.py +214 -19
- tsadmetrics/metric_utils.py +3 -238
- tsadmetrics/non_binary_metrics.py +113 -110
- tsadmetrics/scripts/__init__.py +0 -0
- tsadmetrics/scripts/compute_metrics.py +42 -0
- tsadmetrics/utils.py +71 -2
- tsadmetrics/validation.py +35 -0
- tsadmetrics-0.1.17.dist-info/METADATA +54 -0
- {tsadmetrics-0.1.15.dist-info → tsadmetrics-0.1.17.dist-info}/RECORD +18 -11
- tsadmetrics-0.1.17.dist-info/entry_points.txt +2 -0
- {tsadmetrics-0.1.15.dist-info → tsadmetrics-0.1.17.dist-info}/top_level.txt +2 -0
- tsadmetrics-0.1.15.dist-info/METADATA +0 -23
- {tsadmetrics-0.1.15.dist-info → tsadmetrics-0.1.17.dist-info}/WHEEL +0 -0
docs_api/conf.py
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
2
|
+
#
|
3
|
+
|
4
|
+
import os
|
5
|
+
import sys
|
6
|
+
sys.path.insert(0, os.path.abspath('../'))
|
7
|
+
|
8
|
+
|
9
|
+
project = 'TSADmetrics'
|
10
|
+
copyright = '2025, Pedro Rafael Velasco Priego'
|
11
|
+
author = 'Pedro Rafael Velasco Priego'
|
12
|
+
release = 'MIT'
|
13
|
+
|
14
|
+
# -- General configuration ---------------------------------------------------
|
15
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
16
|
+
|
17
|
+
|
18
|
+
extensions = ['sphinx.ext.duration', 'sphinx.ext.doctest', 'sphinx.ext.autodoc',]
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
templates_path = ['_templates']
|
23
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
24
|
+
|
25
|
+
html_theme = 'furo'
|
26
|
+
html_static_path = ['_static']
|
27
|
+
html_theme_options = {
|
28
|
+
#"sidebar_hide_name": True,
|
29
|
+
"light_css_variables": {
|
30
|
+
"color-brand-primary": "#2e5c7d",
|
31
|
+
"color-brand-content": "#2e5c7d",
|
32
|
+
"codebgcolor": "red",
|
33
|
+
"codetextcolor": "red",
|
34
|
+
},
|
35
|
+
"dark_css_variables": {
|
36
|
+
"color-brand-primary": "#6998b4",
|
37
|
+
"color-brand-content": "#6998b4",
|
38
|
+
"codebgcolor": "green",
|
39
|
+
"codetextcolor": "green",
|
40
|
+
},
|
41
|
+
"navigation_with_keys": True
|
42
|
+
|
43
|
+
}
|
44
|
+
html_baseurl = ''
|
45
|
+
|
46
|
+
html_css_files = [
|
47
|
+
'css/custom.css',
|
48
|
+
]
|
49
|
+
|
50
|
+
epub_show_urls = 'footnote'
|
51
|
+
|
52
|
+
# -- Options for HTML output -------------------------------------------------
|
53
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
### -- LaTeX options -------------------------------------------------
|
59
|
+
|
60
|
+
# comando para compilar: make latexpdf LATEXMKOPTS="-xelatex"
|
61
|
+
|
62
|
+
latex_elements = {
|
63
|
+
'maxlistdepth': '10', # Aumenta el límite de anidamiento
|
64
|
+
'papersize': 'a4paper',
|
65
|
+
'pointsize': '10pt',
|
66
|
+
'maketitle': r'''
|
67
|
+
\makeatletter
|
68
|
+
\begin{titlepage}
|
69
|
+
\noindent\rule{\textwidth}{1pt}\\[3cm]
|
70
|
+
\begin{center}
|
71
|
+
{\Huge\sffamily\bfseries TSADmetrics API Reference}\\[1.5cm]
|
72
|
+
{\Large\sffamily Time Series Anomaly Detection Metrics}\\[3cm]
|
73
|
+
\begin{minipage}{0.8\textwidth}
|
74
|
+
\centering
|
75
|
+
{\large\sffamily
|
76
|
+
\begin{tabular}{l@{\hspace{1cm}}l}
|
77
|
+
\textbf{Autor:} & Pedro Rafael Velasco Priego \\
|
78
|
+
\textbf{Directores:} & Dra. Amelia Zafra Gómez \\
|
79
|
+
& Dr. Sebastián Ventura Soto \\
|
80
|
+
\end{tabular}
|
81
|
+
}
|
82
|
+
\end{minipage}\\[5cm]
|
83
|
+
{\large\sffamily \@date}\\
|
84
|
+
{\large\sffamily \copyright\ 2025 Pedro Rafael Velasco Priego}
|
85
|
+
\end{center}
|
86
|
+
\noindent\rule{\textwidth}{1pt}
|
87
|
+
\end{titlepage}
|
88
|
+
\makeatother
|
89
|
+
''',
|
90
|
+
}
|
docs_manual/conf.py
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
2
|
+
#
|
3
|
+
|
4
|
+
import os
|
5
|
+
import sys
|
6
|
+
sys.path.insert(0, os.path.abspath('../'))
|
7
|
+
|
8
|
+
|
9
|
+
project = 'TSADmetrics'
|
10
|
+
copyright = '2025, Pedro Rafael Velasco Priego'
|
11
|
+
author = 'Pedro Rafael Velasco Priego'
|
12
|
+
release = 'MIT'
|
13
|
+
|
14
|
+
# -- General configuration ---------------------------------------------------
|
15
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
16
|
+
|
17
|
+
|
18
|
+
extensions = ['sphinx.ext.duration', 'sphinx.ext.doctest', 'sphinx.ext.autodoc',]
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
templates_path = ['_templates']
|
23
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
24
|
+
|
25
|
+
html_theme = 'furo'
|
26
|
+
html_static_path = ['_static']
|
27
|
+
html_theme_options = {
|
28
|
+
#"sidebar_hide_name": True,
|
29
|
+
"light_css_variables": {
|
30
|
+
"color-brand-primary": "#2e5c7d",
|
31
|
+
"color-brand-content": "#2e5c7d",
|
32
|
+
"codebgcolor": "red",
|
33
|
+
"codetextcolor": "red",
|
34
|
+
},
|
35
|
+
"dark_css_variables": {
|
36
|
+
"color-brand-primary": "#6998b4",
|
37
|
+
"color-brand-content": "#6998b4",
|
38
|
+
"codebgcolor": "green",
|
39
|
+
"codetextcolor": "green",
|
40
|
+
},
|
41
|
+
"navigation_with_keys": True
|
42
|
+
|
43
|
+
}
|
44
|
+
html_baseurl = ''
|
45
|
+
|
46
|
+
html_css_files = [
|
47
|
+
'css/custom.css',
|
48
|
+
]
|
49
|
+
|
50
|
+
epub_show_urls = 'footnote'
|
51
|
+
|
52
|
+
# -- Options for HTML output -------------------------------------------------
|
53
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
### -- LaTeX options -------------------------------------------------
|
59
|
+
|
60
|
+
# comando para compilar: make latexpdf LATEXMKOPTS="-xelatex"
|
61
|
+
|
62
|
+
latex_elements = {
|
63
|
+
'maxlistdepth': '10', # Aumenta el límite de anidamiento
|
64
|
+
'papersize': 'a4paper',
|
65
|
+
'pointsize': '10pt',
|
66
|
+
'maketitle': r'''
|
67
|
+
\makeatletter
|
68
|
+
\begin{titlepage}
|
69
|
+
\noindent\rule{\textwidth}{1pt}\\[3cm]
|
70
|
+
\begin{center}
|
71
|
+
{\Huge\sffamily\bfseries TSADmetrics User Manual}\\[1.5cm]
|
72
|
+
{\Large\sffamily Time Series Anomaly Detection Metrics}\\[3cm]
|
73
|
+
\begin{minipage}{0.8\textwidth}
|
74
|
+
\centering
|
75
|
+
{\large\sffamily
|
76
|
+
\begin{tabular}{l@{\hspace{1cm}}l}
|
77
|
+
\textbf{Autor:} & Pedro Rafael Velasco Priego \\
|
78
|
+
\textbf{Directores:} & Dra. Amelia Zafra Gómez \\
|
79
|
+
& Dr. Sebastián Ventura Soto \\
|
80
|
+
\end{tabular}
|
81
|
+
}
|
82
|
+
\end{minipage}\\[5cm]
|
83
|
+
{\large\sffamily \@date}\\
|
84
|
+
{\large\sffamily \copyright\ 2025 Pedro Rafael Velasco Priego}
|
85
|
+
\end{center}
|
86
|
+
\noindent\rule{\textwidth}{1pt}
|
87
|
+
\end{titlepage}
|
88
|
+
\makeatother
|
89
|
+
''',
|
90
|
+
}
|
tests/test_binary.py
CHANGED
@@ -593,8 +593,40 @@ class TestAverageDetectionCount(unittest.TestCase):
|
|
593
593
|
"""
|
594
594
|
pass
|
595
595
|
|
596
|
+
def setUp(self):
|
597
|
+
"""
|
598
|
+
Configuración inicial para las pruebas.
|
599
|
+
"""
|
600
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
601
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
602
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
603
|
+
|
604
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
605
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
606
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
607
|
+
|
596
608
|
|
597
609
|
|
610
|
+
def test_average_detection_count(self):
|
611
|
+
"""
|
612
|
+
Prueba para la función average_detection_count.
|
613
|
+
"""
|
614
|
+
metric = round(average_detection_count(self.y_true1, self.y_pred1),2)
|
615
|
+
expected_metric = 0.5
|
616
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
617
|
+
|
618
|
+
metric = round(average_detection_count(self.y_true1, self.y_pred2),2)
|
619
|
+
expected_metric = 0.12
|
620
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
621
|
+
|
622
|
+
metric = round(average_detection_count(self.y_true2, self.y_pred21),2)
|
623
|
+
expected_metric = 0.33
|
624
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
625
|
+
|
626
|
+
metric = round(average_detection_count(self.y_true2, self.y_pred22),2)
|
627
|
+
expected_metric = 0.67
|
628
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
629
|
+
|
598
630
|
|
599
631
|
def test_average_detection_count_consistency(self):
|
600
632
|
try:
|
@@ -615,9 +647,33 @@ class TestAbsoluteDetectionDistance(unittest.TestCase):
|
|
615
647
|
"""
|
616
648
|
Configuración inicial para las pruebas.
|
617
649
|
"""
|
618
|
-
|
650
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
651
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
652
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
619
653
|
|
620
|
-
|
654
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
655
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
656
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
657
|
+
|
658
|
+
def test_absolute_detection_distance(self):
|
659
|
+
"""
|
660
|
+
Prueba para la función absolute_detection_distance.
|
661
|
+
"""
|
662
|
+
metric = round(absolute_detection_distance(self.y_true1, self.y_pred1),2)
|
663
|
+
expected_metric = 0.25
|
664
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
665
|
+
|
666
|
+
metric = round(absolute_detection_distance(self.y_true1, self.y_pred2),2)
|
667
|
+
expected_metric = 0.25
|
668
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
669
|
+
|
670
|
+
metric = round(absolute_detection_distance(self.y_true2, self.y_pred21),2)
|
671
|
+
expected_metric = 0.06
|
672
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
673
|
+
|
674
|
+
metric = round(absolute_detection_distance(self.y_true2, self.y_pred22),2)
|
675
|
+
expected_metric = 0.12
|
676
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
621
677
|
|
622
678
|
|
623
679
|
def test_absolute_detection_distance_consistency(self):
|
@@ -639,7 +695,33 @@ class TestTotalDetectedInRange(unittest.TestCase):
|
|
639
695
|
"""
|
640
696
|
Configuración inicial para las pruebas.
|
641
697
|
"""
|
642
|
-
|
698
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
699
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
700
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
701
|
+
|
702
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
703
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
704
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
705
|
+
|
706
|
+
def test_total_detected_in_range(self):
|
707
|
+
"""
|
708
|
+
Prueba para la función total_detected_in_range.
|
709
|
+
"""
|
710
|
+
metric = round(total_detected_in_range(self.y_true1, self.y_pred1,k=3),2)
|
711
|
+
expected_metric = 0.5
|
712
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
713
|
+
|
714
|
+
metric = round(total_detected_in_range(self.y_true1, self.y_pred2,k=3),2)
|
715
|
+
expected_metric = 0.5
|
716
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
717
|
+
|
718
|
+
metric = round(total_detected_in_range(self.y_true2, self.y_pred21,k=3),2)
|
719
|
+
expected_metric = 0.56
|
720
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
721
|
+
|
722
|
+
metric = round(total_detected_in_range(self.y_true2, self.y_pred22,k=3),2)
|
723
|
+
expected_metric = 0.44
|
724
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
643
725
|
|
644
726
|
|
645
727
|
|
@@ -663,7 +745,33 @@ class TestDetectionAccuracyInRange(unittest.TestCase):
|
|
663
745
|
"""
|
664
746
|
Configuración inicial para las pruebas.
|
665
747
|
"""
|
666
|
-
|
748
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
749
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
750
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
751
|
+
|
752
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
753
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
754
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
755
|
+
|
756
|
+
def test_detection_accuracy_in_range(self):
|
757
|
+
"""
|
758
|
+
Prueba para la función detection_accuracy_in_range.
|
759
|
+
"""
|
760
|
+
metric = round(detection_accuracy_in_range(self.y_true1, self.y_pred1,k=3),2)
|
761
|
+
expected_metric = 1.0
|
762
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
763
|
+
|
764
|
+
metric = round(detection_accuracy_in_range(self.y_true1, self.y_pred2,k=3),2)
|
765
|
+
expected_metric = 1.0
|
766
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
767
|
+
|
768
|
+
metric = round(detection_accuracy_in_range(self.y_true2, self.y_pred21,k=3),2)
|
769
|
+
expected_metric = 1.0
|
770
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
771
|
+
|
772
|
+
metric = round(detection_accuracy_in_range(self.y_true2, self.y_pred22,k=3),2)
|
773
|
+
expected_metric = 1.0
|
774
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
667
775
|
|
668
776
|
|
669
777
|
|
@@ -688,7 +796,33 @@ class TestWeightedDetectionDifference(unittest.TestCase):
|
|
688
796
|
"""
|
689
797
|
Configuración inicial para las pruebas.
|
690
798
|
"""
|
691
|
-
|
799
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
800
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
801
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
802
|
+
|
803
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
804
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
805
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
806
|
+
|
807
|
+
def test_weighted_detection_difference(self):
|
808
|
+
"""
|
809
|
+
Prueba para la función weighted_detection_difference.
|
810
|
+
"""
|
811
|
+
metric = round(weighted_detection_difference(self.y_true1, self.y_pred1,k=3),2)
|
812
|
+
expected_metric = 18.89
|
813
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
814
|
+
|
815
|
+
metric = round(weighted_detection_difference(self.y_true1, self.y_pred2,k=3),2)
|
816
|
+
expected_metric = 24.89
|
817
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
818
|
+
|
819
|
+
metric = round(weighted_detection_difference(self.y_true2, self.y_pred21,k=3),2)
|
820
|
+
expected_metric = 15.73
|
821
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
822
|
+
|
823
|
+
metric = round(weighted_detection_difference(self.y_true2, self.y_pred22,k=3),2)
|
824
|
+
expected_metric = 16.73
|
825
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
692
826
|
|
693
827
|
|
694
828
|
|
@@ -712,7 +846,33 @@ class TestPATE(unittest.TestCase):
|
|
712
846
|
"""
|
713
847
|
Configuración inicial para las pruebas.
|
714
848
|
"""
|
715
|
-
|
849
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
850
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
851
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
852
|
+
|
853
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
854
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
855
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
856
|
+
|
857
|
+
def test_binary_pate(self):
|
858
|
+
"""
|
859
|
+
Prueba para la función binary_pate.
|
860
|
+
"""
|
861
|
+
metric = round(binary_pate(self.y_true1, self.y_pred1,early=2, delay=2),2)
|
862
|
+
expected_metric = 0.67
|
863
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
864
|
+
|
865
|
+
metric = round(binary_pate(self.y_true1, self.y_pred2,early=2, delay=2),2)
|
866
|
+
expected_metric = 0.27
|
867
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
868
|
+
|
869
|
+
metric = round(binary_pate(self.y_true2, self.y_pred21,early=2, delay=2),2)
|
870
|
+
expected_metric = 0.71
|
871
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
872
|
+
|
873
|
+
metric = round(binary_pate(self.y_true2, self.y_pred22,early=2, delay=2),2)
|
874
|
+
expected_metric = 0.62
|
875
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
716
876
|
|
717
877
|
|
718
878
|
|
@@ -737,7 +897,34 @@ class TestMeanTimeToDetect(unittest.TestCase):
|
|
737
897
|
"""
|
738
898
|
Configuración inicial para las pruebas.
|
739
899
|
"""
|
740
|
-
|
900
|
+
self.y_true1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
|
901
|
+
self.y_pred1 = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
902
|
+
self.y_pred2 = np.array([0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
|
903
|
+
|
904
|
+
self.y_true2 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
905
|
+
self.y_pred21 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1])
|
906
|
+
self.y_pred22 = np.array([0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0])
|
907
|
+
|
908
|
+
def test_mean_time_to_detect(self):
|
909
|
+
"""
|
910
|
+
Prueba para la función mean_time_to_detect.
|
911
|
+
"""
|
912
|
+
metric = round(mean_time_to_detect(self.y_true1, self.y_pred1),2)
|
913
|
+
expected_metric = 0.0
|
914
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
915
|
+
|
916
|
+
metric = round(mean_time_to_detect(self.y_true1, self.y_pred2),2)
|
917
|
+
expected_metric = 0.0
|
918
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
919
|
+
|
920
|
+
metric = round(mean_time_to_detect(self.y_true2, self.y_pred21),2)
|
921
|
+
expected_metric = 8.0
|
922
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
923
|
+
|
924
|
+
metric = round(mean_time_to_detect(self.y_true2, self.y_pred22),2)
|
925
|
+
expected_metric = 0.0
|
926
|
+
self.assertAlmostEqual(metric, expected_metric, places=4)
|
927
|
+
|
741
928
|
|
742
929
|
|
743
930
|
|