Neural Mastery
← Practice
Page-Hinkley Concept Drift Statistic Updatehard

Page-Hinkley Concept Drift Statistic Update

hard ML Systems & MLOps 15 min

NumPy allowed · plain Python earns 10 bonus points

Implement one update step of the Page-Hinkley test, a real, lightweight streaming concept-drift detector used to monitor a live model's error rate without storing a full history window.

Task

Implement page_hinkley_update(cumulative_sum, running_min, new_error, running_mean_error, delta). Update new_cumulative_sum = cumulative_sum + (new_error - running_mean_error - delta). Update new_running_min = min(running_min, new_cumulative_sum). The current Page-Hinkley statistic (how far above the running minimum the cumulative sum has drifted) is ph_value = new_cumulative_sum - new_running_min. Return the tuple (new_cumulative_sum, new_running_min, ph_value).

Function Signature

page_hinkley_update(cumulative_sum: float, running_min: float, new_error: float, running_mean_error: float, delta: float) -> tuple

Examples

Example 1: error near mean, small drift
Input: cumulative_sum = 0 running_min = 0 new_error = 0.5 running_mean_error = 0.5 delta = 0.005
Output: [-0.005, -0.005, 0]
Example 2: error spike increases ph_value
Input: cumulative_sum = 0 running_min = 0 new_error = 5 running_mean_error = 0.5 delta = 0.005
Output: [4.495, 0, 4.495]
Example 3: sequential call reusing prior state
Input: cumulative_sum = 2 running_min = -1 new_error = 0.6 running_mean_error = 0.5 delta = 0.005
Output: [2.0949999999999998, -1, 3.0949999999999998]

Constraints

  • delta >= 0
Python3Saved ✓
def page_hinkley_update(cumulative_sum, running_min, new_error, running_mean_error, delta):
# Your implementation here
pass

Case 1: error near mean, small drift
Input: cumulative_sum = 0 running_min = 0 new_error = 0.5 running_mean_error = 0.5 delta = 0.005
Expected: [-0.005, -0.005, 0]
Case 2: error spike increases ph_value
Input: cumulative_sum = 0 running_min = 0 new_error = 5 running_mean_error = 0.5 delta = 0.005
Expected: [4.495, 0, 4.495]
Case 3: sequential call reusing prior state
Input: cumulative_sum = 2 running_min = -1 new_error = 0.6 running_mean_error = 0.5 delta = 0.005
Expected: [2.0949999999999998, -1, 3.0949999999999998]