Talip7/scikit-learn-issues-multilabel huggingface dataset:
Pipeline score asks to explicitly request sample_weight

### Describe the bug

When using `Pipeline` with metadata routing enabled,  an error is thrown unless we explicitly request `sample_weight` for the `score` method (see example below). But `Pipeline` is just a router (for both the `fit` and `score` methods) and not a consumer of `sample_weight`, so in principle it should not require `sample_weight` to be explicitly requested.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import set_config
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_classification

set_config(enable_metadata_routing=True)
X, y = make_classification(10, 4)
sample_weight = np.ones_like(y)
logreg = LogisticRegression()
pipe = Pipeline([("logistic", logreg)])
search = GridSearchCV(pipe, {"logistic__C": [0.1, 1]}, n_jobs=1, cv=3)
logreg.set_fit_request(sample_weight=True)
logreg.set_score_request(sample_weight=True)
search.fit(X, y, sample_weight=sample_weight)
```

### Expected Results

No error is thrown, and `sample_weight` are routed to the `logreg`.  

### Actual Results

```python-traceback
sklearn.exceptions.UnsetMetadataPassedError: [sample_weight] are passed but are not explicitly set as requested or not requested for Pipeline.score, which is used within GridSearchCV.fit. Call `Pipeline.set_score_request({metadata}=True/False)` for each metadata you want to request/ignore.
```

### Versions

```shell
sklearn: 1.7.dev0
```

COMMENT:
Digging deeper here, the issue seems to be that `_PassthroughScorer` doesn't correctly manage to extract the `score` requests on a meta-estimator:

https://github.com/scikit-learn/scikit-learn/blob/52fb066f9dd8eeb841843c27d3d56b28352e1bf0/sklearn/metrics/_scorer.py#L481-L493

I'll see how one can reliably extract a part of a larger request here. I remember having a simple copy of the whole thing wouldn't solve the issue, not sure why.

Labels: Bug, Metadata Routing
Pipeline score asks to explicitly request sample_weight

### Describe the bug

When using `Pipeline` with metadata routing enabled,  an error is thrown unless we explicitly request `sample_weight` for the `score` method (see example below). But `Pipeline` is just a router (for both the `fit` and `score` methods) and not a consumer of `sample_weight`, so in principle it should not require `sample_weight` to be explicitly requested.

### Steps/Code to Reproduce

```python
import numpy as np
from sklearn import set_config
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_classification

set_config(enable_metadata_routing=True)
X, y = make_classification(10, 4)
sample_weight = np.ones_like(y)
logreg = LogisticRegression()
pipe = Pipeline([("logistic", logreg)])
search = GridSearchCV(pipe, {"logistic__C": [0.1, 1]}, n_jobs=1, cv=3)
logreg.set_fit_request(sample_weight=True)
logreg.set_score_request(sample_weight=True)
search.fit(X, y, sample_weight=sample_weight)
```

### Expected Results

No error is thrown, and `sample_weight` are routed to the `logreg`.  

### Actual Results

```python-traceback
sklearn.exceptions.UnsetMetadataPassedError: [sample_weight] are passed but are not explicitly set as requested or not requested for Pipeline.score, which is used within GridSearchCV.fit. Call `Pipeline.set_score_request({metadata}=True/False)` for each metadata you want to request/ignore.
```

### Versions

```shell
sklearn: 1.7.dev0
```

COMMENT:
Hi, I am interested in solving this :). Could I be assigned?

Labels: Bug, Metadata Routing
The default token pattern in CountVectorizer breaks Indic sentences into non-sensical tokens

### Describe the bug

The default `token_pattern` in `CountVectorizer` is `r"(?u)\b\w\w+\b"` which tokenizes Indic texts in a wrong way - breaks whitespace tokenized words into multiple chunks and even omits several valid characters. The resulting vocabulary doesn't make any sense !

Is this the expected behaviour?

Sample code is pasted in the sections below

### Steps/Code to Reproduce

```
import sklearn
from sklearn.feature_extraction.text import CountVectorizer

tel = ["ప్రధానమంత్రిని కలుసుకున్నారు"]
hin = ["आधुनिक मानक हिन्दी"]
eng = ["They met the Prime Minister"]

cvect = CountVectorizer(
    ngram_range=(1, 1),
    max_features=None,
    min_df=1,
    strip_accents=None,
)
cvect.fit(tel + hin + eng)
print(cvect.vocabulary_)
```

### Expected Results

```
{'ప్రధానమంత్రిని': 9, 'కలుసుకున్నారు': 8, 'आधुनिक': 5, 'मानक': 6, 'हिन्दी': 7, 'they': 4, 'met': 0, 'the': 3, 'prime': 2, 'minister': 1}
```

### Actual Results

```
{'రధ': 9, 'నమ': 8, 'కల': 7, 'आध': 5, 'नक': 6, 'they': 4, 'met': 0, 'the': 3, 'prime': 2, 'minister': 1}
```


### Versions

```
System:
    python: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]
executable: miniconda3/envs/lolm/bin/python
   machine: Linux-6.1.0-25-amd64-x86_64-with-glibc2.36

Python dependencies:
      sklearn: 1.5.2
          pip: 24.2
   setuptools: 75.1.0
        numpy: 1.26.0
        scipy: 1.14.1
       Cython: None
       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: mkl
    num_threads: 1
         prefix: libmkl_rt
       filepath: miniconda3/envs/lolm/lib/libmkl_rt.so.2
        version: 2023.1-Product
threading_layer: gnu

       user_api: openmp
   internal_api: openmp
    num_threads: 1
         prefix: libgomp
       filepath: miniconda3/envs/lolm/lib/libgomp.so.1.0.0
        version: None
```

COMMENT:
Thanks for reporting this. It is an interesting one. It is surprising to see the tokenisation fail like this and I am not quite sure why. The default token pattern is something like "word break, one or more word characters, word break" - a word break is the transition from a `\W` to a `\w` (or reverse). With a `\W` being a "not word character" and `\w` being a "word character". What is and isn't a word character seems to boil down to https://docs.python.org/3/library/stdtypes.html#str.isalpha ("Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”.")

So overall I'd have thought this should work.

Interestingly with `token_pattern=r"\S\S+"` the splitting works better. But it includes punctuation characters, so something like "`They met: a prime minister"` becomes `['They', 'met:', 'Prime', 'Minister']` (the `:` doesn't get removed).

I don't know enough about non latin script to understand if `\w` should work or not :-/

Labels: Bug
The default token pattern in CountVectorizer breaks Indic sentences into non-sensical tokens

### Describe the bug

The default `token_pattern` in `CountVectorizer` is `r"(?u)\b\w\w+\b"` which tokenizes Indic texts in a wrong way - breaks whitespace tokenized words into multiple chunks and even omits several valid characters. The resulting vocabulary doesn't make any sense !

Is this the expected behaviour?

Sample code is pasted in the sections below

### Steps/Code to Reproduce

```
import sklearn
from sklearn.feature_extraction.text import CountVectorizer

tel = ["ప్రధానమంత్రిని కలుసుకున్నారు"]
hin = ["आधुनिक मानक हिन्दी"]
eng = ["They met the Prime Minister"]

cvect = CountVectorizer(
    ngram_range=(1, 1),
    max_features=None,
    min_df=1,
    strip_accents=None,
)
cvect.fit(tel + hin + eng)
print(cvect.vocabulary_)
```

### Expected Results

```
{'ప్రధానమంత్రిని': 9, 'కలుసుకున్నారు': 8, 'आधुनिक': 5, 'मानक': 6, 'हिन्दी': 7, 'they': 4, 'met': 0, 'the': 3, 'prime': 2, 'minister': 1}
```

### Actual Results

```
{'రధ': 9, 'నమ': 8, 'కల': 7, 'आध': 5, 'नक': 6, 'they': 4, 'met': 0, 'the': 3, 'prime': 2, 'minister': 1}
```


### Versions

```
System:
    python: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]
executable: miniconda3/envs/lolm/bin/python
   machine: Linux-6.1.0-25-amd64-x86_64-with-glibc2.36

Python dependencies:
      sklearn: 1.5.2
          pip: 24.2
   setuptools: 75.1.0
        numpy: 1.26.0
        scipy: 1.14.1
       Cython: None
       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: mkl
    num_threads: 1
         prefix: libmkl_rt
       filepath: miniconda3/envs/lolm/lib/libmkl_rt.so.2
        version: 2023.1-Product
threading_layer: gnu

       user_api: openmp
   internal_api: openmp
    num_threads: 1
         prefix: libgomp
       filepath: miniconda3/envs/lolm/lib/libgomp.so.1.0.0
        version: None
```

COMMENT:
/take

Labels: Bug
DOC Missing doc string in tests present in sklearn/linear_model/_glm/tests/test_glm.py

### Describe the issue related to documentation
The file `sklearn/linear_model/_glm/tests/test_glm.py` has the following tests without any doc string to describe what these functions aim to test.

- test_glm_wrong_y_range
- test_warm_start
- test_tags
- test_linalg_warning_with_newton_solver

### Suggested fix/improvement
Add doc strings to these tests similar to ones present in other tests with doc strings in the same file.

for example: 

```
def test_linalg_warning_with_newton_solver(global_random_seed):
    """Test PoissonRegressor's behavior with the Newton solver under collinearity."""
```

### Additional Comments
I would like to work on this for my first documentation related work on this project.

COMMENT:
I think it's a good idea to add docstrings when the test code is more than a few non-trivial to understand lines. The docstring should state the purpose of the test. If it's multi-line, please follow PEP 257 recommendations for multiline docstrings:

- first line is a single line, high-level summary,
- then a blank line,
- then a paragraph with more details.

It's also possible to add inline comment to explain the "why" (and not the "what") of complex code sections in those tests.

Labels: Documentation
DOC Missing doc string in tests present in sklearn/linear_model/_glm/tests/test_glm.py

### Describe the issue related to documentation
The file `sklearn/linear_model/_glm/tests/test_glm.py` has the following tests without any doc string to describe what these functions aim to test.

- test_glm_wrong_y_range
- test_warm_start
- test_tags
- test_linalg_warning_with_newton_solver

### Suggested fix/improvement
Add doc strings to these tests similar to ones present in other tests with doc strings in the same file.

for example: 

```
def test_linalg_warning_with_newton_solver(global_random_seed):
    """Test PoissonRegressor's behavior with the Newton solver under collinearity."""
```

### Additional Comments
I would like to work on this for my first documentation related work on this project.

COMMENT:
Hi @ogrisel, Thanks for your feedback, I would raise a PR for this following these instructions.

Labels: Documentation
DOC Missing doc string in tests present in sklearn/linear_model/_glm/tests/test_glm.py

### Describe the issue related to documentation
The file `sklearn/linear_model/_glm/tests/test_glm.py` has the following tests without any doc string to describe what these functions aim to test.

- test_glm_wrong_y_range
- test_warm_start
- test_tags
- test_linalg_warning_with_newton_solver

### Suggested fix/improvement
Add doc strings to these tests similar to ones present in other tests with doc strings in the same file.

for example: 

```
def test_linalg_warning_with_newton_solver(global_random_seed):
    """Test PoissonRegressor's behavior with the Newton solver under collinearity."""
```

### Additional Comments
I would like to work on this for my first documentation related work on this project.

COMMENT:
Please don't forget to cross-link to this issue by mentioning #30934 in the description of the PR.

Labels: Documentation
DecisionTreeClassifier having unexpected behaviour with 'min_weight_fraction_leaf=0.5'

### Describe the bug

When fitting DecisionTreeClassifier on a duplicated sample set (i.e. each sample repeated by two), the result is not the same as when fitting on the original sample set. This only happens for 'min_weight_fraction_leaf' specified as <0.5. This also effects ExtraTreesClassifier and ExtraTreeClassifier.

### Steps/Code to Reproduce

```python
from sklearn.tree import DecisionTreeClassifier
from scipy.stats import kstest
import numpy as np

rng = np.random.RandomState(0)
    
n_samples = 20
X = rng.rand(n_samples, n_samples * 2)
y = rng.randint(0, 3, size=n_samples)

X_repeated = np.repeat(X,2,axis=0)
y_repeated = np.repeat(y,2)

predictions = []
predictions_dup = []

## Fit estimator
for seed in range(100):
    est = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X,y)
    est_dup = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X_repeated,y_repeated)

    ##Get predictions
    predictions.append(est.predict_proba(X)[:,:-1])
    predictions_dup.append(est_dup.predict_proba(X)[:,:-1])

predictions = np.vstack(predictions)
predictions_dup = np.vstack(predictions_dup)

for pred, pred_dup in (predictions.T,predictions_dup.T):
    print(kstest(pred,pred_dup).pvalue)

```

### Expected Results

p-values are more than ˜0.05

### Actual Results

```
p-values = 2.0064970441275627e-69
```

### Versions

```shell
System:
    python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
executable: /Users/shrutinath/micromamba/envs/scikit-learn/bin/python
   machine: macOS-14.3-arm64-arm-64bit

Python dependencies:
      sklearn: 1.7.dev0
          pip: 24.0
   setuptools: 75.8.0
        numpy: 2.0.0
        scipy: 1.14.0
       Cython: 3.0.10
       pandas: 2.2.2
   matplotlib: 3.9.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
...
    num_threads: 8
         prefix: libomp
       filepath: /Users/shrutinath/micromamba/envs/scikit-learn/lib/libomp.dylib
        version: None
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
```

COMMENT:
This occurs for seed in range(300) as well with p-values of:
```
1.336814951659136e-178
```

Labels: Bug
DecisionTreeClassifier having unexpected behaviour with 'min_weight_fraction_leaf=0.5'

### Describe the bug

When fitting DecisionTreeClassifier on a duplicated sample set (i.e. each sample repeated by two), the result is not the same as when fitting on the original sample set. This only happens for 'min_weight_fraction_leaf' specified as <0.5. This also effects ExtraTreesClassifier and ExtraTreeClassifier.

### Steps/Code to Reproduce

```python
from sklearn.tree import DecisionTreeClassifier
from scipy.stats import kstest
import numpy as np

rng = np.random.RandomState(0)
    
n_samples = 20
X = rng.rand(n_samples, n_samples * 2)
y = rng.randint(0, 3, size=n_samples)

X_repeated = np.repeat(X,2,axis=0)
y_repeated = np.repeat(y,2)

predictions = []
predictions_dup = []

## Fit estimator
for seed in range(100):
    est = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X,y)
    est_dup = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X_repeated,y_repeated)

    ##Get predictions
    predictions.append(est.predict_proba(X)[:,:-1])
    predictions_dup.append(est_dup.predict_proba(X)[:,:-1])

predictions = np.vstack(predictions)
predictions_dup = np.vstack(predictions_dup)

for pred, pred_dup in (predictions.T,predictions_dup.T):
    print(kstest(pred,pred_dup).pvalue)

```

### Expected Results

p-values are more than ˜0.05

### Actual Results

```
p-values = 2.0064970441275627e-69
```

### Versions

```shell
System:
    python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
executable: /Users/shrutinath/micromamba/envs/scikit-learn/bin/python
   machine: macOS-14.3-arm64-arm-64bit

Python dependencies:
      sklearn: 1.7.dev0
          pip: 24.0
   setuptools: 75.8.0
        numpy: 2.0.0
        scipy: 1.14.0
       Cython: 3.0.10
       pandas: 2.2.2
   matplotlib: 3.9.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
...
    num_threads: 8
         prefix: libomp
       filepath: /Users/shrutinath/micromamba/envs/scikit-learn/lib/libomp.dylib
        version: None
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
```

COMMENT:
This is related to this RFC about sample weight invariance properties (https://github.com/scikit-learn/scikit-learn/issues/15657), and this case in particular as already been identified as problematic, see https://github.com/scikit-learn/scikit-learn/issues/15657#issuecomment-555615961.

This is another example of an hyper-parameter which depend on n_samples but makes things weird or not very user friendly if modified to depend on weight sum instead.

Labels: Bug
DecisionTreeClassifier having unexpected behaviour with 'min_weight_fraction_leaf=0.5'

### Describe the bug

When fitting DecisionTreeClassifier on a duplicated sample set (i.e. each sample repeated by two), the result is not the same as when fitting on the original sample set. This only happens for 'min_weight_fraction_leaf' specified as <0.5. This also effects ExtraTreesClassifier and ExtraTreeClassifier.

### Steps/Code to Reproduce

```python
from sklearn.tree import DecisionTreeClassifier
from scipy.stats import kstest
import numpy as np

rng = np.random.RandomState(0)
    
n_samples = 20
X = rng.rand(n_samples, n_samples * 2)
y = rng.randint(0, 3, size=n_samples)

X_repeated = np.repeat(X,2,axis=0)
y_repeated = np.repeat(y,2)

predictions = []
predictions_dup = []

## Fit estimator
for seed in range(100):
    est = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X,y)
    est_dup = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X_repeated,y_repeated)

    ##Get predictions
    predictions.append(est.predict_proba(X)[:,:-1])
    predictions_dup.append(est_dup.predict_proba(X)[:,:-1])

predictions = np.vstack(predictions)
predictions_dup = np.vstack(predictions_dup)

for pred, pred_dup in (predictions.T,predictions_dup.T):
    print(kstest(pred,pred_dup).pvalue)

```

### Expected Results

p-values are more than ˜0.05

### Actual Results

```
p-values = 2.0064970441275627e-69
```

### Versions

```shell
System:
    python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
executable: /Users/shrutinath/micromamba/envs/scikit-learn/bin/python
   machine: macOS-14.3-arm64-arm-64bit

Python dependencies:
      sklearn: 1.7.dev0
          pip: 24.0
   setuptools: 75.8.0
        numpy: 2.0.0
        scipy: 1.14.0
       Cython: 3.0.10
       pandas: 2.2.2
   matplotlib: 3.9.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
...
    num_threads: 8
         prefix: libomp
       filepath: /Users/shrutinath/micromamba/envs/scikit-learn/lib/libomp.dylib
        version: None
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
```

COMMENT:
/take

Labels: Bug
DecisionTreeClassifier having unexpected behaviour with 'min_weight_fraction_leaf=0.5'

### Describe the bug

When fitting DecisionTreeClassifier on a duplicated sample set (i.e. each sample repeated by two), the result is not the same as when fitting on the original sample set. This only happens for 'min_weight_fraction_leaf' specified as <0.5. This also effects ExtraTreesClassifier and ExtraTreeClassifier.

### Steps/Code to Reproduce

```python
from sklearn.tree import DecisionTreeClassifier
from scipy.stats import kstest
import numpy as np

rng = np.random.RandomState(0)
    
n_samples = 20
X = rng.rand(n_samples, n_samples * 2)
y = rng.randint(0, 3, size=n_samples)

X_repeated = np.repeat(X,2,axis=0)
y_repeated = np.repeat(y,2)

predictions = []
predictions_dup = []

## Fit estimator
for seed in range(100):
    est = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X,y)
    est_dup = DecisionTreeClassifier(random_state=seed, max_features=0.5, min_weight_fraction_leaf=0.5).fit(X_repeated,y_repeated)

    ##Get predictions
    predictions.append(est.predict_proba(X)[:,:-1])
    predictions_dup.append(est_dup.predict_proba(X)[:,:-1])

predictions = np.vstack(predictions)
predictions_dup = np.vstack(predictions_dup)

for pred, pred_dup in (predictions.T,predictions_dup.T):
    print(kstest(pred,pred_dup).pvalue)

```

### Expected Results

p-values are more than ˜0.05

### Actual Results

```
p-values = 2.0064970441275627e-69
```

### Versions

```shell
System:
    python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
executable: /Users/shrutinath/micromamba/envs/scikit-learn/bin/python
   machine: macOS-14.3-arm64-arm-64bit

Python dependencies:
      sklearn: 1.7.dev0
          pip: 24.0
   setuptools: 75.8.0
        numpy: 2.0.0
        scipy: 1.14.0
       Cython: 3.0.10
       pandas: 2.2.2
   matplotlib: 3.9.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libopenblas
...
    num_threads: 8
         prefix: libomp
       filepath: /Users/shrutinath/micromamba/envs/scikit-learn/lib/libomp.dylib
        version: None
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
```

COMMENT:
Hi @pedroL0pes thanks for that, I can confirm that I also get 1.0 p-values locally. Good call on checking the zip. Submitting a patch request sounds good to me, let me know when it's ready for review/if you need help.

Labels: Bug