Skip to content

GaussianMixture returns wrong scores and probabilities for integer X since 1.7 #35583

Description

@un1u3

Introduce yourself

Hello, I am Unique. I use scikit-learn to build machine learning systems and quickly experiment with my ideas. I have contributed to scikit-learn before (#33117, #33118), and I would like to report and fix this too..

Describe the bug and give evidence about its user-facing impact

I ran the same GaussianMixture code on Google Colab (1.6.1) and on my local machine (1.9.1, latest) and got different results for integer data, with no warnings.

on colab

image

on my local machine

on pip version(1.9.1)

image

on dev version (1.10.dev0)
image

The float results are the same in all three. Only the integer results changed.

I found that fit converts X to float, but score_samples, predict and predict_proba don't. For covariance_type= "full", _estimate_log_gaussian_prob then does:

log_prob = xp.empty((n_samples, n_components), dtype=X.dtype, device=device)

with int64 X this is an integer array so, the squared distances written into it are truncated. dtype= X.dtype was added in #30415. This is not an int overflow.

using AI assistance I also ran these checks

  • 1.5.2 and 1.6.1 are correct; 1.7.2, 1.8.0, 1.9.1 and main are not, so it
    looks like a regression.
  • On 200 random integer datasets (on main), predict gave different labels for
    int and float X in 46, and BIC picked a different number of components
    (1 to 4) in 18. So it can change the model a user chooses.
  • BayesianGaussianMixture is affected too.

using the same dtype in those three validate_data calls as in fit should fix it. I would like to open a PR if u agree.

Steps/Code to Reproduce

import numpy as np
import sklearn
from sklearn.mixture import GaussianMixture

rng = np.random.RandomState(0)
X = np.r_[rng.randint(0, 8, (40, 2)), rng.randint(5, 14, (40, 2))]
m = GaussianMixture(n_components=2, random_state=0).fit(X)

print(m.bic(X), m.bic(X.astype(float)))
print(m.score(X), m.score(X.astype(float)))
print(sklearn.__version__)

Expected Results

Integer and float X give the same values:

872.5069400975487 872.5069400975487
-5.151904044475851 -5.151904044475851

Actual Results

839.0390007466375 872.5069400975487
-4.942729423532655 -5.151904044475851
1.9.1

Versions

System:
    python: 3.12.14 (main, Sep 24 2026, 17:57:43) [Clang 22.1.3 ]
executable: ~/Desktop/gmm_bug/.venv/bin/python
   machine: Linux-7.0.0-44-generic-x86_64-with-glibc2.43

Python dependencies:
      sklearn: 1.9.1
          pip: None
   setuptools: None
        numpy: 2.5.5
        scipy: 1.18.1
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.6.0
threadpoolctl: 3.8.0
     narwhals: 2.30.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 12
         prefix: libscipy_openblas
       filepath: ~/Desktop/gmm_bug/.venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-5f890258.so
        version: 0.3.31.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: openblas
    num_threads: 12
         prefix: libscipy_openblas
       filepath: ~/Desktop/gmm_bug/.venv/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-4b78795a.so
        version: 0.3.34.237.2
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 12
         prefix: libgomp
       filepath: ~/Desktop/gmm_bug/.venv/lib/python3.12/site-packages/scikit_learn.libs/libgomp-e985bcbb.so.1.0.0
        version: None

Interest in fixing the bug

Yes, I would like to work on a PR once this is triaged

Possible fix: pass the same dtype to those three validate_data calls in
sklearn/mixture/_base.py. float32 input would stay float32, so the change from
#30415 is kept. I would also add a non-regression test comparing int and float X
for all covariance types, for score_samples, predict and predict_proba.

I will not open a PR before the issue is triaged:)

Activity

  1. added
    Needs Triage
    on Dec 1, 2026
  2. RjyavardhanSingh commented on Dec 2, 2026

    @RjyavardhanSingh

    Hi, I'd like to work on this. Could you assign it to me? I'll open a PR soon.

  3. added
    Needs Investigation
    and removed
    Needs Triage
    on Dec 2, 2026
  4. ogrisel commented on Dec 2, 2026

    @ogrisel
    Member

    @RjyavardhanSingh the original reporter already expressed interest in contributing a fix so please do not attempt to open a PR.

  5. removed
    Needs Investigation
    on Dec 2, 2026
  6. ogrisel commented on Dec 2, 2026

    @ogrisel
    Member

    @un1u3 I confirm the bug and your analysis of the root cause seems valid. Please open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions