Talip7/scikit-learn-issues-multilabel huggingface dataset:
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:
Hello.I am new at open-source projects and i would like to contribute to this issue.

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 am also new to open source projects and would also like to contribute to this issue. Maybe we could work on this together @DhmhtrhsPakakis. I have started to work on this already, and we could communicate possibly?

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:
@evantakahashi the Naive Bayes classifiers (GaussianNB, MultinomialNB, BernoulliNB, ComplementNB, CategoricalNB) are 5 , maybe i could add the class_weight to 2 or 3 of them and you to the others. In Addition i have found what needs to be changed and i have left the implementation, so if you need help at the idea i could help you.

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:
@DhmhtrhsPakakis  Actually I think that @Aaraviitkgp has submitted a pr already

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:
@DhmhtrhsPakakis @evantakahashi I have already made a pr on this issue, you can look into other issues.

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:
@Aaraviitkgp can you explain the motivations behind the issue?

- do you have a real application use case behind this or is it more of a API consistency thing that you noticed?
- out of curiosity, how did you bump into this limitation?
- is it more than your main motivation is to contribute to scikit-learn? If that's the case, I would suggest you 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).

As far as I am concerned I would guess that Naive Bayes models are not used that much in practice, happy to hear opinions from other maintainers about this!

To set expectations, if Naive Bayes models are not used that much, it's unlikely to be at the top of a maintainer's priority list. This means it's unlikely that a PR addressing this issue will get reviewed, and even less merged.

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:
@lesteve It was more of an api consistency thing I noticed when I started using scikit, it was confusing as all other classification algorithms have it.

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:
@lesteve Well I am a student so I was experimenting on different models for spam detection project, thats when I stumbled on this inconsistency, as for any practical usecase I personally dont think there would be any major usecase.

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:
OK so trying to set expectation here, I would wait for a maintainer to explicitly say something like "I think this is important and I am willing to review your PR to address this issue".

As I said personally, I think this doesn't feel like something that it important enough but other maintainers may have different opinions.

You are more than welcome to keep working on https://github.com/scikit-learn/scikit-learn/pull/32783 as some kind of training to be more familiar with the contributing workflow, but be aware that your PR may never get a review.

Labels: New Feature
DOC: Clarify tie-breaking logic for equivalent splits in decision tree documentation

### Describe the issue linked to the documentation

(IA generated, but read and pruned by a human ^^)

The user guide and API reference for decision trees and extra trees do not currently document what happens when there are multiple optimal splits during training. Specifically, when there are several splits with the same criterion value (i.e., splitting produces the same improvement/loss), the algorithm picks the first split it encounters. This is due to a strict ordering (`if current_proxy_improvement > best_proxy_improvement:`) in the code. For splits involving missing values, the first split with missing values assigned to the right child is considered.

This tie-breaking bias is confusing—recent discussions in PR #32274 highlighted that documentation only describes this for missing value scenarios, and not as a general rule.

**References:** PR #32274, Meta issue #23728.

### Suggest a potential alternative/fix

Add a concise section to the decision tree documentation summarizing the present tie-breaking logic: when multiple splits have the same criterion, the first encountered is always chosen (order matters). For missing values, explain that splits with missing to the right are evaluated first, so those are chosen by default in a tie. 
Maybe mention relevant discussion in #23728, and clarify if/when unbiased/random tie-breaking might be considered as a future enhancement?

COMMENT:
I am on it !

Labels: Documentation
DOC: Clarify tie-breaking logic for equivalent splits in decision tree documentation

### Describe the issue linked to the documentation

(IA generated, but read and pruned by a human ^^)

The user guide and API reference for decision trees and extra trees do not currently document what happens when there are multiple optimal splits during training. Specifically, when there are several splits with the same criterion value (i.e., splitting produces the same improvement/loss), the algorithm picks the first split it encounters. This is due to a strict ordering (`if current_proxy_improvement > best_proxy_improvement:`) in the code. For splits involving missing values, the first split with missing values assigned to the right child is considered.

This tie-breaking bias is confusing—recent discussions in PR #32274 highlighted that documentation only describes this for missing value scenarios, and not as a general rule.

**References:** PR #32274, Meta issue #23728.

### Suggest a potential alternative/fix

Add a concise section to the decision tree documentation summarizing the present tie-breaking logic: when multiple splits have the same criterion, the first encountered is always chosen (order matters). For missing values, explain that splits with missing to the right are evaluated first, so those are chosen by default in a tie. 
Maybe mention relevant discussion in #23728, and clarify if/when unbiased/random tie-breaking might be considered as a future enhancement?

COMMENT:
/take

Labels: Documentation