Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNo
inline_dataNo
n_componentsNo

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.2.0

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With zero annotations provided, the description carries the full disclosure burden and meets it thoroughly. It reveals data filtering (numeric columns auto-excluded), preprocessing (StandardScaler), the non-randomness caveat (random_state=42 is interface consistency only), the exact loading de-standardization formula (component vector × feature std dev), the plot placement (__image__ top level), error behavior (out-of-bounds n_components yields Chinese error), and the interpretive guardrail that principal components are not business factors. This is exemplary transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but earns its length: sections for parameters, methodology (口径), example, and inline data are clearly delineated and scannable. The purpose is front-loaded in the first line. Minor deductions for the meta sentence about docstring maintenance synced with design docs and the '工具 15' organizational label, which are contextually useful but not strictly behavioral information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 3-parameter tool with no output schema and no annotations, the description covers inputs, constraints, preprocessing, computation, outputs (variance rates, cumulative, loadings, plot), and caveats. It is slightly incomplete in not specifying the exact return structure (e.g., field names of the result object beyond the plot key), and it defers scale limits and type-domain details to SPEC.md section 12 rather than stating them inline. Still, an agent has nearly everything needed to call and interpret the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must fully compensate, and it does for all three parameters. file_path gains supported formats (csv/tsv/xlsx/json); n_components gains the bound 1 <= n <= min(samples, features) plus error behavior; inline_data gains the two accepted shapes (records array or {header, rows} object), the v1.2.0+ version gate, and exclusivity with file_path. Every parameter receives meaning far beyond the bare string/integer/array types in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with '主成分分析' (Principal Component Analysis) and then specifies the exact pipeline: numeric-only columns, StandardScaler standardization, sklearn PCA, variance-explained and cumulative outputs, de-standardized loadings, and a loading plot. This is a specific verb+resource with distinct methodology that clearly separates it from statistical-test siblings like t-test, anova_test, and cluster_analysis. The '建模组 · 核心实现' framing also situates it within the modeling workflow.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage context is implied rather than stated: the tool is for PCA in the modeling group, and a concrete example (pca_analysis("samples/clean.csv", n_components=2)) demonstrates invocation. The inline_data vs file_path mutual exclusivity is documented. However, no explicit when-to-use guidance or named alternatives among the 29 sibling statistical tools is provided; an agent must infer when PCA is preferred over correlation_matrix, cluster_analysis, or factor-oriented analyses.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/good-boy4069/statlab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server