multilabel_metrics_fn crashes when a thresholded metric comes after "ddi" in the metrics list
维护者通常 3 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- numpy, python, scikit-learn
调研方向
Start with multilabel_metrics_fn in pyhealth.metrics.multilabel, especially the ddi branch and the metrics loop; the report includes a reproduction script and expected results. Check the existing tests for this function, then verify that reversing metric order produces the same scores and that the documented threshold default and example output match the function. A pull request is already open for this issue.
由索引模型根据 Issue 内容生成。
描述
Where "ddi" sits in the metrics list changes whether multilabel_metrics_fn returns at all. If a metric that reads the thresholded predictions comes after it, the call raises instead of returning scores.
This lands on drug recommendation, where the DDI rate is the headline safety number, so listing it first is the natural way to write the call. Trainer hands the list to the metrics function untouched, so Trainer(metrics=["ddi", "jaccard_samples", "f1_samples"]) fails inside evaluate(). The function's own docstring lists the accepted names with ddi ahead of hamming_loss, and that order fails too.
Steps to reproduce
On b96c3f5, with python 3.13.15, scikit-learn 1.7.2 and numpy 2.2.6:
import os
import tempfile
from unittest.mock import patch
import numpy as np
from pyhealth.metrics import multilabel_metrics_fn
y_true = np.array([[1, 0, 1], [0, 1, 1], [1, 1, 0], [0, 0, 1]])
y_prob = np.array(
[[0.9, 0.4, 0.8], [0.2, 0.7, 0.6], [0.8, 0.9, 0.1], [0.1, 0.2, 0.7]]
)
tmp = tempfile.mkdtemp()
np.save(
os.path.join(tmp, "ddi_adj.npy"),
np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]], dtype=float),
)
with patch("pyhealth.metrics.multilabel.CACHE_PATH", tmp):
print(multilabel_metrics_fn(y_true, y_prob, metrics=["jaccard_samples", "ddi"]))
print(multilabel_metrics_fn(y_true, y_prob, metrics=["ddi", "jaccard_samples"]))
What I get
{'jaccard_samples': 0.9166666666666666, 'ddi_score': 0.4}
ValueError: Classification metrics can't handle a mix of multilabel-indicator and unknown targets
What I expected
Both lines print the same numbers, ddi_score 0.4 and jaccard_samples 0.9166666666666666. The position of a metric in the list should not change the result.
Notes
The "ddi" branch turns the thresholded y_pred matrix into a list of label indices and assigns it back to y_pred, so the next metric in the loop is handed a ragged list. f1_*, precision_*, recall_*, jaccard_* and hamming_loss all raise the ValueError above. accuracy raises AttributeError: 'list' object has no attribute 'flatten'. Metrics that read y_prob only still work, so metrics=["ddi", "pr_auc_samples"] returns {'ddi_score': 0.4, 'pr_auc_samples': 1.0}.
The error text names neither ddi nor y_pred, so there's nothing in it that points at the list order.
Two smaller docstring mistakes in the same function: the signature is threshold: float = 0.3 while the Args block says Default is 0.5, and the Examples block shows {'accuracy': 0.5} where the function returns {'accuracy': 0.6666666666666666}.
I have a fix and can open a PR.
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 803
- 平均合并
- 5 天 16 小时
- 30 天内合并 PR
- 58
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sunlabuiuc/PyHealth 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
sunlabuiuc/PyHealth#1346 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 30/100
sunlabuiuc/PyHealth#1297 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 22/100
sunlabuiuc/PyHealth#1295 · 1 条评论 ·
维护者通常 3 天内回复
-
难度 3/5 1-2 天 新手友好度 42/100
sunlabuiuc/PyHealth#1294 · 1 条评论 ·
维护者通常 3 天内回复
-
Internal transfers are counted as readmissions可能已有人在做 @thebean27 于 22 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
sunlabuiuc/PyHealth#1269 · 3 条评论 ·
维护者通常 3 天内回复
查看 sunlabuiuc/PyHealth 的全部 Issue
相似的 Issue
-
test-failure
难度 2/5 1-3 小时 新手友好度 72/100
teramoby/speedle-plus#129 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
btclib-org/btclib-ecc#404 ·
-
verify: just verify runs tools/verify_agents_imports.py (the recipe line was only read, not run)未关闭needs-verification
难度 1/5 1 小时以内 新手友好度 76/100
EchoTools/nevr-runtime#1322 ·
维护者通常 1 天内回复
-
changelog investigate
难度 1/5 1 小时以内 新手友好度 78/100
ramnes/notion-sdk-py#430 ·
-
bug good first issue
难度 1/5 1 小时以内 新手友好度 91/100
hyeonjoong/debussy#56 ·