Drift detection
Ver. 0.2.0 (2025-03-03)
This module provides templates for drift detection to be used in the context of online adaptivity.
- class mlpro.oa.streams.tasks.driftdetectors.basics.DriftDetector(p_name: str = None, p_range_max=1, p_ada: bool = True, p_duplicate_data: bool = False, p_visualize: bool = False, p_logging=True, p_drift_buffer_size: int = 100, **p_kwargs)
Bases:
OAStreamTaskBase class for online anomaly detectors. It raises an event whenever the beginning or the end of a drift is detected. Please describe in child classes which event classes are used. Always use the _raise_drift_event() method when raising an event.
- Parameters:
p_name (str) – Optional name of the task. Default is None.
p_range_max (int) – Maximum range of asynchonicity. See class Range. Default is Range.C_RANGE_PROCESS.
p_ada (bool) – Boolean switch for adaptivitiy. Default = True.
p_duplicate_data (bool) – If True, instances will be duplicated before processing. Default = False.
p_visualize (bool) – Boolean switch for visualisation. Default = False.
p_logging – Log level (see constants of class Log). Default: Log.C_LOG_ALL
p_drift_buffer_size (int = 100) – Size of the internal drift buffer self.drifts. Default = 100.
p_kwargs (dict) – Further optional named parameters.
- C_TYPE = 'Drift Detector'
- C_PLOT_ACTIVE: bool = True
- C_PLOT_STANDALONE: bool = False
- _get_next_drift_id()
Methd that returns the id of the next drift.
- Returns:
drift_id
- Return type:
int
- _buffer_drift(p_drift: Drift)
Method to be used internally to add a new drift object. Please use as part of your algorithm.
- Parameters:
p_drift (Drift) – Drift object to be added.
- _remove_drift(p_drift: Drift)
Method to remove an existing drift object. Please use as part of your algorithm.
- Parameters:
p_drift (Drift) – Drift object to be removed.
- _raise_drift_event(p_drift: Drift, p_buffer: bool = True)
Specialized method to raise drift events.
- Parameters:
p_drift (Drift) – Drift event object to be raised.
- init_plot(p_figure: Figure = None, p_plot_settings: PlotSettings = None)
Initializes the plot functionalities of the class.
- Parameters:
p_figure (Matplotlib.figure.Figure, optional) – Optional MatPlotLib host figure, where the plot shall be embedded. The default is None.
p_plot_settings (PlotSettings) – Optional plot settings. If None, the default view is plotted (see attribute C_PLOT_DEFAULT_VIEW).
- update_plot(p_inst: Dict[int, Tuple[str, Instance]] = None, **p_kwargs)
Specialized definition of method update_plot() of class mlpro.bf.plot.Plottable.
- Parameters:
p_inst (InstDict) – Instances to be plotted.
p_kwargs (dict) – Further optional plot parameters.
- remove_plot(p_refresh: bool = True)
” Removes the plot and optionally refreshes the display.
- Parameters:
p_refresh (bool = True) – On True the display is refreshed after removal
- _renormalize(p_normalizer)
Internal renormalization of all buffered drifts. See method OATask.renormalize_on_event() for further information.
- Parameters:
p_normalizer (Normalizer) – Normalizer object to be applied on task-specific
Ver. 0.3.0 (2025-02-19)
This module provides a template class for types of data drift to be used in drift detection algorithms.
- class mlpro.oa.streams.tasks.driftdetectors.drifts.basics.Drift(p_drift_status: bool, p_id: int = 0, p_tstamp: datetime = None, p_visualize: bool = False, p_raising_object: object = None, **p_kwargs)
Bases:
Id,Event,Plottable,RenormalizableThis is the base class for drift events which can be raised by drift detectors when the beginning or end of a drift is detected.
- Parameters:
p_drift_status (bool) – Determines whether a new drift starts (True) or an existing drift ends (False).
p_id (int) – Drift ID. Default value = 0.
p_tstamp (datetime) – Time stamp of drift detection. Default = None.
p_visualize (bool) – Boolean switch for visualisation. Default = False.
p_raising_object (object) – Reference of the object raised. Default = None.
**p_kwargs – Further optional keyword arguments.
- event_id
Event id to be used when raising a drift event object. It is a string consisting of the class name and one of the postfixes ‘(ON)’, ‘(OFF)’ depending on the drift status.
- Type:
str
- C_PLOT_STANDALONE: bool = False
- _get_drift_status() bool
- _get_event_id() str
- property drift_status: bool
- property event_id: str