Skip to content

Scorers

siapy.optimizers.scorers

Scorer

Scorer(scorer)
PARAMETER DESCRIPTION
scorer

Source code in siapy/optimizers/scorers.py
18
19
def __init__(self, scorer):
    self._scorer = scorer

init_cross_validator_scorer classmethod

init_cross_validator_scorer(scoring: str | ScorerFuncType | None = None, cv: int | BaseCrossValidator | _RepeatedSplits | Iterable | Literal['RepeatedKFold', 'RepeatedStratifiedKFold'] | None = None, n_jobs: int | None = None) -> Scorer
PARAMETER DESCRIPTION
scoring

TYPE: str | ScorerFuncType | None DEFAULT: None

cv

TYPE: int | BaseCrossValidator | _RepeatedSplits | Iterable | Literal['RepeatedKFold', 'RepeatedStratifiedKFold'] | None DEFAULT: None

n_jobs

TYPE: int | None DEFAULT: None

Source code in siapy/optimizers/scorers.py
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
@classmethod
def init_cross_validator_scorer(
    cls,
    scoring: str | ScorerFuncType | None = None,
    cv: int
    | model_selection.BaseCrossValidator
    | model_selection._split._RepeatedSplits
    | Iterable
    | Literal["RepeatedKFold", "RepeatedStratifiedKFold"]
    | None = None,
    n_jobs: Annotated[
        int | None,
        "Number of jobs to run in parallel. `-1` means using all processors.",
    ] = None,
) -> "Scorer":
    if isinstance(cv, str) and cv in ["RepeatedKFold", "RepeatedStratifiedKFold"]:
        cv = initialize_object(
            module=model_selection,
            module_name=cv,
            n_splits=3,
            n_repeats=5,
            random_state=0,
        )
    scorer = partial(
        cross_validation,
        scoring=scoring,
        cv=cv,  # type: ignore
        groups=None,
        n_jobs=n_jobs,
        verbose=0,
        fit_params=None,
        pre_dispatch=1,
        error_score=0,
    )
    return cls(scorer)

init_hold_out_scorer classmethod

init_hold_out_scorer(scoring: str | ScorerFuncType | None = None, test_size: float | None = 0.2, stratify: ndarray | None = None) -> Scorer
PARAMETER DESCRIPTION
scoring

TYPE: str | ScorerFuncType | None DEFAULT: None

test_size

TYPE: float | None DEFAULT: 0.2

stratify

TYPE: ndarray | None DEFAULT: None

Source code in siapy/optimizers/scorers.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@classmethod
def init_hold_out_scorer(
    cls,
    scoring: str | ScorerFuncType | None = None,
    test_size: float | None = 0.2,
    stratify: np.ndarray | None = None,
) -> "Scorer":
    scorer = partial(
        hold_out_validation,
        scoring=scoring,
        test_size=test_size,
        random_state=0,
        shuffle=True,
        stratify=stratify,
    )
    return cls(scorer)