Skip to main content

Crate driftwatch

Crate driftwatch 

Source
Expand description

driftwatch — data & model drift detection for Rust.

driftwatch computes how far a live data or prediction distribution has moved from a trusted reference (training/baseline) distribution, and lets you alert on it. It provides the metrics named in the Rust ML ecosystem gap that Evidently/WhyLabs fill in Python — but no equivalent existed in Rust:

§What this crate is not

It does not render HTML reports or a dashboard UI (pair DriftReport’s structured data with plotters-statistical for charts), it does not do general data-quality profiling beyond drift, and it recomputes drift over discrete windows/snapshots rather than as a continuously-updated online statistic. See the README for the full comparison against Evidently/WhyLabs.

§Quick start

use driftwatch::{DatasetMonitor, ReferenceDistribution, EqualFrequencyBinning, LiveFeature};

// Fit a reference distribution per feature from baseline data.
let baseline: Vec<f64> = (0..200).map(|i| i as f64 / 200.0).collect();
let reference = ReferenceDistribution::fit_continuous(
    "score",
    &baseline,
    EqualFrequencyBinning::new(10).unwrap(),
)
.unwrap();

let mut monitor = DatasetMonitor::new();
monitor.add_feature(reference);

// Check a live batch that has shifted upward.
let live: Vec<f64> = (0..200).map(|i| 0.5 + i as f64 / 200.0).collect();
let report = monitor.check(&[("score", LiveFeature::Continuous(&live))]).unwrap();
println!("{report}");
assert!(report.dataset_drift_detected());

Re-exports§

pub use binning::BinDefinition;
pub use binning::ContinuousBinning;
pub use binning::EqualFrequencyBinning;
pub use binning::EqualWidthBinning;
pub use binning::Histogram;
pub use binning::DEFAULT_BIN_COUNT;
pub use distribution::FeatureKind;
pub use distribution::LiveFeature;
pub use distribution::ReferenceDistribution;
pub use error::DriftError;
pub use error::Result;
pub use metrics::chi_square_test;
pub use metrics::js_divergence;
pub use metrics::kl_divergence;
pub use metrics::ks_test;
pub use metrics::psi;
pub use metrics::ChiSquareResult;
pub use metrics::KsTestResult;
pub use metrics::DEFAULT_EPSILON;
pub use monitor::DatasetMonitor;
pub use monitor::DriftReport;
pub use monitor::DriftVerdict;
pub use monitor::FeatureConfig;
pub use monitor::FeatureDrift;
pub use monitor::LiveWindow;
pub use monitor::MetricKind;
pub use monitor::MetricScore;
pub use monitor::PredictionDriftMonitor;
pub use monitor::WindowMode;
pub use monitor::LabelDriftMonitor;
pub use monitor::LabelDriftReport;
pub use dashboard::Dashboard;
pub use streaming::OnlineDistribution;
pub use streaming::PageHinkleyChange;
pub use streaming::PageHinkleyDetector;
pub use streaming::StreamingMonitor;
pub use streaming::StreamingReport;
pub use profile::CategoricalProfile;
pub use profile::ContinuousProfile;
pub use profile::DatasetProfile;
pub use profile::FeatureProfile;
pub use profile::Schema;
pub use profile::ValidationIssue;
pub use profile::ValidationReport;
pub use report::HtmlReport;
pub use alert::Alerter;
pub use alert::DriftAlertEvent;
pub use alert::NopAlerter;
pub use alert::LogAlerter;
pub use alert::WebhookAlerter;

Modules§

alert
Pluggable alerting on drift detection.
binning
Binning: turning raw feature samples into comparable discretized distributions.
dashboard
A live, auto-refreshing drift dashboard (feature dashboard).
distribution
Per-feature reference distributions and the live data compared against them.
error
Error types for the crate.
export
Prometheus / metrics export (feature prometheus-export).
metrics
Drift metrics.
monitor
Orchestration: turning per-feature reference distributions into a dataset-level DriftReport, plus the LiveWindow buffer that feeds a monitor from a running service.
profile
Data-quality profiling and schema validation.
report
Static, self-contained HTML drift reports.
streaming
Continuously-updated online drift (feature streaming).