Skip to content

Commit 523d06a

Browse files
committed
Add documentation
1 parent fc62532 commit 523d06a

File tree

4 files changed

+87
-18
lines changed

4 files changed

+87
-18
lines changed

environment.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: mapie-dev
22
channels:
3+
- defaults
34
- conda-forge
45
dependencies:
56
- bump2version=1.0.1

mapie/classification.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,16 @@ def _check_fit_parameter(
914914
y: ArrayLike,
915915
sample_weight: Optional[ArrayLike] = None,
916916
groups: Optional[ArrayLike] = None,
917-
):
917+
) -> Tuple[
918+
Optional[ClassifierMixin],
919+
Optional[Union[int, str, BaseCrossValidator]],
920+
ArrayLike,
921+
NDArray,
922+
NDArray,
923+
Optional[NDArray],
924+
Optional[NDArray],
925+
ArrayLike
926+
]:
918927
"""
919928
Perform several checks on class parameters.
920929
@@ -934,6 +943,14 @@ def _check_fit_parameter(
934943
train/test set.
935944
By default ``None``.
936945
946+
Returns
947+
-------
948+
Tuple[Optional[ClassifierMixin],
949+
Optional[Union[int, str, BaseCrossValidator]],
950+
ArrayLike, NDArray, NDArray, Optional[NDArray],
951+
Optional[NDArray], ArrayLike]
952+
953+
Parameters checked
937954
Raises
938955
------
939956
ValueError
@@ -973,7 +990,48 @@ def _check_fit_parameter(
973990

974991
return (estimator, cv, X, y, y_enc, sample_weight, groups, n_samples)
975992

976-
def _split_data(self, X, y_enc, sample_weight, groups, size_raps):
993+
def _split_data(
994+
self,
995+
X,
996+
y_enc,
997+
sample_weight,
998+
groups,
999+
size_raps
1000+
) -> Tuple[ArrayLike, ArrayLike, ArrayLike, ArrayLike, NDArray, ArrayLike]:
1001+
1002+
"""Split data for raps method
1003+
Parameters
1004+
----------
1005+
X: ArrayLike
1006+
Observed values.
1007+
1008+
y_enc: ArrayLike
1009+
Target values as normalized encodings.
1010+
1011+
sample_weight: Optional[NDArray] of shape (n_samples,)
1012+
Non-null sample weights.
1013+
1014+
groups: Optional[ArrayLike] of shape (n_samples,)
1015+
Group labels for the samples used while splitting the dataset into
1016+
train/test set.
1017+
By default ``None``.
1018+
1019+
size_raps: : Optional[float]
1020+
Percentage of the data to be used for choosing lambda_star and
1021+
k_star for the RAPS method.
1022+
1023+
Returns
1024+
-------
1025+
Tuple[ArrayLike, ArrayLike, ArrayLike, NDArray, Optional[NDArray],
1026+
Optional[ArrayLike]]
1027+
1028+
- ArrayLike of shape (n_samples, n_features)
1029+
- ArrayLike of shape (n_samples,)
1030+
- ArrayLike of shape (n_samples,)
1031+
- ArrayLike of shape (n_samples,)
1032+
- NDArray of shape (n_samples,)
1033+
- ArrayLike of shape (n_samples,)
1034+
"""
9771035
raps_split = ShuffleSplit(
9781036
1, test_size=size_raps, random_state=self.random_state
9791037
)

mapie/estimator/classification/estimator.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def predict(
449449
X: ArrayLike,
450450
alpha_np: ArrayLike = [],
451451
agg_scores: Any = None
452-
) -> Union[NDArray, Tuple[NDArray, NDArray, NDArray]]:
452+
) -> NDArray:
453453
"""
454454
Predict target from X. It also computes the prediction per train sample
455455
for each test sample according to ``self.method``.
@@ -459,14 +459,19 @@ def predict(
459459
X: ArrayLike of shape (n_samples, n_features)
460460
Test data.
461461
462-
TODO
462+
alpha_np: ArrayLike of shape (n_alphas)
463+
Level of confidences.
464+
465+
agg_scores: Optional[str]
466+
How to aggregate the scores output by the estimators on test data
467+
if a cross-validation strategy is used
463468
464-
Returns TODO
469+
Returns
465470
-------
466-
Tuple[NDArray, NDArray, NDArray]
467-
- Predictions
468-
- The multiple predictions for the lower bound of the intervals.
469-
- The multiple predictions for the upper bound of the intervals.
471+
NDArray
472+
Predictions of shape
473+
(n_samples, n_classes)
474+
470475
"""
471476
check_is_fitted(self, self.fit_attributes)
472477
alpha_np = cast(NDArray, alpha_np)

mapie/estimator/classification/interface.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from abc import ABCMeta, abstractmethod
4-
from typing import Any, Optional, Tuple, Union
4+
from typing import Any, Optional
55

66
from sklearn.base import ClassifierMixin
77

@@ -40,7 +40,8 @@ def fit(
4040
y: ArrayLike of shape (n_samples,)
4141
Input labels.
4242
43-
# TODO document this
43+
y_enc: ArrayLike
44+
Target values as normalized encodings.
4445
4546
sample_weight: Optional[ArrayLike] of shape (n_samples,)
4647
Sample weights. If None, then samples are equally weighted.
@@ -66,7 +67,7 @@ def predict(
6667
X: ArrayLike,
6768
alpha_np: ArrayLike = [],
6869
agg_scores: Any = None
69-
) -> Union[NDArray, Tuple[NDArray, NDArray, NDArray]]:
70+
) -> NDArray:
7071
"""
7172
Predict target from X. It also computes the prediction per train sample
7273
for each test sample according to ``self.method``.
@@ -76,12 +77,16 @@ def predict(
7677
X: ArrayLike of shape (n_samples, n_features)
7778
Test data.
7879
79-
TODO
80+
alpha_np: ArrayLike of shape (n_alphas)
81+
Level of confidences.
8082
81-
Returns TODO
83+
agg_scores: Optional[str]
84+
How to aggregate the scores output by the estimators on test data
85+
if a cross-validation strategy is used
86+
87+
Returns
8288
-------
83-
Tuple[NDArray, NDArray, NDArray]
84-
- Predictions
85-
- The multiple predictions for the lower bound of the intervals.
86-
- The multiple predictions for the upper bound of the intervals.
89+
NDArray
90+
Predictions of shape
91+
(n_samples, n_classes)
8792
"""

0 commit comments

Comments
 (0)