pitci.xgboost.XGBSklearnAbsoluteErrorConformalPredictor

class pitci.xgboost.XGBSklearnAbsoluteErrorConformalPredictor(model)[source]

Bases: pitci.base.AbsoluteErrorConformalPredictor

Conformal interval predictor for an underlying xgb.XGBRegressor or xgb.XGBClassifier model using non-scaled absolute error as the nonconformity measure.

Class implements inductive conformal intervals where a calibration dataset is used to learn the information that is used when generating intervals for new instances.

The predictor outputs fixed width intervals for every new instance, there is no interval scaling implemented in this class.

The currently supported xgboost objective functions, given the nonconformity measure that is based on absolute error, are defined in the SUPPORTED_OBJECTIVES attribute.

Parameters

model (xgb.XGBRegressor or xgb.XGBClassifier) – Underlying xgb.XGBRegressor or xgb.XGBClassifier model to generate prediction intervals with.

__version__

The version of the pitci package that generated the object.

Type

str

model

The underlying xgb.XGBRegressor or xgb.XGBClassifier model passed in initialising the object.

Type

xgb.XGBRegressor or xgb.XGBClassifier

baseline_interval

The default or baseline conformal half interval width. Will be applied without modification to provide an interval for all new instances. Attribute is set when the calibrate() method is run.

Type

float

alpha

The confidence level of the conformal intervals that will be produced. Attribute is set when the calibrate() method is run.

Type

int or float

SUPPORTED_OBJECTIVES

Booster supported objectives. If an xgb.XGBRegressor or xgb.XGBClassifier with a non-supported objective is passed when initialising the class object an error will be raised.

Type

list

__init__(model)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(model)

Initialize self.

calibrate(data, response[, alpha])

Calibrate conformal intervals that will be applied to new instances when calling predict_with_interval.

predict_with_interval(data)

Generate predictions with conformal intervals using the underlying model.

calibrate(data, response, alpha=0.95)[source]

Calibrate conformal intervals that will be applied to new instances when calling predict_with_interval.

The value passed in alpha is stored in an attribute of the same name.

Parameters
  • data (np.ndarray or pd.DataFrame) – Dataset to calibrate baselines on.

  • response (np.ndarray or pd.Series) – The associated response values for every record in data.

  • alpha (int or float, default = 0.95) – Confidence level for the intervals.

predict_with_interval(data)[source]

Generate predictions with conformal intervals using the underlying model.

Parameters

data (np.ndarray or pd.DataFrame) – Dataset to generate predictions with intervals on.

Returns

predictions_with_interval – Array of predictions with intervals for each row in data. Output array will have 3 columns where the first is the lower interval, second are the predictions and the third is the upper interval.

Return type

np.ndarray