Skip to content

Classification Module

Classes:

Name Description
BaseClassificationDecision

Base class for classification-based decision-making.

BaseClassificationDecision

BaseClassificationDecision(
    estimator, *, threshold=0.0, predict_mode="score"
)

Bases: BaseDecision, ABC

Base class for classification-based decision-making.

This class provides a common interface for classification-based decision-making algorithms.

It calls estimator.predict_proba(X) or estimator.decision_function(X) to predict the output values.

When using this class?

  • When the decision is based on the output of a classification model.

Parameters:

Name Type Description Default
estimator BaseEstimator

The estimator object used for making predictions.

required
threshold float

The threshold value used for decision-making.

0.0
predict_mode str

The mode to use for prediction. Can be 'proba' or 'score'.

'score'

Attributes:

Name Type Description
estimator BaseEstimator

The estimator object used for making predictions.

threshold float

The threshold value used for decision-making.

predict_mode str

The mode to use for prediction. Can be 'proba' or 'score'.

  • If 'proba', the predict_proba method of the estimator is used.
  • If 'score', the decision_function method of the estimator is used.

Methods:

Name Description
get_params

Get the parameters of the estimator.

make_prediction

Predict the output values based on the input data.

Source code in risk_control/decision/classification.py
45
46
47
48
49
50
51
52
53
54
def __init__(
    self,
    estimator: BaseEstimator,
    *,
    threshold: float = 0.0,
    predict_mode: str = "score",
) -> None:
    super().__init__(estimator=estimator)
    self.threshold = threshold
    self.predict_mode = predict_mode

threshold instance-attribute

threshold = threshold

predict_mode instance-attribute

predict_mode = predict_mode

get_params

get_params()

Get the parameters of the estimator.

Returns:

Name Type Description
params dict

The parameters of the estimator.

Source code in risk_control/decision/classification.py
56
57
58
59
60
61
62
63
64
65
66
67
68
def get_params(self) -> Dict[str, Any]:
    """
    Get the parameters of the estimator.

    Returns
    -------
    params : dict
        The parameters of the estimator.
    """
    return {
        "threshold": self.threshold,
        "predict_mode": self.predict_mode,
    }

make_prediction

make_prediction(X)

Predict the output values based on the input data.

  • If predict_mode is 'proba', return the predicted probabilities.
  • If predict_mode is 'score', return the decision function scores.

Parameters:

Name Type Description Default
X ndarray

The input data for making predictions.

required

Returns:

Type Description
ndarray

The predicted output values based on the input data.

Source code in risk_control/decision/classification.py
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
def make_prediction(self, X: np.ndarray) -> np.ndarray:
    """
    Predict the output values based on the input data.

    - If predict_mode is 'proba', return the predicted probabilities.
    - If predict_mode is 'score', return the decision function scores.

    Parameters
    ----------
    X : np.ndarray
        The input data for making predictions.

    Returns
    -------
    np.ndarray
        The predicted output values based on the input data.
    """
    assert self.predict_mode in [
        "proba",
        "score",
    ], "predict_mode must be 'proba' or 'score'"
    if self.predict_mode == "proba":
        return self.estimator.predict_proba(X)
    elif self.predict_mode == "score":
        return self.estimator.decision_function(X)
    else:
        return self.estimator.predict(X)