用途:面向数据工程师和分析师,在数据集中检测离群点,提供可直接用于生产的异常检测函数。
主要能力:脚本 scripts/anomaly_detection.py 提供 detect_anomalies_zscore、detect_anomalies_iqr、detect_anomalies_modified_zscore、detect_anomalies_isolation_forest、detect_anomalies_lof、detect_anomalies_rolling、detect_anomalies_stl、detect_anomalies_ensemble 等函数。方法选择:Z-Score 适合正态分布但受离群值影响;IQR 适合偏态分布但整体灵敏度较低;修正 Z-Score 更稳健但计算较慢;Isolation Forest 适合高维数据但需调参;LOF 适合局部密度异常但计算开销大;滚动窗口适合带趋势的时间序列但对窗口大小敏感;STL 适合季节性时间序列但需已知周期。
使用方式:从 scripts.anomaly_detection 导入所需函数,传入 pandas Series 或 DataFrame。单列可用 detect_anomalies_zscore(df['value'], threshold=3.0) 或 detect_anomalies_iqr(df['value'], multiplier=1.5);多列可用 detect_anomalies_isolation_forest(df, numeric_cols, contamination=0.01);集成方法 detect_anomalies_ensemble(df, columns=[...], methods=[...], min_agreement=2) 在多个方法一致时标记异常;时间序列可用 detect_anomalies_rolling(df['daily_sales'], window=7, n_std=2.0) 或 detect_anomalies_stl(df['monthly_revenue'], period=12, threshold=3.0)。
依赖:pandas、numpy、scikit-learn(Isolation Forest、LOF)、statsmodels(STL)。
限制:各方法均有适用条件与局限,如参数敏感、需调参或计算开销较大;具体安装命令、收费与平台信息暂未提供。