Monitors
Last updated
Last updated
This guide will show you how to automatically add monitors to your models from code using the Python SDK. For more information on the various types of monitors in Aporia, please refer to the documentation on monitors.
To define a new monitor, create an aporia.Monitor(...)
object.
When designing a new monitor, the first decision you have to make is:
What's the monitor type you'd like to create?
Examples: Data drift, Missing values, Performance degradation, etc.
This step is similar to the following step in the UI:
What's the detection method you'd like to use?
Examples: Anomaly Detection over Time, Change in Percentage, Absolute values, Compared to Training, Compared to Segment, etc.
This step is similar to the following step in the UI:
To begin, start by creating a monitor object, with your chosen monitor_type
and detection_method
, and add it to your model.
See Detection Methods Overview and Supported Monitor Types / Detection Methods for the an overview on different monitor types and their supported detection methods.
The next step is to choose the dataset in which your monitor will be evaluated - this is called the focal dataset. In most detection methods, you'll also need to provide a baseline dataset.
For example, if you want to create a data drift monitor to compare the distribution of a feature from the last week to the training set, then focal will be "last week in serving", and baseline will be "training set".
Baseline is required for any monitor that has a "Compared to" field like in the example below, or in any detection method that is not DetectionMethod.ABSOLUTE
:
Here's an example for focal / baseline in an anomaly detection over time monitor:
Next, it is time to configure some important parameters for the monitor. For example:
The following table describes the required parameters for each monitor type
Monitor | Detection Method | Required Parameters |
---|---|---|
Model Activity | Anomaly Detection |
|
Model Activity | Change in Percentage |
|
Model Activity | Absolute values |
|
Data Drift | Anomaly Detection |
|
Data Drift | Compared to Segment |
|
Data Drift | Compared to Training |
|
Prediction Drift | Anomaly Detection |
|
Prediction Drift | Compared to Segment |
|
Prediction Drift | Compared to Training |
|
Missing Values | Anomaly Detection |
|
Missing Values | Change in Percentage |
|
Missing Values | Absolute values |
|
Missing Values | Compared to Segment |
|
Model Staleness | Absolute |
|
New Values | Percentage |
|
New Values | Compared to Segment |
|
New Values | Compared to Training |
|
Values Range | Percentage |
|
Values Range | Absolute |
|
Values Range | Compared to Segment |
|
Values Range | Compared to Training |
|
Performance Degradation | Anomaly Detection |
|
Performance Degradation | Absolute |
|
Performance Degradation | Percentage |
|
Performance Degradation | Compared to Segment |
|
Performance Degradation | Compared to Training |
|
Metric Change | Anomaly Detection |
|
Metric Change | Absolute |
|
Metric Change | Percentage |
|
Metric Change | Compared to Segment |
|
Metric Change | Compared to Training |
|
Custom Metric | Anomaly Detection |
|
Custom Metric | Absolute |
|
Custom Metric | Percentage |
|
k
: Used for ranking metrics, such as NDCG, MRR, MAP etc.
prediction_threshold
: Used for binary confusion matrix metrics, such as accuracy, tp_count, recall etc. Used with a numeric prediction (0-1) and a boolean actual.
prediction_class
: The class for which to calculate per-class metrics, such as accuracy-per-class.
average_method
: Used for precision/recall/f1_score on multiclass predictions. Values are of aporia.AverageMethod
enum (MICRO
/MACRO
/WEIGHTED
)
Finally, any monitor requires a severity
parameter to describe the severity of the alerts generated by this monitor (low / medium / high).
You can also add an emails
parameter for receiving the alert in mail, or the messaging
parameter for integration with Webhooks, Datadog, Slack, Teams, etc.
Detection Method | Enum value | Description | Exmaple |
---|---|---|---|
Anomaly Detection over Time |
| This will train an anomaly detection model to raise an alert if there's an anomaly in metric value with respect to a certain baseline | Missing value ratio of last week compared to week before that |
Change in Percentage |
| Detect change in percentage in metric value | Standard deviation changed by >20% |
Absolute values |
| Raise an alert when metric value is larger or smaller than a certain value | Accuracy is lower than 0.9 |
Compared to Segment |
| Detect changes in metric value between two data segments | Data drift between |
Compared to Training |
| Data change in metric value compared to the training set | Prediction drift of last month in serving compared to training |
The following table describes the various monitor types and their supported detection methods:
Monitor Type | Enum value | Supported detection methods |
---|---|---|
Model Activity |
|
|
Data Drift |
|
|
Prediction Drift |
|
|
Missing Values |
|
|
Performance Degradation |
|
|
Metric Change |
|
|
Custom Metric |
|
|
Model Staleness |
|
|
Value Range |
|
|
New Values |
|
|