File size: 4,446 Bytes
1910b25
 
4560eb1
 
 
1910b25
bdd162d
1910b25
 
4560eb1
 
 
 
 
1910b25
 
bdd162d
 
 
4560eb1
 
 
 
bdd162d
 
 
4560eb1
 
 
 
 
 
 
 
bdd162d
 
4560eb1
 
 
 
 
 
 
 
 
 
 
 
bdd162d
 
 
4560eb1
bdd162d
4560eb1
 
 
 
bdd162d
 
 
4560eb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd162d
 
 
 
4560eb1
 
 
 
 
 
 
 
 
 
 
 
bdd162d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: Geometric Mean
emoji: 🤗 
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 3.0.2
app_file: app.py
pinned: false
tags:
- evaluate
- metric
description: >-
 The geometric mean (G-mean) is the root of the product of class-wise sensitivity.  
---

# Metric Card for Geometric Mean

## Metric Description

The geometric mean (G-mean) is the root of the product of class-wise sensitivity. 
This measure tries to maximize the accuracy on each of the classes while keeping these accuracies balanced. 
For binary classification G-mean is the squared root of the product of the sensitivity and specificity. 

## How to Use

At minimum, this metric requires predictions and references as input

```python
>>> gmean_metric = evaluate.load("geometric_mean")
>>> results = gmean_metric.compute(predictions=[0, 1], references=[0, 1])
>>> print(results)
["{'geometric-mean': 1.0}"]
```

### Inputs
- **predictions** (`list` of `int`): Predicted labels.
- **references** (`list` of `int`): Ground truth labels.
- **labels** (`list` of `int`): The set of labels to include when average != 'binary', and their order if average is None. Labels present in the data can be excluded, for example to calculate a multiclass average ignoring a majority negative class, while labels not present in the data will result in 0 components in a macro average. Defaults to None.
- **pos_label** (`string` or `int`): The class to report if average='binary' and the data is binary. If the data are multiclass, this will be ignored; setting labels=[pos_label] and average != 'binary' will report scores for that label only. Defaults to 1.
- **average** (`string`): If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data. Defaults to `'multiclass'`.
    - 'binary': Only report results for the class specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.
    - 'micro': Calculate metrics globally by counting the total true positives, false negatives and false positives.
    - 'macro': Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
    - 'weighted': Calculate metrics for each label, and find their average, weighted by support (the number of true instances for each label).
    - 'samples': Calculate metrics for each instance, and find their average (only meaningful for multilabel classification where this differs from accuracy_score).
- **sample_weight** (`list` of `float`): Sample weights. Defaults to None.
- **correction** (`float`): Substitutes sensitivity of unrecognized classes from zero to a given value. Defaults to 0.0.

### Output Values

- **geometric_mean** (`float` or `array` of `float`): geometric mean score or list of geometric mean scores, depending on the value passed to `average`. Minimum possible value is 0. Maximum possible value is 1. Higher geometric mean scores are better.

Output Example:
```python
{'geometric_mean': 0.4714045207910317}
```


### Examples

Example 1-A simple binary example
```python
>>> geometric_mean = evaluate.load("geometric_mean")
>>> results = geometric_mean.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0])
>>> print(round(res['geometric-mean'], 2))
0.58
```

Example 2-The same simple binary example as in Example 1, but with `sample_weight` included.
```python
>>> geometric_mean = evaluate.load("geometric_mean")
>>> results = geometric_mean.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0], sample_weight=[0.9, 0.5, 3.9, 1.2, 0.3])
>>> print(round(results['geometric-mean'], 2))
0.35
```

Example 3-A multiclass example, with `average` equal to `macro`.
```python
>>> predictions = [0, 2, 1, 0, 0, 1]
>>> references = [0, 1, 2, 0, 1, 2]
>>> results = geometric_mean.compute(predictions=predictions, references=references, average="macro")
>>> print(round(results['geometric-mean'], 2))
0.47
```

## Limitations and Bias
*Note any known limitations or biases that the metric has, with links and references if possible.*

## Citation(s)
```bibtex
@article{imbalanced-learn,
  title={Imbalanced-learn: A Python Toolbox to Tackle the Curse of
Imbalanced Datasets in Machine Learning},
  author={Lemaˆıtre, G. and Nogueira, F. and Aridas, C.},
  journal={Journal of Machine Learning Research},
  volume={18},
  pages={1-5},
  year={2017}
}
```

## Further References
*Add any useful further references.*