logistic_regression
Fit and evaluate a binary classifier using stratified train/test split and balanced class handling, outputting ROC-AUC, confusion matrix, and odds ratios with p-values.
Instructions
logistic_regression —— 建模组 · 逻辑回归(工具 13,核心实现)。
docstring = agent 使用说明书,与 statlab_mcp/docs/design/05_modeling.md 同步维护。
参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) target (str): 二分类目标列(恰好 2 类;类名映射为 0/1 输出 label_mapping) features (list[str]): 数值特征(本工具不做 one-hot,规格未要求;非数值报错) test_size (float, 0.3): train/test 分层划分比例 ∈(0,1) random_state (int, 42): 划分与复制的固定随机种子 class_weight (str, "balanced"): balanced 用少数类确定性复制实现(statsmodels Logit 无内置类权重,如实披露;复制样本 w=n/(2*n_class) 于训练集内,seed 固定)
固定五项输出(规格硬性): 类别分布 / accuracy(仅对照,受类别不平衡影响)/ 混淆矩阵 / ROC-AUC+95%CI (Hanley-McNeil 正态近似)/ 特征 OR 与 p 值(statsmodels Logit 矩阵接口, OR=exp(beta))。ConvergenceWarning(完美可分)-> convergence_warning 注明系数不稳定。
示例: logistic_regression("tests/fixtures/binary_noisy.csv", target="label", features=["score"]) 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 |
|---|---|---|---|
| target | No | ||
| features | No | ||
| file_path | No | ||
| test_size | No | ||
| inline_data | No | ||
| class_weight | No | balanced | |
| random_state | No |