示例#1
0
def test_ddm():
    """
    DDM drift detection test.
    The first half of the data contains a sequence corresponding to a normal distribution with mean 0 and sigma 0.1.
    The second half corresponds to a normal distribution with mean 0.5 and sigma 0.1.
    """
    ddm = DDM()

    # Data
    np.random.seed(1)
    mu, sigma = 0, 0.1  # mean and standard deviation
    d_1 = np.random.normal(mu, sigma, 1000) > 0
    mu, sigma = 0.5, 0.1  # mean and standard deviation
    d_2 = np.random.normal(mu, sigma, 1000) > 0
    data_stream = np.concatenate((d_1.astype(int), d_2.astype(int)))

    expected_indices = [103, 1060]
    detected_indices = []

    for i in range(data_stream.size):
        ddm.update(data_stream[i])
        if ddm.change_detected:
            detected_indices.append(i)

    assert detected_indices == expected_indices
示例#2
0
# DDM

import numpy as np
from river.drift import DDM

np.random.seed(12345)

ddm = DDM()

# Simulate a data stream as a normal distribution of 1's and 0's
data_stream = np.random.randint(2, size=2000)
# Change the data distribution from index 999 to 1500, simulating an
# increase in error rate (1 indicates error)
data_stream[1000:1200] = [np.random.binomial(1, .8) for _ in range(200)]

# Update drift detector and verify if change is detected
for i, val in enumerate(data_stream):
    in_drift, in_warning = ddm.update(val)
    if in_drift:
        print(f"Change detected at index {i}, input value: {val}")
# Change detected at index 1157, input value: 1