ealvaradob commited on
Commit
4e0a19f
β€’
1 Parent(s): 2810f97

Create false_positive_rate.py

Browse files
Files changed (1) hide show
  1. false_positive_rate.py +58 -0
false_positive_rate.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ from sklearn.metrics import confusion_matrix
3
+ import evaluate
4
+
5
+ _DESCRIPTION = """
6
+ FPR is the proportion of negative cases incorrectly identified as positive cases in the data (i.e. the probability that false alerts will be raised). It is defined as:
7
+ FPR = FP / (FP + TN)
8
+ Where:
9
+ TN: True negative
10
+ FP: False positive
11
+ """
12
+
13
+
14
+ _KWARGS_DESCRIPTION = """
15
+ Args:
16
+ predictions (`list` of `int`): Predicted labels.
17
+ references (`list` of `int`): Ground truth (correct) target values.
18
+ normalize (`boolean`): Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.
19
+ sample_weight (`list` of `float`): Sample weights. Defaults to None.
20
+ Returns:
21
+ false positive rate (`float` or `int`): FPR score. Minimum possible value is 0. Maximum possible value is 1.0.
22
+ """
23
+
24
+ _CITATION = """
25
+ @misc{ enwiki:1178431122,
26
+ author = "{Wikipedia contributors}",
27
+ title = "False positives and false negatives --- {Wikipedia}{,} The Free Encyclopedia",
28
+ year = "2023",
29
+ url = "https://en.wikipedia.org/w/index.php?title=False_positives_and_false_negatives&oldid=1178431122",
30
+ note = "[Online; accessed 17-November-2023]"
31
+ }
32
+ """
33
+
34
+ @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
35
+ class FPR(evaluate.Metric):
36
+ def _info(self):
37
+ return evaluate.MetricInfo(
38
+ description=_DESCRIPTION,
39
+ citation=_CITATION,
40
+ inputs_description=_KWARGS_DESCRIPTION,
41
+ features=datasets.Features(
42
+ {
43
+ "predictions": datasets.Sequence(datasets.Value("int32")),
44
+ "references": datasets.Sequence(datasets.Value("int32")),
45
+ }
46
+ if self.config_name == "multilabel"
47
+ else {
48
+ "predictions": datasets.Value("int32"),
49
+ "references": datasets.Value("int32"),
50
+ }
51
+ ),
52
+ reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html"],
53
+ )
54
+
55
+ def _compute(self, predictions, references, normalize=None, sample_weight=None):
56
+ tn, fp, fn, tp = confusion_matrix(references, predictions, normalize=normalize, sample_weight=sample_weight).ravel()
57
+ fpr = fp / (fp + tn)
58
+ return {"false_positive_rate": fpr}