Describe the bug
imblearn.metrics.classification_report_imbalanced raises an opaque IndexError: list index out of range when target_names has a different length than the number of classes, whereas the scikit-learn function it mirrors — sklearn.metrics.classification_report — raises a clear, actionable ValueError on the same input.
Steps/Code to Reproduce
from imblearn.metrics import classification_report_imbalanced
from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
classification_report_imbalanced(y_true, y_pred, target_names=["a", "b"])
# -> IndexError: list index out of range
classification_report(y_true, y_pred, target_names=["a", "b"])
# -> ValueError: Number of classes, 3, does not match size of target_names, 2.
# Try specifying the labels parameter
Expected behavior
A clear ValueError matching scikit-learn, e.g. "Number of classes, 3, does not match size of target_names, 2. Try specifying the labels parameter".
Versions
imbalanced-learn 0.15.dev0
scikit-learn 1.9.0
Python 3.12
I'll open a PR with the fix.
Describe the bug
imblearn.metrics.classification_report_imbalancedraises an opaqueIndexError: list index out of rangewhentarget_nameshas a different length than the number of classes, whereas the scikit-learn function it mirrors —sklearn.metrics.classification_report— raises a clear, actionableValueErroron the same input.Steps/Code to Reproduce
Expected behavior
A clear
ValueErrormatching scikit-learn, e.g. "Number of classes, 3, does not match size of target_names, 2. Try specifying the labels parameter".Versions
I'll open a PR with the fix.