Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

multilabel_metrics_fn crashes when a thresholded metric comes after "ddi" in the metrics list

Cerrado
#1,242 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@Om-singhaI ya está trabajando en esto.

Desde el 22/9/2026.

  • #1243 de @Om-singhaI — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
numpy, python, scikit-learn

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.7k
Forks
803
Merge medio
5 d 16 h
PR fusionados (30 d)
58

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sunlabuiuc/PyHealth

Todos los issues de sunlabuiuc/PyHealth

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.