Repository navigation
Description
Several of our supervised clustering metrics specify/suggest (??) that the array input should be of type int or integral, e.g.:
pair_confusion_matrix:
scikit-learn/sklearn/metrics/cluster/_supervised.py
Lines 212 to 216 in b0ba8b0
| labels_true : array-like of shape (n_samples,), dtype=integral | |
| Ground truth class labels to be used as a reference. | |
| labels_pred : array-like of shape (n_samples,), dtype=integral | |
| Cluster labels to evaluate. |
rand_score:
scikit-learn/sklearn/metrics/cluster/_supervised.py
Lines 298 to 302 in b0ba8b0
| labels_true : array-like of shape (n_samples,), dtype=integral | |
| Ground truth class labels to be used as a reference. | |
| labels_pred : array-like of shape (n_samples,), dtype=integral | |
| Cluster labels to evaluate. |
mutual_info_score:
scikit-learn/sklearn/metrics/cluster/_supervised.py
Lines 858 to 864 in b0ba8b0
| labels_true : array-like of shape (n_samples,), dtype=integral | |
| A clustering of the data into disjoint subsets, called :math:`U` in | |
| the above formula. | |
| labels_pred : array-like of shape (n_samples,), dtype=integral | |
| A clustering of the data into disjoint subsets, called :math:`V` in | |
| the above formula. |
fowlkes_mallows_score:
scikit-learn/sklearn/metrics/cluster/_supervised.py
Lines 1221 to 1225 in b0ba8b0
| labels_true : array-like of shape (n_samples,), dtype=int | |
| A clustering of the data into disjoint subsets. | |
| labels_pred : array-like of shape (n_samples,), dtype=int | |
| A clustering of the data into disjoint subsets. |
Looking at the code/testing a few - we don't seem to enforce this. I also have not seen specification of dtype of array input much elsewhere in the codebase. Is this dytpe specification needed in the docs?
Edit: I mean is it worth clarifying it is a suggestion and not enforced?
Activity
[-]DOC Supervised clustering metrics input dytpe specification[/-][+]DOC Supervised clustering metrics specify array input dtype[/+]rustamali9183 commentedon Dec 23, 2025
Othman-vram commentedon Dec 25, 2025
Othman-vram commentedon Dec 25, 2025
akhilkumar-dot commentedon Dec 25, 2025
StefanieSenger commentedon Dec 29, 2025
Some of the clustering metrics raise a warning if the input type is continuous:
scikit-learn/sklearn/metrics/cluster/_supervised.py
Lines 63 to 69 in b0ba8b0
It was added in #17911. (I am wondering why we would only warn and not error here though.)
Since we expect integers, I think it is consistent to mention this in the docs, but then the code needs to comply to this.
Is it, that there were only warnings, or did those you had tested not even warn? I would expect an error here and I wonder if we should error instead of warn.
It would be an interesting next step to check all the clustering metrics from this module and see if all that should raise a warning actually use
check_clusterings()internally. It is probably an easy issue to work on, but not an issue for a first time contributor. Do we know someone with a bit of experience in the repo who'd be happy to take care of this?lucyleeow commentedon Dec 30, 2025
Good point I didn't look into that part. However, discrete vs continuous does not seem to depend on dtype. e.g.:
(I checked that dtype of
np.array([1.0, 1.0, 0.0, 0.0])is float64)And I just checked with the docstring example, changing the input to float instead of int, and no warning or error for e.g.,
rand_score:Ravichandranayakar commentedon Dec 30, 2025
hi i investigated this issue locally by testing int , str and float inputs
i also tested "discrete floats" (like 0.0 and 1.0) to see if the warning is based on type or value
here are the results for all 4 metrics
this proves that the functions actually check if the values are discrete not strictly if the dtype is int
so the documentation requirement for
dtype=integralis definitely too stricti would be happy to update the docstrings to clarify that discrete labels (including strings) are valid inputs
StefanieSenger commentedon Dec 31, 2025
Yes, that's true. Providing discrete floats works and doesn't trigger the warning. And the params that are documented to hold the int dtype are actually all starting on "label...", which suggests discreteness.
Now thinking about this, I would go with the suggestion of removing the dtype specification from the docs, without adding any other information constraints on the labels.
This now seems to me as a separate issue, but since we talked about it in here:
Concerning the warning, I was thinking that it was chosen to warn and not to error to keep the code executable, since
type_of_targetis not precise.Do you think that using
type_of_targetis the right choice to be used incheck_clusterings? Actually, we only need to check if the inputs are convertible into ints.check_arraycan do that, I think. In this case, we could even error instead of to warn, because check_array can give us a precise answer.Ravichandranayakar commentedon Jan 1, 2026
Thank you @StefanieSenger.
I agree that the warning/error logic in
check_clusteringsis a separate architectural discussion.Since there is consensus on the documentation part removing the
dtypespecification , I am happy to proceed with only that adjustment to solve this particular issue.@lucyleeow My previous PR was only for the docs. Do you want me to reopen that one, or create a new PR.
manshirahangdale commentedon Jan 14, 2026