Talip7/scikit-learn-issues-multilabel huggingface dataset:
Pin dependencies version in CI with lock files with a bot that auto-updates the lockfiles

### Motivation

- avoid CI breakage due to dependencies updates (recent examples: setuptools update, pytest7 update, coverage 6.3 update, very likely others ...)
- avoid painful debugging when a breakage happens to figure out what is the cause of the problem and generally end up after some time that a dependency has changed
- avoid breaking everyone PRs which is confusing for contributers

### Ideas for implementation

- have environment.yml files for each build rather than versions defined in azure/Circle .yml (for the build using build, we can either use  poetry or conda-lock is supposed to support pip section in the environment.yml although I have not managed to get it to work yet)
- have a script using [conda-lock](https://github.com/conda-incubator/conda-lock) to regenerates conda lock files for each build based on their environment.yml
- have a bot that runs this script updates the lock files and creates a PR, it seems like using an approach using GH action like  Hypothesis does could work:
  https://github.com/HypothesisWorks/hypothesis/commit/c96bbc86efbaa46a78bbb075a36869734dde76b9.
- Have this PR merged if CI passes
- only one PR opened at a time to avoid generating many PRs with the same diff. If there is already an open PR (based on a github label for example), push -f  to the PR branch

### Where to start

I'll probably try out this idea on one build first (e.g. one using conda-forge) to test it out, see how that works, and go from there.

cc @thomasjpfan in case you have some thoughs about this or you have already started working on something similar

### Rejected alternatives

In an ideal workd we would "just" use Dependabot but [it can spam forks](https://github.com/dependabot/dependabot-core/issues/2804) with PRs. Numpy has given up on it see for example [this](https://twitter.com/ralfgommers/status/1457023221841149955)

COMMENT:
> I undid the update of build_tools/azure/pylatest_conda_mkl_no_openmp_osx-64_conda.lock to wait for the Anaconda.org defaults channel to update their scipy version to get a consistent set of dependencies on that distribution.

In https://github.com/scikit-learn/scikit-learn/pull/24363, we had to manually undo the pypy environment and the conda defaults environment. I think the future bot should open one PR for each environment. This way an issue with one environment does not block other environments from updating. If this ends up to be too many PRs, we get the bot to auto merge, or configure GitHub to only auto-merge the PRs the bot created.

XREF: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request

Labels: Build / CI
Pin dependencies version in CI with lock files with a bot that auto-updates the lockfiles

### Motivation

- avoid CI breakage due to dependencies updates (recent examples: setuptools update, pytest7 update, coverage 6.3 update, very likely others ...)
- avoid painful debugging when a breakage happens to figure out what is the cause of the problem and generally end up after some time that a dependency has changed
- avoid breaking everyone PRs which is confusing for contributers

### Ideas for implementation

- have environment.yml files for each build rather than versions defined in azure/Circle .yml (for the build using build, we can either use  poetry or conda-lock is supposed to support pip section in the environment.yml although I have not managed to get it to work yet)
- have a script using [conda-lock](https://github.com/conda-incubator/conda-lock) to regenerates conda lock files for each build based on their environment.yml
- have a bot that runs this script updates the lock files and creates a PR, it seems like using an approach using GH action like  Hypothesis does could work:
  https://github.com/HypothesisWorks/hypothesis/commit/c96bbc86efbaa46a78bbb075a36869734dde76b9.
- Have this PR merged if CI passes
- only one PR opened at a time to avoid generating many PRs with the same diff. If there is already an open PR (based on a github label for example), push -f  to the PR branch

### Where to start

I'll probably try out this idea on one build first (e.g. one using conda-forge) to test it out, see how that works, and go from there.

cc @thomasjpfan in case you have some thoughs about this or you have already started working on something similar

### Rejected alternatives

In an ideal workd we would "just" use Dependabot but [it can spam forks](https://github.com/dependabot/dependabot-core/issues/2804) with PRs. Numpy has given up on it see for example [this](https://twitter.com/ralfgommers/status/1457023221841149955)

COMMENT:
The workflow of SciTools seems really what we wanted or close to it.
@lesteve Do you think that it would be a hassle to adapt this workflow to ours?

I would be thrilled to review a give it a try for sometimes on our repository. I already like the comfort that we got by adopting the lock files.

Labels: Build / CI
Pin dependencies version in CI with lock files with a bot that auto-updates the lockfiles

### Motivation

- avoid CI breakage due to dependencies updates (recent examples: setuptools update, pytest7 update, coverage 6.3 update, very likely others ...)
- avoid painful debugging when a breakage happens to figure out what is the cause of the problem and generally end up after some time that a dependency has changed
- avoid breaking everyone PRs which is confusing for contributers

### Ideas for implementation

- have environment.yml files for each build rather than versions defined in azure/Circle .yml (for the build using build, we can either use  poetry or conda-lock is supposed to support pip section in the environment.yml although I have not managed to get it to work yet)
- have a script using [conda-lock](https://github.com/conda-incubator/conda-lock) to regenerates conda lock files for each build based on their environment.yml
- have a bot that runs this script updates the lock files and creates a PR, it seems like using an approach using GH action like  Hypothesis does could work:
  https://github.com/HypothesisWorks/hypothesis/commit/c96bbc86efbaa46a78bbb075a36869734dde76b9.
- Have this PR merged if CI passes
- only one PR opened at a time to avoid generating many PRs with the same diff. If there is already an open PR (based on a github label for example), push -f  to the PR branch

### Where to start

I'll probably try out this idea on one build first (e.g. one using conda-forge) to test it out, see how that works, and go from there.

cc @thomasjpfan in case you have some thoughs about this or you have already started working on something similar

### Rejected alternatives

In an ideal workd we would "just" use Dependabot but [it can spam forks](https://github.com/dependabot/dependabot-core/issues/2804) with PRs. Numpy has given up on it see for example [this](https://twitter.com/ralfgommers/status/1457023221841149955)

COMMENT:
This seems completely doable, although with CI things tend to take longer than anticipated/hoped :wink:

Labels: Build / CI
Pin dependencies version in CI with lock files with a bot that auto-updates the lockfiles

### Motivation

- avoid CI breakage due to dependencies updates (recent examples: setuptools update, pytest7 update, coverage 6.3 update, very likely others ...)
- avoid painful debugging when a breakage happens to figure out what is the cause of the problem and generally end up after some time that a dependency has changed
- avoid breaking everyone PRs which is confusing for contributers

### Ideas for implementation

- have environment.yml files for each build rather than versions defined in azure/Circle .yml (for the build using build, we can either use  poetry or conda-lock is supposed to support pip section in the environment.yml although I have not managed to get it to work yet)
- have a script using [conda-lock](https://github.com/conda-incubator/conda-lock) to regenerates conda lock files for each build based on their environment.yml
- have a bot that runs this script updates the lock files and creates a PR, it seems like using an approach using GH action like  Hypothesis does could work:
  https://github.com/HypothesisWorks/hypothesis/commit/c96bbc86efbaa46a78bbb075a36869734dde76b9.
- Have this PR merged if CI passes
- only one PR opened at a time to avoid generating many PRs with the same diff. If there is already an open PR (based on a github label for example), push -f  to the PR branch

### Where to start

I'll probably try out this idea on one build first (e.g. one using conda-forge) to test it out, see how that works, and go from there.

cc @thomasjpfan in case you have some thoughs about this or you have already started working on something similar

### Rejected alternatives

In an ideal workd we would "just" use Dependabot but [it can spam forks](https://github.com/dependabot/dependabot-core/issues/2804) with PRs. Numpy has given up on it see for example [this](https://twitter.com/ralfgommers/status/1457023221841149955)

COMMENT:
I opened #27622 with a first PR towards a CI lock file bot

Labels: Build / CI
Pin dependencies version in CI with lock files with a bot that auto-updates the lockfiles

### Motivation

- avoid CI breakage due to dependencies updates (recent examples: setuptools update, pytest7 update, coverage 6.3 update, very likely others ...)
- avoid painful debugging when a breakage happens to figure out what is the cause of the problem and generally end up after some time that a dependency has changed
- avoid breaking everyone PRs which is confusing for contributers

### Ideas for implementation

- have environment.yml files for each build rather than versions defined in azure/Circle .yml (for the build using build, we can either use  poetry or conda-lock is supposed to support pip section in the environment.yml although I have not managed to get it to work yet)
- have a script using [conda-lock](https://github.com/conda-incubator/conda-lock) to regenerates conda lock files for each build based on their environment.yml
- have a bot that runs this script updates the lock files and creates a PR, it seems like using an approach using GH action like  Hypothesis does could work:
  https://github.com/HypothesisWorks/hypothesis/commit/c96bbc86efbaa46a78bbb075a36869734dde76b9.
- Have this PR merged if CI passes
- only one PR opened at a time to avoid generating many PRs with the same diff. If there is already an open PR (based on a github label for example), push -f  to the PR branch

### Where to start

I'll probably try out this idea on one build first (e.g. one using conda-forge) to test it out, see how that works, and go from there.

cc @thomasjpfan in case you have some thoughs about this or you have already started working on something similar

### Rejected alternatives

In an ideal workd we would "just" use Dependabot but [it can spam forks](https://github.com/dependabot/dependabot-core/issues/2804) with PRs. Numpy has given up on it see for example [this](https://twitter.com/ralfgommers/status/1457023221841149955)

COMMENT:
I think the bot is working fine, see [PRs opened by the bot](https://github.com/scikit-learn/scikit-learn/pulls?q=is%3Apr+sort%3Aupdated-desc+author%3Ascikit-learn-bot), so I am going to close this issue. 

Other improvements could happen in the future e.g. auto-merging PRs, updating the conda-lock version automatically, but the bulk of the work is done.

Labels: Build / CI
Identity Mapping

### Describe the workflow you want to enable

Introduce the identity element to the sklearn processing system.
When creating a program that allows you to select the pipeline of sklearn with the GUI, you may be asked to select whether or not to select explanatory variables.

When selecting explanatory variables, it can be described as follows.
SelectKBest () * RandomForestRegressor ()
However, since the sklearn processing system does not have an identity element, it is difficult to incorporate the operation of "do nothing" into Pipeline.
In other words, there is a flaw in the definition of multiplication on sklearn.
Do_nothing () * RandomForestRegressor ()

Therefore, by introducing Identity Mapping, it becomes easier to implement the operation of "doing nothing". 


### Describe your proposed solution

Here is the psuedo code.
```
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
class IdentityMapping(TransformerMixin, BaseEstimator):
    def __init__(self):
        pass
    def fit(self, X, y=None, sample_weight=None, check_input=True):
        return self
    def transform(self, X, y=None, sample_weight=None, check_input=True):
        self.mask = [True for i in range(np.array(X).shape[1])]
        return X
    def inverse_transform(self, X, y=None, sample_weight=None, check_input=True):
        return X
    def get_support(self):
        return self.mask
```

```
pipe1 = Pipeline([('selector', IdentityMapping(), 'estimator', RandomForestRegressor())])

pipe2 = Pipeline([('selector', SelectKBest(chi2), 'estimator', RandomForestRegressor())])

```

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

_No response_

### Additional context

_No response_

COMMENT:
Thank you for opening the issue!

Pipeline allows "passthrough" to be a step which functions as "do nothing":

```python
from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification

X, y = make_classification()
pipe = Pipeline([("selector", "passthrough"),
                 ("classifier", RandomForestClassifier())])
pipe.fit(X, y)
```

If you need an estimator, [FunctionTransformer](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.FunctionTransformer.html#sklearn.preprocessing.FunctionTransformer) is an identity transformation by default.

Labels: New Feature, Needs Triage
Y_trans is not equal to y_scores_ in PLSRegression

### Describe the bug

The documentation that `Y_trans` obtained from `fit_transform` should be equal to `y_scores_` fitted attribute but this is not the case.

We should investigate if this is normal or not

### Steps/Code to Reproduce

```python
In [1]: from sklearn.cross_decomposition import PLSRegression
   ...: X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
   ...: Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
   ...: pls2 = PLSRegression(n_components=2)
   ...: X_trans, Y_trans = pls2.fit_transform(X, Y)
```

### Expected Results

`Y_trans` should be equal to `y_scores_`.

### Actual Results

```python

In [2]: Y_trans
Out[2]: 
array([[-1.10089007,  2.64706486],
       [-1.73668766, -5.50753532],
       [ 1.05463999,  5.91255735],
       [ 1.78293774, -3.05208689]])

In [3]: pls2.y_scores_
Out[3]: 
array([[-1.40620988,  0.09323305],
       [-1.10143324, -0.85118366],
       [ 0.37266921,  1.64933181],
       [ 2.13497391, -0.8913812 ]])
```

### Versions

```shell
In [8]: sklearn.show_versions()

System:
    python: 3.8.12 | packaged by conda-forge | (default, Sep 16 2021, 01:38:21)  [Clang 11.1.0 ]
executable: /Users/glemaitre/mambaforge/envs/dev/bin/python
   machine: macOS-12.1-arm64-arm-64bit

Python dependencies:
          pip: 21.3
   setuptools: 58.2.0
      sklearn: 1.1.dev0
        numpy: 1.21.2
        scipy: 1.8.0.dev0+1902.b795164
       Cython: 0.29.24
       pandas: 1.3.3
   matplotlib: 3.4.3
       joblib: 1.2.0.dev0
threadpoolctl: 3.0.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libopenblas_vortexp-r0.3.18.dylib
        version: 0.3.18
threading_layer: openmp
   architecture: VORTEX
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libomp.dylib
        version: None
    num_threads: 8
```
```

COMMENT:
Looks like the `transform` method takes `TS` where `T` is the _normalized_ `Y` matrix, and `S` is the rotation matrix for `Y`, accessible as `y_rotations_`, which is consistent with the [user guide](https://scikit-learn.org/stable/modules/cross_decomposition.html#transforming-data) so I'm inclined to believe that the documentation for `transform` should be updated. 

In fact, it looks like the documentation actually states that `transform` will return `x_scores, y_scores`, without the `_` suffix. Furthermore, even the fitted attributes `x_scores_, y_scores_` are meant to be depreciated, so we should steer away from referencing them entirely imo.

Labels: Bug, module:cross_decomposition
Y_trans is not equal to y_scores_ in PLSRegression

### Describe the bug

The documentation that `Y_trans` obtained from `fit_transform` should be equal to `y_scores_` fitted attribute but this is not the case.

We should investigate if this is normal or not

### Steps/Code to Reproduce

```python
In [1]: from sklearn.cross_decomposition import PLSRegression
   ...: X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
   ...: Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
   ...: pls2 = PLSRegression(n_components=2)
   ...: X_trans, Y_trans = pls2.fit_transform(X, Y)
```

### Expected Results

`Y_trans` should be equal to `y_scores_`.

### Actual Results

```python

In [2]: Y_trans
Out[2]: 
array([[-1.10089007,  2.64706486],
       [-1.73668766, -5.50753532],
       [ 1.05463999,  5.91255735],
       [ 1.78293774, -3.05208689]])

In [3]: pls2.y_scores_
Out[3]: 
array([[-1.40620988,  0.09323305],
       [-1.10143324, -0.85118366],
       [ 0.37266921,  1.64933181],
       [ 2.13497391, -0.8913812 ]])
```

### Versions

```shell
In [8]: sklearn.show_versions()

System:
    python: 3.8.12 | packaged by conda-forge | (default, Sep 16 2021, 01:38:21)  [Clang 11.1.0 ]
executable: /Users/glemaitre/mambaforge/envs/dev/bin/python
   machine: macOS-12.1-arm64-arm-64bit

Python dependencies:
          pip: 21.3
   setuptools: 58.2.0
      sklearn: 1.1.dev0
        numpy: 1.21.2
        scipy: 1.8.0.dev0+1902.b795164
       Cython: 0.29.24
       pandas: 1.3.3
   matplotlib: 3.4.3
       joblib: 1.2.0.dev0
threadpoolctl: 3.0.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libopenblas_vortexp-r0.3.18.dylib
        version: 0.3.18
threading_layer: openmp
   architecture: VORTEX
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/glemaitre/mambaforge/envs/dev/lib/libomp.dylib
        version: None
    num_threads: 8
```
```

COMMENT:
Actually we want only to deprecate these attributes for all PLS algorithms apart from the PLSRegression. So I assume we can update the documentation and fix the test in the deprecation PR.

Labels: Bug, module:cross_decomposition
ValueError when a key present in class_weight is not found in labels

### Describe the bug

While using `sklearn.ensemble.RandomForestClassifier` with a custom dictionary specified for `class_weight` parameter, a `ValueError` is raised when a key (label) present in `class_weight` is not found in any of the labels. I got this error while using `TimeSeriesSplit`. Specifically, if a split is such that training data doesn't have a label specified in `class_weight`, a `ValueError` will be raised. This stops users from evaluating their model since `class_weight` cannot be changed on a go after the model has been created. 

Is there any reason this check is being done? There's no error when we don't specify class_weight. The code raising this error can be found here ([link](https://github.com/scikit-learn/scikit-learn/blob/5900e2660f4293b52ea57bf830e7bff312779036/sklearn/utils/class_weight.py#L8)).



### Steps/Code to Reproduce

```
from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier(class_weight={1:10, 0:1})
rfc.fit([[0, 0, 1], [1, 0, 1]], [0, 0])
```



### Expected Results

No errors raised.

### Actual Results

`ValueError: Class label 1 not present.`


### Versions

```shell
System:
    python: 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)]
executable: c:\python3.9.2\python.exe
   machine: Windows-10-10.0.19041-SP0

Python dependencies:
          pip: 21.3.1
   setuptools: 58.3.0
      sklearn: 0.24.1
        numpy: 1.21.3
        scipy: 1.6.1
       Cython: 0.29.24
       pandas: 1.2.3
   matplotlib: 3.3.4
       joblib: 1.0.1
threadpoolctl: 2.1.0

Built with OpenMP: True
```

COMMENT:
So the specific code that causes this is: https://github.com/scikit-learn/scikit-learn/blob/5900e2660f4293b52ea57bf830e7bff312779036/sklearn/utils/class_weight.py#L61-L66

To me, it would make sense to simply _ignore_ instances where the `class_weights` dict defines weights for unobserved classes, exactly for the kind of workflow mentioned. A simple change could be:

```python
        for c in class_weight:
            i = np.searchsorted(classes, c)            
            if i < len(classes) and classes[i] == c:
                weight[i] = class_weight[c]
```

@DeepOde would you potentially be interested in opening a PR for this? Of course we'll still need to hear from the core maintainers regarding whether this is a viable change to behavior, or if this ends up being an unintentional regression.

Labels: Bug, Moderate, module:tree
ValueError when a key present in class_weight is not found in labels

### Describe the bug

While using `sklearn.ensemble.RandomForestClassifier` with a custom dictionary specified for `class_weight` parameter, a `ValueError` is raised when a key (label) present in `class_weight` is not found in any of the labels. I got this error while using `TimeSeriesSplit`. Specifically, if a split is such that training data doesn't have a label specified in `class_weight`, a `ValueError` will be raised. This stops users from evaluating their model since `class_weight` cannot be changed on a go after the model has been created. 

Is there any reason this check is being done? There's no error when we don't specify class_weight. The code raising this error can be found here ([link](https://github.com/scikit-learn/scikit-learn/blob/5900e2660f4293b52ea57bf830e7bff312779036/sklearn/utils/class_weight.py#L8)).



### Steps/Code to Reproduce

```
from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier(class_weight={1:10, 0:1})
rfc.fit([[0, 0, 1], [1, 0, 1]], [0, 0])
```



### Expected Results

No errors raised.

### Actual Results

`ValueError: Class label 1 not present.`


### Versions

```shell
System:
    python: 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)]
executable: c:\python3.9.2\python.exe
   machine: Windows-10-10.0.19041-SP0

Python dependencies:
          pip: 21.3.1
   setuptools: 58.3.0
      sklearn: 0.24.1
        numpy: 1.21.3
        scipy: 1.6.1
       Cython: 0.29.24
       pandas: 1.2.3
   matplotlib: 3.3.4
       joblib: 1.0.1
threadpoolctl: 2.1.0

Built with OpenMP: True
```

COMMENT:
@Micky774 Sure, I'd love to open a PR for this.

Labels: Bug, Moderate, module:tree