feature_importance
Rank predictor contributions with permutation or impurity-based importance from a random forest, using a target column to identify key drivers in classification or regression.
Instructions
feature_importance —— 建模组 · 特征重要性(工具 16,核心实现)。
docstring = agent 使用说明书,与 statlab_mcp/docs/design/05_modeling.md 同步维护。
参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) target (str): 目标列(<=20 类 -> 分类随机森林 class_weight=balanced;连续 -> 回归森林) method (str, "permutation"): permutation(打乱验证集特征,验证集思想)/ impurity(训练集内基尼/方差减少;两者都输出,默认 permutation) n_estimators (int, 200): 森林树数 >=10 random_state (int, 42): 森林与划分固定种子 n_repeats (int, 10): permutation 专用,打乱次数 >=1
硬性门槛: n < 50 拒绝(规格);特征重要性排序 + "重要性≠因果"尾注。
第 4.1 条实现(确定性): train_test_split(0.25, random_state) 划分;模型在训练集拟合;impurity 取 feature_importances_;permutation 在测试集上打乱(sklearn.inspection.permutation_importance)。
示例: feature_importance("samples/clean.csv", target="income") 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 |
|---|---|---|---|
| method | No | permutation | |
| target | No | ||
| file_path | No | ||
| n_repeats | No | ||
| inline_data | No | ||
| n_estimators | No | ||
| random_state | No |