Skip to content

Decision Base Module

Classes:

Name Description
BaseDecision

Abstract base class for decision-making in risk control.

BaseDecision

BaseDecision(estimator)

Bases: ABC

Abstract base class for decision-making in risk control.

This class provides a common interface for decision-making algorithms used in risk control. It includes methods for making predictions and decisions.

How does it work?

  • The decision-making algorithm is initialized with an estimator.
  • The estimator is used to make predictions.
  • The decision is made based on the hyper-parameters and the predictions.

How to use it?

  • Initialize the decision-making algorithm with an estimator and a parameter space.
  • Make predictions using the predict method.
    • First, the estimator is used to make predictions using the make_prediction method.
    • Then, the decision is made based on the hyper-parameters and the predictions using the make_decision method.

Parameters:

Name Type Description Default
estimator BaseEstimator

The estimator object used for making predictions.

required

Attributes:

Name Type Description
estimator BaseEstimator

The estimator object used for making predictions.

Methods:

Name Description
set_params

Set the parameters of the estimator.

get_params

Get the parameters of the estimator.

make_prediction

Abstract method for predicting output values based on the input data.

make_decision

Abstract method for predicting decisions based on output values.

predict

Predict decisions based on the input data.

fit

Fit the estimator to the input data.

Source code in risk_control/decision/base.py
43
44
def __init__(self, estimator: BaseEstimator) -> None:
    self.estimator = estimator

estimator instance-attribute

estimator = estimator

set_params

set_params(**params)

Set the parameters of the estimator.

Parameters:

Name Type Description Default
**params Dict[str, Any]

The parameters to set on the estimator.

{}

Returns:

Name Type Description
self BaseDecision

Returns the instance itself.

Source code in risk_control/decision/base.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def set_params(
    self,
    **params: Dict[str, Any],
) -> Self:
    """
    Set the parameters of the estimator.

    Parameters
    ----------
    **params : Dict[str, Any]
        The parameters to set on the estimator.

    Returns
    -------
    self : BaseDecision
        Returns the instance itself.
    """
    for key, value in params.items():
        setattr(self, key, value)
    return self

get_params abstractmethod

get_params()

Get the parameters of the estimator.

Returns:

Name Type Description
params Dict[str, Any]

The parameters of the estimator.

Source code in risk_control/decision/base.py
67
68
69
70
71
72
73
74
75
76
77
@abstractmethod
def get_params(self) -> Dict[str, Any]:
    """
    Get the parameters of the estimator.

    Returns
    -------
    params : Dict[str, Any]
        The parameters of the estimator.
    """
    pass

make_prediction abstractmethod

make_prediction(X)

Abstract method for predicting output values based on the input data.

Parameters:

Name Type Description Default
X ndarray

The input data for making predictions.

required

Returns:

Type Description
Any

The predicted output values based on the input data.

Source code in risk_control/decision/base.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@abstractmethod
def make_prediction(self, X: np.ndarray) -> Any:
    """
    Abstract method for predicting output values based on the input data.

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

    Returns
    -------
    Any
        The predicted output values based on the input data.
    """
    pass

make_decision abstractmethod

make_decision(y_output)

Abstract method for predicting decisions based on output values.

Parameters:

Name Type Description Default
y_output Any

The predicted output values.

required

Returns:

Type Description
ndarray

The predicted decisions based on the output values.

Source code in risk_control/decision/base.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@abstractmethod
def make_decision(self, y_output: Any) -> np.ndarray:
    """
    Abstract method for predicting decisions based on output values.

    Parameters
    ----------
    y_output : Any
        The predicted output values.

    Returns
    -------
    np.ndarray
        The predicted decisions based on the output values.
    """
    pass

predict

predict(X)

Predict decisions based on the input data.

Parameters:

Name Type Description Default
X ndarray

The input data for making predictions.

required

Returns:

Type Description
ndarray

The predicted decisions based on the input data.

Source code in risk_control/decision/base.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def predict(self, X: np.ndarray) -> np.ndarray:
    """
    Predict decisions based on the input data.

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

    Returns
    -------
    np.ndarray
        The predicted decisions based on the input data.
    """
    y_output = self.make_prediction(X)
    y_decision = self.make_decision(y_output)
    return y_decision

fit

fit(X, y)

Fit the estimator to the input data.

This method is a placeholder and does not perform any fitting. It is intended to be overridden by subclasses that require fitting.

Parameters:

Name Type Description Default
X ndarray

The input data for fitting the estimator.

required
y ndarray

The target values for fitting the estimator.

required

Returns:

Name Type Description
self BaseDecision

Returns the instance itself.

Source code in risk_control/decision/base.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def fit(self, X: np.ndarray, y: np.ndarray) -> Self:
    """
    Fit the estimator to the input data.

    This method is a placeholder and does not perform any fitting. It is
    intended to be overridden by subclasses that require fitting.

    Parameters
    ----------
    X : np.ndarray
        The input data for fitting the estimator.
    y : np.ndarray
        The target values for fitting the estimator.

    Returns
    -------
    self : BaseDecision
        Returns the instance itself.
    """
    return self