On a data stream the honest evaluation is prequential: predict each example before training on it, then update. Implement an online logistic-regression learner and the prequential protocol, with a drift point where the labelling rule flips.
online_logreg_step(w, x, y, lr)
w is (d,), x (d,), y in . Predict and return (pred, w_next) with pred = int(p >= 0.5) and w_next = w - lr * (p - y) * x (one step of gradient descent on the log loss).prequential(X, y, w0, lr, window)
"accuracy" (overall prequential accuracy, float), "windows" (list of mean accuracies over consecutive blocks of window examples; a final shorter block is included), and "w" (the final weights as a rounded list, 4 decimals).make_drift_stream(n, d, drift_at, rng)
(n, d) matrix of standard normal features with a single rng.normal call; labels are int(x[0] > 0) before index drift_at and int(x[0] <= 0) from drift_at on (the rule flips). Return (X, y) with y an integer array.recovery_steps(window_acc, window, drift_at, threshold)
window_acc is the "windows" list from a prequential run. Return the number of examples after the drift until the first window that starts at or after drift_at reaches accuracy >= threshold, measured from drift_at to the end of that window; return -1 if no such window exists.i * window to (i + 1) * window - 1; the first window at or after the drift starts at index ceil(drift_at / window) * window.