Triggers¶
- PREDICT.Triggers.CITLThreshold(model, lower_limit=None, upper_limit=None)¶
Create a trigger that fires when Calibration-In-The-Large (CITL) falls outside provided bounds.
- Parameters:
model (PREDICTModel) – The model to evaluate, must have a predict method.
lower_limit (float, optional) – Lower acceptable bound for CITL. If None, only upper_limit is used.
upper_limit (float, optional) – Upper acceptable bound for CITL. If None, only lower_limit is used.
- Returns:
Bound method that accepts (self, input_data) and returns True when CITL is outside bounds.
- Return type:
MethodType
- PREDICT.Triggers.CalibrationSlopeThreshold(model, lower_limit=None, upper_limit=None)¶
Create a trigger that fires when calibration slope falls outside provided bounds.
- Parameters:
model (PREDICTModel) – The model to evaluate, must have a predict method.
lower_limit (float, optional) – Lower acceptable bound for calibration slope. If None, only upper_limit is used.
upper_limit (float, optional) – Upper acceptable bound for calibration slope. If None, only lower_limit is used.
- Returns:
Bound method that accepts (self, input_data) and returns True when calibration slope is outside bounds.
- Return type:
MethodType
- PREDICT.Triggers.KLDivergenceThreshold(model, input_data, update_threshold=0.1)¶
Create a trigger that fires when the KL divergence of residuals exceeds a threshold.
- Parameters:
model (PREDICTModel) – The model to evaluate, must have a predict method and an outcomeColName attribute.
initial_data (pd.DataFrame) – Data to compute initial residuals from.
update_threshold (float) – KL divergence threshold to trigger an update.
- Returns:
Bound method that accepts (self, input_data) and returns True when KL divergence is too high.
- Return type:
MethodType
- PREDICT.Triggers.SPCTrigger(model, input_data, dateCol='date', clStartDate=None, clEndDate=None, numMonths=None, warningCL=None, recalCL=None, warningSDs=2, recalSDs=3, verbose=True)¶
- Trigger function to update the model if the error enters an upper control limit.
The control limits can be set using one of the following methods:
Enter a start (clStartDate) and end date (clEndDate) to determine the control limits using the error mean and std during this period.
Enter the number of months (numMonths) to base the control limits on from the start of the period.
Manually set the control limits by entering the float values for the ‘warning’ (warningCL) and ‘recalibration’ (recalCL) zones.
Enter the number of standard deviations from the mean for the start of the warning zone (warningSDs) and the start of the recalibration zone (recalSDs).
- Parameters:
model (PREDICTModel) – The model to evaluate, must have a predict method.
input_data (dataframe) – DataFrame with column of the predicted outcome.
dateCol (str) – Column containing the dates.
clStartDate (str) – Start date to determine control limits from. Defaults to None.
clEndDate (str) – End date to determine control limits from. Defaults to None.
numMonths (int) – The number of months to base the control limits on. Defaults to None.
warningCL (float) – A manually set control limit for the warning control limit. Defaults to None.
recalCL (float) – A manually set control limit for the recalibration trigger limit. Defaults to None.
warningSDs (int or float) – Number of standard deviations from the mean to set the warning limit to. Defaults to 2.
recalSDs (int or float) – Number of standard deviations from the mean to set the recalibration trigger to. Defaults to 3.
verbose (bool) – If True, prints the control limit warnings. Defaults to True.
- Returns:
A tuple containing:
pd.Timedelta: The calculated time interval for updating the model.
pd.DatetimeIndex: A range of dates specifying the update schedule.
- Return type:
tuple
- PREDICT.Triggers.TimeframeTrigger(model, updateTimestep, dataStart, dataEnd)¶
Create a list of dates to update the model based on a fixed time interval.
- Parameters:
model (PREDICTModel) – The model to evaluate, must have a predict method.
updateTimestep (pd.Timedelta) – Time interval at which to update the model. Note: The model can only be recalibrated at the end of the time interval. If the prediction window is less than the updateTimestep, the model will not be recalibrated.
dataStart (pd.Timedelta) – Date of when to start regular recalibration.
dataEnd (pd.Timedelta) – Date of when to end regular recalibration.
- Raises:
TypeError – If updateTimestep is not a valid input.
- Returns:
A tuple containing:
pd.Timedelta: The calculated time interval for updating the model.
pd.DatetimeIndex: A range of dates specifying the update schedule, excluding the first window.
- Return type:
tuple