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.

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.

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.

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))
__init__(min_instances=30, delta=0.005, threshold=50, alpha=0.9999)[source]

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

Methods

__init__([min_instances, delta, threshold, …])

Initialize self.

add_element(x)

Add a new element to the statistics

detected_change()

This function returns whether concept drift was detected or not.

detected_warning_zone()

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

get_info()

Collects and returns the information about the configuration of the estimator

get_length_estimation()

Returns the length estimation.

get_params([deep])

Get parameters for this estimator.

reset()

Resets the change detector parameters.

set_params(**params)

Set the parameters of this estimator.

Attributes

estimator_type

add_element(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()[source]

This function returns whether concept drift was detected or not.

Returns

Whether concept drift was detected or not.

Return type

bool

detected_warning_zone()[source]

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

Returns

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

Return type

bool

get_info()[source]

Collects and returns the information about the configuration of the estimator

Returns

Configuration of the estimator.

Return type

string

get_length_estimation()[source]

Returns the length estimation.

Returns

The length estimation

Return type

int

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters

deep (boolean, optional) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

reset()[source]

Resets the change detector parameters.

set_params(**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

Return type

self