Die Oberfläche ist lokalisiert; Skill-Beschreibungen und -Dokumente werden per KI automatisch in Ihre Sprache übersetzt. Code, Befehle, Pfade und Fachbegriffe bleiben im Original, maßgeblich ist das Dokument des Autors.
Skills entdecken
Produktivität · SKILL.md

outlier-scan

outlier-scan

CSV数据异常检测工具,使用Z-score、IQR(四分位距)、移动平均偏离三种方法进行扫描,并自动将检测到的异常点分类为「可解释」或「需关注」,输出详细的JSON报告。当用户需要异常检测、离群值排查或数据质量巡检,提及outlier detection、Z-score、IQR、移动平均偏离等关键词或直接上传CSV文件时触发。

Independent GitHub snapshot · Automated classification · Original documentation governs

Skill-Dokumentation

GitHub

name: outlier-scan description: "CSV数据异常检测工具,使用Z-score、IQR(四分位距)、移动平均偏离三种方法进行扫描,并自动将检测到的异常点分类为「可解释」或「需关注」,输出详细的JSON报告。当用户需要异常检测、离群值排查或数据质量巡检,提及outlier detection、Z-score、IQR、移动平均偏离等关键词或直接上传CSV文件时触发。" license: MIT

anomaly-detector

多方法异常检测工具,支持 Z-score、IQR(四分位距)、移动平均偏离三种检测方法,对检测到的异常自动分类标注为「可解释」或「需关注」。

能力概览

能力说明
Z-score 检测基于标准差偏离程度识别异常,适合近似正态分布数据
IQR 检测基于四分位距识别异常,对偏态分布更稳健
移动平均偏离基于滑动窗口均值偏离识别异常,适合时序数据
异常分类综合多方法结果,将异常标注为「可解释」或「需关注」

Quick Start

# 使用全部方法检测
python3 scripts/anomaly_detector.py data.csv

# 指定方法和列
python3 scripts/anomaly_detector.py data.csv --methods z-score,iqr --columns price,volume

# 自定义阈值,输出到文件
python3 scripts/anomaly_detector.py data.csv --z-threshold 2.5 --window 7 --output result.json

参数说明

参数类型默认值说明
csv_file位置参数(必填)输入 CSV 文件路径
--methods字符串z-score,iqr,moving-avg逗号分隔的检测方法
--columns字符串全部数值列逗号分隔的目标列名
--z-threshold浮点数3.0Z-score 判定阈值
--iqr-multiplier浮点数1.5IQR 倍数(1.5=普通异常, 3.0=极端异常)
--window整数5移动平均窗口大小
--ma-threshold浮点数2.0移动平均偏离阈值(标准差倍数)
--output字符串stdout输出文件路径(JSON 格式)

异常分类规则

脚本会综合所有方法的检测结果,对每个异常点进行分类:

需关注(needs_attention):满足以下任一条件

  • 被 2 种及以上方法同时检出
  • Z-score 绝对值 > 阈值 × 1.5(极端偏离)
  • IQR 偏离超过 3 倍 IQR(极端离群)

可解释(explainable):不满足上述条件的异常

  • 仅被 1 种方法检出
  • 偏离程度温和,可能是正常波动

输出结构

{
  "summary": {
    "total_rows": 100,
    "columns_analyzed": ["price", "volume"],
    "methods_used": ["z-score", "iqr", "moving-avg"],
    "total_anomalies": 8,
    "needs_attention": 3,
    "explainable": 5
  },
  "anomalies": [
    {
      "row": 42,
      "column": "price",
      "value": 999.9,
      "methods_detected": ["z-score", "iqr"],
      "details": {
        "z_score": 4.2,
        "iqr_bounds": [10.0, 50.0]
      },
      "classification": "needs_attention",
      "reason": "被 2 种方法同时检出,Z-score=4.2 远超阈值"
    }
  ],
  "column_stats": {
    "price": {
      "mean": 25.3,
      "std": 5.1,
      "q1": 21.0,
      "q3": 29.5,
      "iqr": 8.5,
      "anomaly_count": 5
    }
  }
}

使用指南

  1. 准备数据:CSV 文件需包含表头行,数值列会被自动识别
  2. 选择方法:
    • 数据近似正态分布 → 优先使用 z-score
    • 数据有偏态或不确定分布 → 优先使用 iqr
    • 时序数据关注趋势偏离 → 使用 moving-avg
    • 不确定时使用全部方法(默认),综合判断更可靠
  3. 解读结果:优先关注 needs_attention 类异常,explainable 类可作为参考

依赖

仅使用 Python 标准库,无需额外安装:

  • csv — CSV 文件读取
  • json — JSON 输出
  • math — 数学计算
  • statistics — 统计函数
Gespeicherte Skills