Talip7/scikit-learn-issues-multilabel huggingface dataset:
TSNE segfaults when numbers turn to NaN

### Describe the bug

When running `TSNE.fit_transform`, if numbers produced during the initialization somehow turned to NaN, it will segfault the process instead of throwing a python exception.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.manifold import TSNE
X = np.ones((10,5))
TSNE(init="pca", perplexity=5).fit_transform(X)
```

### Expected Results

Should not segfault.

### Actual Results

Segfaults.

### Versions

```shell
System:
    python: 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:16:49) [GCC 13.3.0]
executable: /home/david/miniforge3/bin/python
   machine: Linux-6.12.57+deb12-amd64-x86_64-with-glibc2.36

Python dependencies:
      sklearn: 1.7.1
          pip: 24.2
   setuptools: 74.1.2
        numpy: 2.0.1
        scipy: 1.14.1
       Cython: 3.1.0
       pandas: 2.2.3
   matplotlib: 3.9.2
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 20
         prefix: libscipy_openblas
       filepath: /home/david/.local/lib/python3.12/site-packages/numpy.libs/libscipy_openblas64_-99b71e71.so
        version: 0.3.27
threading_layer: pthreads
   architecture: Haswell

       user_api: blas
   internal_api: mkl
    num_threads: 14
         prefix: libmkl_rt
       filepath: /home/david/miniforge3/lib/libmkl_rt.so.2
        version: 2023.2-Product
threading_layer: gnu

       user_api: openmp
   internal_api: openmp
    num_threads: 20
         prefix: libgomp
       filepath: /home/david/miniforge3/lib/libgomp.so.1.0.0
        version: None
```

COMMENT:
Yes, seems to be the same underlying issue.

Labels: Bug, Needs Triage
Address sanitizer

> [!WARNING]
> This is not a good first issue to contribute. Great if you are interested to contribute to scikit-learn 🙏. Please have a look at our [contributing doc](https://scikit-learn.org/dev/developers/contributing.html) and in particular the section [Issues for new contributors](https://scikit-learn.org/dev/developers/contributing.html#new-contributors). 

### Describe the workflow you want to enable

This was discussed a little on issue https://github.com/scikit-learn/scikit-learn/issues/32491 and I wanted to give a bit of context about how to do it (unfortunately I don't think I know your CI workflow well enough to do it myself).

Essentially, address sanitizer is a compiler option which looks for out of bounds reads and writes so should catch errors like reading beyond the end of an array. It slows things down so you definitely don't want to distribute wheels with it enabled, but it may help with testing. It only works if you actually exercise the code so you'll want to build and run the tests. It's probably easiest to do on Linux and with just one Python version - there's likely little benefit to doing it comprehensively.

Undefined behaviour sanitizer is related and can be enabled at the same time. However it probably has less value, and there's some minor bits of undefined behaviour in Cython which you'll have to ignore.

### Describe your proposed solution

Rough outline:

* pick a compiler - `clang` is probably the best but `gcc` or `msvc` will work if you have strong preferences.
* Compile and link with `-fsanitize=address` as a command-line option.
* Run the tests with `ASAN_OPTIONS=detect_leaks=0` set as an environmental variable - Cython definitely doesn't clean everything up on exit so you'll get lots of fairly useless false positives.
* You may need `LD_PRELOAD=$(gcc --print-file-name=libasan.so)` as an environmental variable too.
* Dependency: I don't think it's strictly necessary to build all your dependencies with address sanitizer, however:
   * if you're linking to C++ libraries that use `std::string` and `std::vector` then it's a good idea to build them with it too (otherwise you have to manually disable some checks).
   * I imagine you're doing a lot of your memory allocation in Numpy? In which case it'd probably be a good idea to build Numpy with it too. I'm not the right person to advise on that.

Hopefully that makes some sense - feel ping me if it doesn't work, or close if it isn't something you want to do.


### Additional context

[Numpy doc](https://numpy.org/devdocs/dev/development_advanced_debugging.html#compiler-sanitizers) about compiler sanitizers

[Numpy CI workflow](https://github.com/numpy/numpy/blob/main/.github/workflows/compiler_sanitizers.yml)

COMMENT:
Hi @da-woods ,
I would like to contribute

Labels: Build / CI
⚠️ CI failed on Ubuntu_Jammy_Jellyfish.pymin_conda_forge_openblas_ubuntu_2204 (last failure: Nov 23, 2025) ⚠️

**CI failed on [Ubuntu_Jammy_Jellyfish.pymin_conda_forge_openblas_ubuntu_2204](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=82693&view=logs&j=f71949a9-f9d9-549e-cf45-2e99c7b412d1)** (Nov 23, 2025)
- test_mcd[46]

COMMENT:
## CI is no longer failing! ✅

[Successful run](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=82890&view=logs&j=f71949a9-f9d9-549e-cf45-2e99c7b412d1) on Nov 27, 2025

Labels: Needs Triage
⚠️ CI failed on Ubuntu_Jammy_Jellyfish.pymin_conda_forge_openblas_ubuntu_2204 (last failure: Nov 23, 2025) ⚠️

**CI failed on [Ubuntu_Jammy_Jellyfish.pymin_conda_forge_openblas_ubuntu_2204](https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=82693&view=logs&j=f71949a9-f9d9-549e-cf45-2e99c7b412d1)** (Nov 23, 2025)
- test_mcd[46]

COMMENT:
November 23 failure has been observed in other builds will probably be fixed by one of @cakedev0's [PRs](https://github.com/scikit-learn/scikit-learn/pulls?q=sort%3Aupdated-desc+is%3Apr+is%3Aopen+author%3Acakedev0)
```
FAILED covariance/tests/test_robust_covariance.py::test_mcd[46] - assert np.int64(74) >= 75
```

Labels: Needs Triage
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
I think you can get the same result by changing `priors` parameter, because it is by definition prior class weight

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
@glevv 

You're right that priors and class_weight have overlapping functionality for reweighting classes. However, there are important differences:

User Intent: priors represents domain knowledge about true class distribution, while class_weight represents a training procedure choice for handling imbalance. Conceptually distinct.

API Consistency: As I said in the feature request all other sklearn classifiers use class_weight except naive bayes models which can be confusing.

Automatic Balancing: class_weight='balanced' automatically computes appropriate weights, while manually setting priors requires the user to calculate the right values.

Interaction with sample_weight: class_weight naturally combines with sample_weight (multiplicative), giving users flexible control.

Parameter Estimation: While subtle, class_weight affects likelihood parameter estimation (weighted means/variances), not just the prior

That said, you're correct that for many practical cases, carefully chosen priors can achieve similar decision boundaries.But it can be extremely tedious for a beginner to do so.

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
AI-generated comments are in clear violation of the Code of Conduct of [scikit-learn](https://github.com/scikit-learn/scikit-learn/blob/main/CODE_OF_CONDUCT.md).

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
@glevv I am not a native english speaker, I used AI to explain my point, I am sorry about that if it is violating any code of conduct of scikit-learn repo. I am a active contributor in tensorflow repo and just wanted to contribute to scikit learn. Once again I am really sorry if any code of conduct was violated.

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
Closing as AI spam.

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
Change "close as completed" to "close as not planned" for the stats.

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
We've re-evaluated this with @StefanieSenger , and concluded this as not a "spam".

We're somewhat flooded with AI junk these days, and that's why sometimes posts get flagged as false positive.

Your issue is valid, and might be easy to implement (it's not always easy).

We can't promise a high priority review if you open a PR, but having the PR would help assessing the complexity of the implementation. So your contribution here is very much welcome @Aaraviitkgp

Labels: New Feature
Add class_weight support to Naive Bayes models (GaussianNB, MultinomialNB, BernoulliNB)

### Describe the workflow you want to enable

Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) currently do not support the class_weight parameter, while almost all other scikit-learn classifiers do. This creates API inconsistency and requires users to manually compute and pass sample_weight for imbalanced datasets.

# Current Workaround

```py
from sklearn.naive_bayes import GaussianNB
from sklearn.utils.class_weight import compute_sample_weight
sample_weight = compute_sample_weight('balanced', y)
gnb = GaussianNB()
gnb.fit(X, y, sample_weight=sample_weight)
```

# Proposed Enhancement

```py
gnb = GaussianNB(class_weight='balanced')
gnb.fit(X, y)
```


### Describe your proposed solution

Add a class_weight parameter to all Naive Bayes classifiers that internally converts class weights to sample weights before calling the existing fit() logic. This leverages the fact that all NB classifiers already support sample_weight in their fitting methods.

```py
class GaussianNB(_BaseNB):
    _parameter_constraints: dict = {
        "priors": ["array-like", None],
        "var_smoothing": [Interval(Real, 0, None, closed="left")],
        "class_weight": ["dict", "balanced", None],  # NEW
    }

    def __init__(self, *, priors=None, var_smoothing=1e-9, class_weight=None):
        self.priors = priors
        self.var_smoothing = var_smoothing
-->  self.class_weight = class_weight 
```


### Describe alternatives you've considered, if relevant

_No response_

### Additional context

This is a improvement for API consistency. While the workaround exists, having uniform behavior across classifiers reduces confusion and improves discoverability, especially for beginners.

COMMENT:
I'm very sorry @Aaraviitkgp, I had wrongly assumed your initial issue was purely AI generated (since we had had similar "add class_weight" issues in the past). Your contribution is very welcome here.

Labels: New Feature