pca_analysis
Reduce dataset dimensionality by extracting principal components from numeric columns, returning variance explained, component loadings, and visualizations.
Instructions
pca_analysis —— 建模组 · 主成分分析(工具 15,核心实现)。
docstring = agent 使用说明书,与 statlab_mcp/docs/design/05_modeling.md 同步维护。
参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) n_components (int): 主成分数,1 <= n <= min(样本数, 特征数)(超界中文报错)
口径: 仅数值列(自动排除列出);StandardScaler 标准化后 sklearn PCA(random_state=42, PCA 本身无随机性,仅为接口一致);输出方差解释率+累积; 载荷反标准化 = 成分向量 × 特征标准差(原单位近似权重,规格要求); 载荷图(方差解释条形 + 前两主成分载荷向量,image 顶层); 结论注明"主成分是特征的线性组合,不等于业务因子"。
示例: pca_analysis("samples/clean.csv", n_components=2) inline 数据: 本工具支持可选 inline_data 参数(v1.2.0 起):与 file_path 二选一, 支持 records 数组或 {"header": [...], "rows": [[...], ...]} 对象两种形态; 规模上限/类型域/data_source 来源标注见 statlab_mcp/docs/SPEC.md 第 12 节。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | No | ||
| inline_data | No | ||
| n_components | No |