let stats = { mean: 0, std: 1, }; export function trainModel(values) { const n = values.length; if (n === 0) return; const mean = values.reduce((a, b) => a + b, 0) / n; const variance = values.reduce((a, b) => a + (b - mean) ** 2, 0) / n; stats.mean = mean; stats.std = Math.sqrt(variance) || 1; console.log("📊 Anomaly model trained", stats); } export function isAnomaly(value) { const z = Math.abs((value - stats.mean) / stats.std); return z > 3; // Z-score threshold }