Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GaussianMixture sample() ValueError on Models with 1 Component Fitted on <32 samples #23032

Copy link
Copy link
Closed
@luhlir

Description

@luhlir
Issue body actions

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

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.