skmultiflow.drift_detection.PageHinkley

class skmultiflow.drift_detection.PageHinkley(min_instances=30, delta=0.005, threshold=50, alpha=0.9999)[source]

Page-Hinkley method for concept drift detection.

Parameters
min_instances: int (default=30)

The minimum number of instances before detecting change.

delta: float (default=0.005)

The delta factor for the Page Hinkley test.

threshold: int (default=50)

The change detection threshold (lambda).

alpha: float (default=1 - 0.0001)

The forgetting factor, used to weight the observed value and the mean.

Notes

This change detection method works by computing the observed values and their mean up to the current moment. Page-Hinkley won’t output warning zone warnings, only change detections. The method works by means of the Page-Hinkley test [1]. In general lines it will detect a concept drift if the observed mean at some instant is greater then a threshold value lambda.

References

1

E. S. Page. 1954. Continuous Inspection Schemes. Biometrika 41, 1/2 (1954), 100–115.

Examples

>>> # Imports
>>> import numpy as np
>>> from skmultiflow.drift_detection import PageHinkley
>>> ph = PageHinkley()
>>> # Simulating a data stream as a normal distribution of 1's and 0's
>>> data_stream = np.random.randint(2, size=2000)
>>> # Changing the data concept from index 999 to 2000
>>> for i in range(999, 2000):
...     data_stream[i] = np.random.randint(4, high=8)
>>> # Adding stream elements to the PageHinkley drift detector and verifying if drift occurred
>>> for i in range(2000):
...     ph.add_element(data_stream[i])
...     if ph.detected_change():
...         print('Change has been detected in data: ' + str(data_stream[i]) + ' - of index: ' + str(i))

Methods

add_element(self, x)

Add a new element to the statistics

detected_change(self)

This function returns whether concept drift was detected or not.

detected_warning_zone(self)

If the change detector supports the warning zone, this function will return whether it’s inside the warning zone or not.

get_info(self)

Collects and returns the information about the configuration of the estimator

get_length_estimation(self)

Returns the length estimation.

get_params(self[, deep])

Get parameters for this estimator.

reset(self)

Resets the change detector parameters.

set_params(self, **params)

Set the parameters of this estimator.

Attributes

estimator_type

add_element(self, x)[source]

Add a new element to the statistics

Parameters
x: numeric value

The observed value, from which we want to detect the concept change.

Notes

After calling this method, to verify if change was detected, one should call the super method detected_change, which returns True if concept drift was detected and False otherwise.

detected_change(self)[source]

This function returns whether concept drift was detected or not.

Returns
bool

Whether concept drift was detected or not.

detected_warning_zone(self)[source]

If the change detector supports the warning zone, this function will return whether it’s inside the warning zone or not.

Returns
bool

Whether the change detector is in the warning zone or not.

get_info(self)[source]

Collects and returns the information about the configuration of the estimator

Returns
string

Configuration of the estimator.

get_length_estimation(self)[source]

Returns the length estimation.

Returns
int

The length estimation

get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

reset(self)[source]

Resets the change detector parameters.

set_params(self, **params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self