Skip to content

Regression Module

Classes:

Name Description
BaseRegressionDecision

Base class for regression-based decision-making.

AdvancedRegressionDecision

Advanced class for regression-based decision-making.

BaseRegressionDecision

BaseRegressionDecision(estimator, *, threshold=0.0)

Bases: BaseDecision, ABC

Base class for regression-based decision-making.

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

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

When using this class?

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

Parameters:

Name Type Description Default
estimator BaseEstimator

The estimator used to predict the output values.

required
threshold float

The threshold for the prediction. If the prediction is less than or equal to the threshold, the decision is NaN; otherwise, the prediction.

0.0

Attributes:

Name Type Description
estimator BaseEstimator

The estimator used to predict the output values.

threshold float

The threshold for the residual.

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/regression.py
38
39
40
41
42
43
44
45
def __init__(
    self,
    estimator: BaseEstimator,
    *,
    threshold: float = 0.0,
) -> None:
    super().__init__(estimator)
    self.threshold = threshold

threshold instance-attribute

threshold = threshold

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/regression.py
47
48
49
50
51
52
53
54
55
56
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}

make_prediction

make_prediction(X)

Predict the output values 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 output values based on the input data.

Source code in risk_control/decision/regression.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def make_prediction(self, X: np.ndarray) -> np.ndarray:
    """
    Predict the output values based on the input data.

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

    Returns
    -------
    np.ndarray
        The predicted output values based on the input data.
    """
    return self.estimator.predict(X)

AdvancedRegressionDecision

AdvancedRegressionDecision(
    estimator, residual, *, threshold=1.0
)

Bases: BaseDecision, ABC

Advanced class for regression-based decision-making.

This class provides a common interface for regression-based decision-making algorithms based on residuals.

It calls estimator.predict(X) to predict the output values and residual.predict(X) to predict the residuals.

When using this class?

  • When the prediction and residual are estimated separately.
  • When the decision is based on the residual.

Parameters:

Name Type Description Default
estimator BaseEstimator

The estimator used to predict the output values.

required
residual BaseEstimator

The estimator used to predict the residuals.

required
threshold float

The threshold for the residual. If the residual is less than or equal to the threshold, the prediction is returned; otherwise, NaN. The default is 0.0.

1.0

Attributes:

Name Type Description
estimator BaseEstimator

The estimator used to predict the output values.

residual BaseEstimator

The estimator used to predict the residuals.

threshold float

The threshold for the residual.

Methods:

Name Description
get_params

Get the parameters of the estimator.

make_prediction

Predict the output values and residuals for the input data.

Source code in risk_control/decision/regression.py
109
110
111
112
113
114
115
116
117
118
def __init__(
    self,
    estimator: BaseEstimator,
    residual: BaseEstimator,
    *,
    threshold: float = 1.0,
) -> None:
    super().__init__(estimator)
    self.residual = residual
    self.threshold = threshold

residual instance-attribute

residual = residual

threshold instance-attribute

threshold = threshold

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/regression.py
120
121
122
123
124
125
126
127
128
129
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}

make_prediction

make_prediction(X)

Predict the output values and residuals for the input data.

Parameters:

Name Type Description Default
X ndarray

The input data for which to predict the output values and residuals.

required

Returns:

Type Description
Tuple[ndarray, ndarray]

The predicted output values and residuals. The first element is the predicted output values, and the second element is the predicted residuals.

Source code in risk_control/decision/regression.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def make_prediction(self, X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
    """
    Predict the output values and residuals for the input data.

    Parameters
    ----------
    X : np.ndarray
        The input data for which to predict the output values and residuals.

    Returns
    -------
    Tuple[np.ndarray, np.ndarray]
        The predicted output values and residuals.
        The first element is the predicted output values, and the second element
        is the predicted residuals.
    """
    return self.estimator.predict(X), self.residual.predict(X)