Skip to content

Commit 9fc34fd

Browse files
committed
docs: improve docstring docs #13
1 parent 0cabbb0 commit 9fc34fd

File tree

4 files changed

+429
-153
lines changed

4 files changed

+429
-153
lines changed

src/modelsight/_typing.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
This file deals with the implementation of custom types.
3+
"""
4+
15
import sys
26
import random
37
import numpy as np
@@ -24,7 +28,37 @@
2428

2529

2630
@dataclass
27-
class CVModellingOutput:
31+
class CVModellingOutput:
32+
"""This class stores the data generated by a cross-validation
33+
process for a single estimator.
34+
35+
Arguments
36+
---------
37+
gts_train: ArrayLike
38+
A (n_repetitions * n_outer_splits) list of arrays representing training ground-truth.
39+
gts_val: ArrayLike
40+
A (n_repetitions * n_outer_splits) list of arrays representing validation ground-truth.
41+
gts_train_conc: ArrayLike
42+
A list of (n_repetitions * n_outer_splits) data points representing pooled training ground-truth.
43+
gts_val_conc: ArrayLike
44+
A list of (n_repetitions * n_outer_splits) data points representing pooled validation ground-truth.
45+
probas_train: ArrayLike
46+
A (n_repetitions * n_outer_splits) list of arrays representing training predicted probabilities.
47+
probas_val: ArrayLike
48+
A (n_repetitions * n_outer_splits) list of arrays representing validation predicted probabilities.
49+
probas_train_conc: ArrayLike
50+
A list of (n_repetitions * n_outer_splits) data points representing pooled training predicted probabilities.
51+
probas_val_conc: ArrayLike
52+
A list of (n_repetitions * n_outer_splits) data points representing pooled validation predicted probabilities.
53+
models: List[Estimator]
54+
A list of (n_repetitions * n_outer_splits) fitted estimators.
55+
errors: Optional[ArrayLike]
56+
A (n_repetitions * n_outer_splits) list of validation prediction errors.
57+
correct: Optional[ArrayLike]
58+
A (n_repetitions * n_outer_splits) list of validation correct predictions.
59+
features: Optional[ArrayLike]
60+
A (n_repetitions * n_outer_splits) list of subsets of selected features.
61+
"""
2862
gts_train: ArrayLike
2963
gts_val: ArrayLike
3064
gts_train_conc: ArrayLike

src/modelsight/calibration/calib.py

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
This file deals with the implementation of the Hosmer-Lemeshow plot for the
3+
assessment of calibration of predicted probabilities.
4+
"""
5+
16
import numpy as np
27
from typing import Tuple
38
import matplotlib.pyplot as plt
@@ -6,11 +11,14 @@
611

712

813
def ntile_name(n: int) -> str:
9-
"""Returns the ntile name corresponding to an ntile integer.
14+
"""
15+
Returns the ntile name corresponding to an ntile integer.
16+
1017
Parameters
1118
----------
1219
n : int
1320
An ntile integer.
21+
1422
Returns
1523
-------
1624
ntile_name : str
@@ -30,13 +38,16 @@ def ntile_name(n: int) -> str:
3038

3139
def make_recarray(y_true: ArrayLike,
3240
y_pred: ArrayLike) -> np.recarray:
33-
"""Combines arrays into a recarray.
41+
"""
42+
Combines arrays into a recarray.
43+
3444
Parameters
3545
----------
3646
y_true : array
3747
Observed labels, either 0 or 1.
3848
y_pred : array
3949
Predicted probabilities, floats on [0, 1].
50+
4051
Returns
4152
-------
4253
table : recarray
@@ -53,7 +64,9 @@ def make_recarray(y_true: ArrayLike,
5364
def hosmer_lemeshow_table(y_true: ArrayLike,
5465
y_pred: ArrayLike,
5566
n_bins: int = 10) -> np.recarray:
56-
"""Constructs a Hosmer–Lemeshow table.
67+
"""
68+
Constructs a Hosmer–Lemeshow table.
69+
5770
Parameters
5871
----------
5972
y_true : array
@@ -63,6 +76,7 @@ def hosmer_lemeshow_table(y_true: ArrayLike,
6376
n_bins : int, optional
6477
The number of groups to create. The default value is 10, which
6578
corresponds to deciles of predicted probabilities.
79+
6680
Returns
6781
-------
6882
table : recarray
@@ -100,26 +114,28 @@ def hosmer_lemeshow_plot(y_true: ArrayLike,
100114
101115
Parameters
102116
----------
103-
y_true: ArrayLike
117+
y_true : ArrayLike
104118
(n_obs,) shaped array of ground-truth values
105-
y_pred: ArrayLike
119+
y_pred : ArrayLike
106120
(n_obs,) shaped array of predicted probabilities
107-
n_bins: int
121+
n_bins : int
108122
Number of bins to group observed and predicted probabilities into
109-
colors: Tuple[str, str]
123+
colors : Tuple[str, str]
110124
Pair of colors for observed (line) and predicted (vertical bars) probabilities.
111-
annotate_bars: bool
125+
annotate_bars : bool
112126
Whether bars should be annotated with the number of observed probabilities in each bin.
113-
title: str
127+
title : str
114128
Title to display on top of the calibration plot.
115-
brier_score_annot: str
129+
brier_score_annot : str
116130
Optional brier score (95% CI) annotation on the top-left corner.
117-
ax: plt.Axes
131+
ax : plt.Axes
118132
A matplotlib Axes object to draw the calibration plot into. If None, an Axes object is created by default.
133+
119134
Returns
120135
-------
121-
Tuple[plt.Figure, plt.Axes]:
122-
Corresponding figure and Axes
136+
f, ax : Tuple[plt.Figure, plt.Axes]
137+
f: pyplot figure
138+
ax: pyplot Axes
123139
"""
124140
table = hosmer_lemeshow_table(y_true, y_pred, n_bins)
125141
# transform observed and predicted frequencies in percentage relative to the bin dimension

0 commit comments

Comments
 (0)