multilabel_metrics_fn crashes when a thresholded metric comes after "ddi" in the metrics list
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- numpy, python, scikit-learn
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 803
- Merge trung bình
- 4 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 58
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sunlabuiuc/PyHealth
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
sunlabuiuc/PyHealth#1357 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
sunlabuiuc/PyHealth#1346 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
sunlabuiuc/PyHealth#1297 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
sunlabuiuc/PyHealth#1295 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
sunlabuiuc/PyHealth#1294 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của sunlabuiuc/PyHealth
Issue tương tự
-
area:scripts area:tests bug priority:later
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Ikalus1988/MisakaNet#4358 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Discovered ports from service discovery are never propagated to modules in Module.load()Có thể đã có người làm @vishalmore90 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OWASP/Nettacker#1828 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
aws-samples/sample-per-model-bedrock#708 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
[Performance] Bound resolve_api_hashes raw fallback reads to the 1 MiB region actually scannedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sjkim1127/Reversecore_MCP#365 ·
Maintainer thường phản hồi trong vòng 1 ngày