Skip to content

A Rust library for detecting and measuring concept drift in machine learning model predictions over time

Notifications You must be signed in to change notification settings

not-manuu/neural-drift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Neural Drift

A Rust library for detecting and measuring concept drift in machine learning model predictions over time.

Crates.io Documentation License: MIT

Features

  • 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

Quick Start

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!");
    }
}

Sliding Window Analysis

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);

Supported Algorithms

ADWIN (Adaptive Windowing)

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());
    }
}

Installation

Add this to your Cargo.toml:

[dependencies]
neural-drift = "0.1"

Error Handling

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);
    },
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

A Rust library for detecting and measuring concept drift in machine learning model predictions over time

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages