-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompStats.qmd
More file actions
113 lines (85 loc) · 4.17 KB
/
CompStats.qmd
File metadata and controls
113 lines (85 loc) · 4.17 KB
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
106
107
108
109
110
111
112
113
---
title: "CompStats"
format:
dashboard:
logo: images/ingeotec.png
orientation: columns
nav-buttons: [github]
theme: cosmo
execute:
freeze: auto
---
# Introduction
## Column
::: {.card title='Introduction'}
Collaborative competitions have gained popularity in the scientific and technological fields. These competitions involve defining tasks, selecting evaluation scores, and devising result verification methods. In the standard scenario, participants receive a training set and are expected to provide a solution for a held-out dataset kept by organizers. An essential challenge for organizers arises when comparing algorithms' performance, assessing multiple participants, and ranking them. Statistical tools are often used for this purpose; however, traditional statistical methods often fail to capture decisive differences between systems' performance. CompStats implements an evaluation methodology for statistically analyzing competition results and competition. CompStats offers several advantages, including off-the-shell comparisons with correction mechanisms and the inclusion of confidence intervals.
:::
::: {.card title='Installing using conda' .flow}
`CompStats` can be install using the conda package manager with the following instruction.
```{sh}
conda install --channel conda-forge CompStats
```
:::
::: {.card title='Installing using pip' .flow}
A more general approach to installing `CompStats` is through the use of the command pip, as illustrated in the following instruction.
```{sh}
pip install CompStats
```
:::
# scikit-learn Users
## Column
To illustrate the use of `CompStats`, the following snippets show an example. The instructions load the necessary libraries, including the one to obtain the problem (e.g., digits), four different classifiers, and the last line is the score used to measure the performance and compare the algorithm.
Belowe the imports, it is found the code to load the digits problem and split the dataset into training and validation sets.
::: {.card title="Dataset and libraries" .flow}
```{python}
#| echo: true
#| code-fold: true
from sklearn.svm import LinearSVC
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.base import clone
from CompStats.metrics import f1_score
X, y = load_digits(return_X_y=True)
_ = train_test_split(X, y, test_size=0.3)
X_train, X_val, y_train, y_val = _
```
:::
The first line estimates the parameters of a linear Support Vector Machine and predict the validation set's classes. The predictions are stored in the variable `hy`.
::: {.card title="Linear SVM" .flow}
```{python}
#| echo: true
m = LinearSVC().fit(X_train, y_train)
hy = m.predict(X_val)
```
:::
Once the predictions are available, it is time to measure the algorithm's performance, as seen in the following code. It is essential to note that the API used in `sklearn.metrics` is followed; the difference is that the function returns an instance with different methods that can be used to estimate different performance statistics and compare algorithms.
::: {.card title="Score" .flow}
```{python}
#| echo: true
score = f1_score(y_val, hy, average='macro')
score
```
:::
## Column
Continuing with the example, let us assume that one wants to test another classifier on the same problem, in this case, a random forest, as can be seen in the following two lines. The second line predicts the validation set and sets it to the analysis.
::: {.card title="Random Forest" .flow}
```{python}
#| echo: true
ens = RandomForestClassifier().fit(X_train, y_train)
score(ens.predict(X_val), name='Random Forest')
```
:::
Let us incorporate another predictions, now with Naive Bayes classifier, and Histogram Gradient Boosting as seen below.
::: {.card title="Rest of the classifiers" .flow}
```{python}
#| echo: true
nb = GaussianNB().fit(X_train, y_train)
_ = score(nb.predict(X_val), name='Naive Bayes')
hist = HistGradientBoostingClassifier().fit(X_train, y_train)
_ = score(hist.predict(X_val), name='Hist. Grad. Boost. Tree')
score.plot()
```
:::