Skip to content

getml.pipeline.Scores

Scores(
    data: Sequence[Score], latest: Dict[str, List[float]]
)

Container which holds the history of all scores associated with a given pipeline. The container supports slicing and is sort- and filterable.

PARAMETER DESCRIPTION
data

A list of Score objects.

TYPE: Sequence[Score]

latest

A dictionary containing the latest scores for each metric.

TYPE: Dict[str, List[float]]

Source code in getml/pipeline/scores_container.py
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(self, data: Sequence[Score], latest: Dict[str, List[float]]) -> None:
    self._latest = latest

    self.is_classification = all(
        isinstance(score, ClassificationScore) for score in data
    )

    self.is_regression = not self.is_classification

    self.data = data

    self.sets_used = [score.set_used for score in data]

accuracy property

accuracy: Union[float, List[float]]

A convenience wrapper to retrieve the accuracy from the latest scoring run.

auc property

A convenience wrapper to retrieve the auc from the latest scoring run.

cross_entropy property

cross_entropy: Union[float, List[float]]

A convenience wrapper to retrieve the cross entropy from the latest scoring run.

mae property

A convenience wrapper to retrieve the mae from the latest scoring run.

RETURNS DESCRIPTION
Union[float, List[float]]

The mean absolute error.

rmse property

rmse: Union[float, List[float]]

A convenience wrapper to retrieve the rmse from the latest scoring run.

RETURNS DESCRIPTION
Union[float, List[float]]

The root mean squared error.

rsquared property

rsquared: Union[float, List[float]]

A convenience wrapper to retrieve the rsquared from the latest scoring run.

RETURNS DESCRIPTION
Union[float, List[float]]

The squared correlation coefficient.

filter

filter(conditional: Callable[[Score], bool]) -> Scores

Filters the scores container.

PARAMETER DESCRIPTION
conditional

A callable that evaluates to a boolean for a given item.

TYPE: Callable[[Score], bool]

RETURNS DESCRIPTION
Scores

A container of filtered scores.

Example
from datetime import datetime, timedelta
one_week_ago = datetime.today() - timedelta(days=7)
scores_last_week = pipe.scores.filter(lambda score: score.date_time >= one_week_ago)
Source code in getml/pipeline/scores_container.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def filter(self, conditional: Callable[[Score], bool]) -> Scores:
    """
    Filters the scores container.

    Args:
        conditional:
            A callable that evaluates to a boolean for a given item.

    Returns:
            A container of filtered scores.

    ??? example
        ```python
        from datetime import datetime, timedelta
        one_week_ago = datetime.today() - timedelta(days=7)
        scores_last_week = pipe.scores.filter(lambda score: score.date_time >= one_week_ago)
        ```
    """
    scores_filtered = [score for score in self.data if conditional(score)]

    return Scores(scores_filtered, self._latest)

sort

sort(
    key: Callable[[Score], Union[float, int, str]],
    descending: bool = False,
) -> Scores

Sorts the scores container.

PARAMETER DESCRIPTION
key

A callable that evaluates to a sort key for a given item.

TYPE: Callable[[Score], Union[float, int, str]]

descending

Whether to sort in descending order.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Scores

A container of sorted scores.

Example
by_auc = pipe.scores.sort(key=lambda score: score.auc)
most_recent_first = pipe.scores.sort(key=lambda score: score.date_time, descending=True)
Source code in getml/pipeline/scores_container.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def sort(
    self, key: Callable[[Score], Union[float, int, str]], descending: bool = False
) -> Scores:
    """
    Sorts the scores container.

    Args:
        key:
            A callable that evaluates to a sort key for a given item.

        descending:
            Whether to sort in descending order.

    Returns:
            A container of sorted scores.

    ??? example
        ```python
        by_auc = pipe.scores.sort(key=lambda score: score.auc)
        most_recent_first = pipe.scores.sort(key=lambda score: score.date_time, descending=True)
        ```
    """

    scores_sorted = sorted(self.data, key=key, reverse=descending)
    return Scores(scores_sorted, self._latest)