一键导入
data-preprocessing
数据清洗、EDA、缺失值处理、异常值检测、相关性分析。触发词: 数据预处理、数据清洗、EDA、缺失值、异常值、data preprocessing、数据探索。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
数据清洗、EDA、缺失值处理、异常值检测、相关性分析。触发词: 数据预处理、数据清洗、EDA、缺失值、异常值、data preprocessing、数据探索。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
模型验证:交叉验证、留出法、残差分析、与已知解对比、假设检验。触发词: 模型验证、交叉验证、残差分析、model validation、留出法、误差分析、假设检验。
多子问题拆解与依赖分析。触发词: 子问题拆解、拆题、problem decomposition、依赖关系、求解顺序、时间分配、并行安排。
灵敏度分析:参数扰动、单因素/多因素分析、Monte Carlo 模拟、龙卷风图/蛛网图。触发词: 灵敏度分析、参数敏感性、sensitivity analysis、Monte Carlo、鲁棒性测试、参数扰动。
自动多轮评审优化循环。通过 Codex MCP 反复评审→修改→重新评审,直到达标或达到最大轮数。当用户说'自动优化循环'、'auto optimize'、'评审到通过'时使用。
Autonomously improve a generated paper via GPT-5.4 xhigh review → implement fixes → recompile, for 2 rounds. Use when user says "改论文", "improve paper", "论文润色循环", "auto improve", or wants to iteratively polish a generated paper.
数模竞赛全流程流水线:赛题分析 → 建模方案 → 代码求解 → 自动优化 → 论文撰写。当用户说'全流程'、'full pipeline'、'从赛题到论文'、'一键建模'时使用。
| name | data-preprocessing |
| description | 数据清洗、EDA、缺失值处理、异常值检测、相关性分析。触发词: 数据预处理、数据清洗、EDA、缺失值、异常值、data preprocessing、数据探索。 |
| argument-hint | ["data-file-or-data-directory"] |
| allowed-tools | Bash(*), Read, Write, Edit, Grep, Glob, Agent, mcp__codex__codex, mcp__codex__codex-reply |
执行描述: $ARGUMENTS
DATA_PREPROCESSING_REPORT.md — 主输出文件,供 model-creator、solve-plan 使用。data/cleaned/ — 清洗后数据的存放目录。figures/eda/ — EDA 图表存放目录。50 — 超过 50 列时只对高相关列做完整画像,其余做摘要。100000 — 超过 10 万行时先采样分析,再对全量数据做统计。0.05 — 缺失率超过 5% 的列必须在报告中标红。0.50 — 缺失率超过 50% 的列建议删除,除非有充分理由保留。3.0 — Z-score 阈值,超过即标记为疑似异常值。1.5 — IQR 方法乘数,与 Z-score 交叉验证。0.85 — 相关系数绝对值超过 0.85 的变量对需要标注多重共线性风险。gpt-5.4 — Codex MCP 交叉验证模型。high — 数据预处理验证使用高推理强度。artifacts/ — 存放中间结构化文件。Input: $ARGUMENTS(文件路径或目录路径)。
Output: 数据成功加载,基础元信息记录到 artifacts/data_profile_raw.json。
$ARGUMENTS 是文件路径,直接读取。$ARGUMENTS 是目录路径,扫描目录下所有 .csv、.xlsx、.xls、.json、.txt 文件。data/、dataset/、附件/、项目根目录。artifacts/data_profile_raw.json。import pandas as pd
from pathlib import Path
import json
import chardet
def detect_encoding(filepath: str) -> str:
with open(filepath, "rb") as f:
raw = f.read(min(100000, Path(filepath).stat().st_size))
result = chardet.detect(raw)
return result.get("encoding", "utf-8") or "utf-8"
def load_data(filepath: str) -> pd.DataFrame:
enc = detect_encoding(filepath)
suffix = Path(filepath).suffix.lower()
if suffix in [".csv", ".txt"]:
for sep in [",", "\t", ";", "|"]:
try:
df = pd.read_csv(filepath, encoding=enc, sep=sep, nrows=5)
if len(df.columns) > 1:
return pd.read_csv(filepath, encoding=enc, sep=sep)
except Exception:
continue
return pd.read_csv(filepath, encoding=enc)
elif suffix in [".xlsx", ".xls"]:
return pd.read_excel(filepath)
elif suffix == ".json":
return pd.read_json(filepath, encoding=enc)
else:
raise ValueError(f"Unsupported file type: {suffix}")
# Example usage
data_files = list(Path("data").glob("*.*"))
profiles = []
for fp in data_files:
try:
df = load_data(str(fp))
profiles.append({
"file": fp.name,
"rows": len(df),
"cols": len(df.columns),
"columns": list(df.columns),
"dtypes": {c: str(df[c].dtype) for c in df.columns},
"size_kb": round(fp.stat().st_size / 1024, 1),
})
except Exception as e:
profiles.append({"file": fp.name, "error": str(e)})
Path("artifacts").mkdir(exist_ok=True)
Path("artifacts/data_profile_raw.json").write_text(
json.dumps(profiles, ensure_ascii=False, indent=2), encoding="utf-8"
)
Input: 已加载的 DataFrame。
Output: artifacts/missing_value_report.json 与缺失值热力图。
MISSING_THRESHOLD_WARN (5%) 的列标记为"需要关注"。MISSING_THRESHOLD_DROP (50%) 的列标记为"建议删除"。figures/eda/missing_heatmap.png。import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns
def analyze_missing(df: pd.DataFrame, fig_dir: str = "figures/eda") -> dict:
missing = df.isnull().sum()
missing_pct = (missing / len(df)).round(4)
report = {
"total_rows": len(df),
"total_cols": len(df.columns),
"columns": {}
}
for col in df.columns:
pct = float(missing_pct[col])
status = "ok"
if pct > 0.50:
status = "suggest_drop"
elif pct > 0.05:
status = "needs_attention"
report["columns"][col] = {
"missing_count": int(missing[col]),
"missing_pct": pct,
"status": status,
"dtype": str(df[col].dtype),
}
Path(fig_dir).mkdir(parents=True, exist_ok=True)
fig, ax = plt.subplots(figsize=(12, max(4, len(df.columns) * 0.3)))
sns.heatmap(df.isnull().T, cbar=True, yticklabels=True, ax=ax, cmap="YlOrRd")
ax.set_title("Missing Value Heatmap")
fig.tight_layout()
fig.savefig(f"{fig_dir}/missing_heatmap.png", dpi=150)
plt.close(fig)
return report
Input: 已加载的 DataFrame(数值列)。
Output: artifacts/outlier_report.json 与箱线图。
figures/eda/boxplots.png。import numpy as np
def detect_outliers(df: pd.DataFrame, z_thresh: float = 3.0, iqr_mult: float = 1.5) -> dict:
report = {}
numeric_cols = df.select_dtypes(include=[np.number]).columns
for col in numeric_cols:
series = df[col].dropna()
if len(series) == 0:
continue
z_scores = np.abs((series - series.mean()) / series.std())
z_outliers = set(series[z_scores > z_thresh].index)
q1, q3 = series.quantile(0.25), series.quantile(0.75)
iqr = q3 - q1
iqr_outliers = set(series[(series < q1 - iqr_mult * iqr) | (series > q3 + iqr_mult * iqr)].index)
strong = z_outliers & iqr_outliers
weak = (z_outliers | iqr_outliers) - strong
report[col] = {
"strong_outliers": len(strong),
"weak_outliers": len(weak),
"strong_pct": round(len(strong) / len(series), 4),
"min": float(series.min()),
"max": float(series.max()),
"mean": float(series.mean()),
"std": float(series.std()),
}
return report
Input: 已加载的 DataFrame。
Output: artifacts/correlation_report.json、分布图、相关性热力图。
CORRELATION_THRESHOLD (0.85) 的变量对标注"多重共线性风险"。figures/eda/correlation_heatmap.png。MAX_COLUMNS_FULL_PROFILE),先筛选高方差和高相关列。def correlation_analysis(df: pd.DataFrame, threshold: float = 0.85, fig_dir: str = "figures/eda") -> dict:
numeric_df = df.select_dtypes(include=[np.number])
pearson = numeric_df.corr(method="pearson")
spearman = numeric_df.corr(method="spearman")
high_corr_pairs = []
cols = pearson.columns
for i in range(len(cols)):
for j in range(i + 1, len(cols)):
r = abs(pearson.iloc[i, j])
if r > threshold:
high_corr_pairs.append({
"var1": cols[i],
"var2": cols[j],
"pearson": round(float(pearson.iloc[i, j]), 4),
"spearman": round(float(spearman.iloc[i, j]), 4),
"risk": "multicollinearity",
})
Path(fig_dir).mkdir(parents=True, exist_ok=True)
fig, ax = plt.subplots(figsize=(max(8, len(cols) * 0.5), max(6, len(cols) * 0.4)))
sns.heatmap(pearson, annot=len(cols) <= 15, fmt=".2f", cmap="RdBu_r", center=0, ax=ax)
ax.set_title("Pearson Correlation Matrix")
fig.tight_layout()
fig.savefig(f"{fig_dir}/correlation_heatmap.png", dpi=150)
plt.close(fig)
return {
"num_numeric_cols": len(cols),
"high_corr_pairs": high_corr_pairs,
"skewness": {c: round(float(numeric_df[c].skew()), 4) for c in cols},
"kurtosis": {c: round(float(numeric_df[c].kurtosis()), 4) for c in cols},
}
Input: Phase 2-4 的分析结果、用户确认的处理决策。
Output: 清洗后数据文件保存到 data/cleaned/。
artifacts/cleaning_log.json,包括:操作、影响行数、影响列、原因。data/cleaned/。scripts/data_cleaning.py,确保可复现。Input: 数据概况、缺失值报告、异常值报告、清洗决策。 Output: 修订建议。
gpt-5.4 与 high 推理强度做独立审查。threadId,后续可追问具体列的处理建议。mcp__codex__codex:
model: gpt-5.4
config: {"model_reasoning_effort": "high"}
prompt: |
你是数学建模竞赛数据分析专家,请审查以下数据预处理方案。
数据概况:
[粘贴数据 profile 摘要]
缺失值分析:
[粘贴缺失值报告摘要]
异常值分析:
[粘贴异常值报告摘要]
清洗决策:
[粘贴清洗决策表]
请逐项回答:
1. 缺失值处理策略是否合理?有没有更好的插补方法?
2. 异常值的判定标准是否合适?是否有误杀或遗漏?
3. 当前的数据清洗是否可能引入偏差或信息损失?
4. 有没有遗漏的数据质量问题(如重复行、单位不一致、时间格式混乱)?
5. 对后续建模有什么数据层面的建议?
将最终结果写入 DATA_PREPROCESSING_REPORT.md。
Output files:
| 路径 | 必需 | 内容 | 说明 |
|---|---|---|---|
DATA_PREPROCESSING_REPORT.md | Yes | 主报告 | 提供给 model-creator 与 solve-plan |
data/cleaned/*.csv | Yes | 清洗后数据 | 供后续建模使用 |
figures/eda/missing_heatmap.png | Recommended | 缺失值热力图 | 可直接用于论文 |
figures/eda/boxplots.png | Recommended | 箱线图矩阵 | 异常值可视化 |
figures/eda/correlation_heatmap.png | Recommended | 相关性热力图 | 可直接用于论文 |
figures/eda/distributions/ | Recommended | 各列分布图 | 支持变量变换决策 |
artifacts/data_profile_raw.json | Recommended | 原始数据概况 | 机器可读元信息 |
artifacts/missing_value_report.json | Recommended | 缺失值报告 | 支持复查 |
artifacts/outlier_report.json | Recommended | 异常值报告 | 支持复查 |
artifacts/correlation_report.json | Recommended | 相关性报告 | 支持变量筛选 |
artifacts/cleaning_log.json | Recommended | 清洗日志 | 确保可追溯 |
scripts/data_cleaning.py | Recommended | 清洗脚本 | 确保可复现 |
cat << 'EOF' > file) to write in chunks. Do NOT ask the user for permission — just do it silently.Open Questions,为下游建模暴露数据层面的不确定性。problem-analysis
-> problem-decomposer
-> data-preprocessing
-> model-creator
-> solve-plan
data-preprocessing
-> model-creator (提供清洗后数据和变量建议)
-> paper-figure (提供 EDA 图表)
-> paper-write (提供数据描述章节素材)