A Rust library for detecting and measuring concept drift in machine learning model predictions over time.
- Statistical drift detection algorithms - Implements ADWIN and other proven methods
- Sliding window analysis for streaming data - Efficient memory-bounded analysis
- Configurable sensitivity thresholds and alerts - Customizable detection parameters
use neural_drift::{detectors::AdwinDetector, window::SlidingWindow};
// Create a new ADWIN detector with default confidence
let mut detector = AdwinDetector::new(0.002)?;
// Process streaming predictions
let predictions = vec![0.8, 0.7, 0.9, 0.3, 0.2, 0.1]; // accuracy values
for prediction in predictions {
if detector.add_element(prediction)? {
println!("Concept drift detected!");
}
}use neural_drift::window::SlidingWindow;
// Create a sliding window with capacity of 100 elements
let mut window = SlidingWindow::new(100);
// Add elements to the window
window.push(0.85);
window.push(0.82);
// Get statistics
let mean = window.mean();
let variance = window.variance();
println!("Window mean: {:.3}, variance: {:.3}", mean, variance);ADWIN automatically grows the window when no change is detected and shrinks it when change is detected.
use neural_drift::detectors::AdwinDetector;
// Create detector with custom confidence level
let mut detector = AdwinDetector::new(0.001)?; // Higher confidence = less sensitive
// Process data points
for value in data_stream {
if detector.add_element(value)? {
println!("Distribution change detected at element {}", detector.total_elements());
}
}Add this to your Cargo.toml:
[dependencies]
neural-drift = "0.1"The library uses a custom error type for handling various failure scenarios:
use neural_drift::error::DriftError;
match detector.add_element(value) {
Ok(drift_detected) => {
if drift_detected {
// Handle drift detection
}
},
Err(DriftError::InvalidConfidence(msg)) => {
eprintln!("Configuration error: {}", msg);
},
Err(DriftError::ComputationError(msg)) => {
eprintln!("Computation failed: {}", msg);
},
}This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.