Description
Describe the bug
If you fit a GaussianMixture model with one component on less than 32 samples, a ValueError is thrown when trying to generate a random sample from the model. If you use a model with more than one component, you are able to fit it on as low as two samples and still generate a random sample from the model. Likewise, no ValueError is thrown if you use 32 samples to fit a model with one component.
Steps/Code to Reproduce
https://gist.github.com/luhlir/8db41552d086ecaa441bb534312bfeb4
Expected Results
No error is thrown
Actual Results
This is the ValueError produced
Traceback (most recent call last):
File "gaussian_mixture_bug.py", line 17, in
print(c.sample()) # This will throw a ValueError
File "./lib/python3.9/site-packages/sklearn/mixture/base.py", line 438, in sample
n_samples_comp = rng.multinomial(n_samples, self.weights)
File "mtrand.pyx", line 4249, in numpy.random.mtrand.RandomState.multinomial
File "_common.pyx", line 376, in numpy.random._common.check_array_constraint
File "_common.pyx", line 362, in numpy.random._common._check_array_cons_bounded_0_1
ValueError: pvals < 0, pvals > 1 or pvals contains NaNs
Versions
System:
python: 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:14:58) [Clang 12.0.5 (clang-1205.0.22.9)]
machine: macOS-12.2.1-x86_64-i386-64bit
Python dependencies:
pip: 21.3.1
setuptools: 57.0.0
sklearn: 1.0.2
numpy: 1.22.1
scipy: 1.8.0
Cython: None
pandas: None
matplotlib: None
joblib: 1.1.0
threadpoolctl: 3.1.0
Built with OpenMP: True