Talip7/scikit-learn-issues-multilabel huggingface dataset:
OrdinalEncoder with option to mention the start index

### Describe the workflow you want to enable

Hi,
Can OrdinalEncoder be provided with an argument to decide what index to start encoding on


### Describe your proposed solution


For example
``` 
import numpy as np
from sklearn.preprocessing import OrdinalEncoder
oe = OrdinalEncoder(encode_start=0)
oe.fit_transform(np.array(['a','b','c','d','e']))
# Gives us [0,1,2,3,4]

oe = OrdinalEncoder(encode_start=1)
oe.fit_transform(np.array(['a','b','c','d','e']))
# Gives us [1,2,3,4,5]

```



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

_No response_

### Additional context

The Rationale Behind this issue is that users may be able to set unknown values to 0 if encoding is 1-indexed

COMMENT:
> > I am -1 for this feature. I don't think that the benefit of the feature is worth the maintenance and the addition of the new keyword.
> > Note that this behaviour can easily be achieved with the following pipeline:
> > ```python
> > encoder_with_shift = make_pipeline(
> >     OrdinalEncoder(unknown_value=-1),
> >     FunctionTransformer(
> >         func=lambda x: x + 1,
> >         inverse_func=lambda x: x - 1,
> >     )
> > )
> > ```
> 
> If use `FunctionTransformer` to assign the start index, we will have problem saving the pipeline, see the following code:
> 
> ```python
> pickle.dump(encoder_with_shift , open(save_path, 'wb'))
> ```
> 
> It will raise an error, look like the following: `_pickle.PicklingError: Can't pickle <function <lambda> at 0x7f32c82b1900>: it's not found as xxx.<lambda> `
> 
> How to fix the issue?

cause lambda function cannot be pickled by default, you can try using some operator functions

```python
from operator import add
from functools import partial
from sklearn.preprocessing import PowerTransformer

tf = FunctionTransformer(
    func=partial(add, 1),
    inverse_func=partial(add, -1),
)

pickle.dumps(tf)
```

Labels: New Feature, Needs Triage
ValueError: Number of features of the input must be equal to or greater than that of the fitted transformer. Transformer n_features is 5 and input n_features is 4.

i am making an machine learning model for a house price prediction project and when i click on predict price it shows
ValueError: Number of features of the input must be equal to or greater than that of the fitted transformer. Transformer n_features is 5 and input n_features is 4. how to solve this problem

COMMENT:
Hi 👋 !

A good place to ask a question about using scikit-learn is the [discussions area](github.com/scikit-learn/scikit-learn/discussions). I've moved your question there.

You posted in the issue tracker which we try to reserve for discussions about bugs, improvements and other topics directly related to the code.

Labels: Needs Triage
Missing visualization tool - sklearn-evaluation

### Describe the issue linked to the documentation

[This issue](https://github.com/scikit-learn/scikit-learn/pull/17112) was closed a while ago, removing some unmaintained tools. One of them was a tool to allow out-of-the-box visualizations.

My suggestion is to add [sklearn-evaluation](https://github.com/ploomber/sklearn-evaluation), allowing the users an easy mechanism to plot. **We were originally inspired by your plotting API.**

### Suggest a potential alternative/fix

Happy to submit a PR.

COMMENT:
I am okay with adding sklearn-evaluation to the [Related Projects page](https://scikit-learn.org/stable/related_projects.html).

Labels: Documentation
Missing visualization tool - sklearn-evaluation

### Describe the issue linked to the documentation

[This issue](https://github.com/scikit-learn/scikit-learn/pull/17112) was closed a while ago, removing some unmaintained tools. One of them was a tool to allow out-of-the-box visualizations.

My suggestion is to add [sklearn-evaluation](https://github.com/ploomber/sklearn-evaluation), allowing the users an easy mechanism to plot. **We were originally inspired by your plotting API.**

### Suggest a potential alternative/fix

Happy to submit a PR.

COMMENT:
Literally was working on the PR, one sec.

Labels: Documentation
Missing visualization tool - sklearn-evaluation

### Describe the issue linked to the documentation

[This issue](https://github.com/scikit-learn/scikit-learn/pull/17112) was closed a while ago, removing some unmaintained tools. One of them was a tool to allow out-of-the-box visualizations.

My suggestion is to add [sklearn-evaluation](https://github.com/ploomber/sklearn-evaluation), allowing the users an easy mechanism to plot. **We were originally inspired by your plotting API.**

### Suggest a potential alternative/fix

Happy to submit a PR.

COMMENT:
@thomasjpfan is there room for a tutorial/blog?

Labels: Documentation
Missing visualization tool - sklearn-evaluation

### Describe the issue linked to the documentation

[This issue](https://github.com/scikit-learn/scikit-learn/pull/17112) was closed a while ago, removing some unmaintained tools. One of them was a tool to allow out-of-the-box visualizations.

My suggestion is to add [sklearn-evaluation](https://github.com/ploomber/sklearn-evaluation), allowing the users an easy mechanism to plot. **We were originally inspired by your plotting API.**

### Suggest a potential alternative/fix

Happy to submit a PR.

COMMENT:
I think a blog post would be nice @idomic . Could go under https://github.com/scikit-learn/blog/

Labels: Documentation
Missing visualization tool - sklearn-evaluation

### Describe the issue linked to the documentation

[This issue](https://github.com/scikit-learn/scikit-learn/pull/17112) was closed a while ago, removing some unmaintained tools. One of them was a tool to allow out-of-the-box visualizations.

My suggestion is to add [sklearn-evaluation](https://github.com/ploomber/sklearn-evaluation), allowing the users an easy mechanism to plot. **We were originally inspired by your plotting API.**

### Suggest a potential alternative/fix

Happy to submit a PR.

COMMENT:
@adrinjalali sounds good, will start at it!

Labels: Documentation
Typo in contributing docs

### Describe the issue linked to the documentation

In a previous PR when `master` was changed to `main`, it also changed the word `master in` following line:

https://github.com/scikit-learn/scikit-learn/blame/e1ec3f99a3a91823d5923b8e894b8b8792206aab/doc/developers/contributing.rst#L1415

`Reading and digesting an existing code base is always a difficult exercise
that takes time and experience to main.`

On this line we want to change `main` back to `master`.

### Suggest a potential alternative/fix

On this line above, we just need to change `main` back to `master`!

COMMENT:
Happy to fix this issue as it's as easy as they come, and will then raise a PR for the change suggested above

Labels: Documentation, Needs Triage
sklearn.neighbors.KernelDensity bandwith estimation with "scott" or "silverman" is showing TypeError

### Describe the bug

I am not able to use bandwith estimation techniques "scott" and "silverman" in  KernelDensity estimation in sklearn.neighbors as shown in the documentation. It is throwing TypeError. It works only when we give float values to bandwith. 

### Steps/Code to Reproduce

```
from sklearn.neighbors import KernelDensity
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
kde = KernelDensity(kernel='gaussian', bandwidth='scott').fit(X)
```

### Expected Results

No error is thrown

### Actual Results

from sklearn.neighbors import KernelDensity
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
kde = KernelDensity(kernel='gaussian', bandwidth='scott').fit(X)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tony/miniconda3/lib/python3.8/site-packages/sklearn/neighbors/_kde.py", line 143, in __init__
    if bandwidth <= 0:
TypeError: '<=' not supported between instances of 'str' and 'int'

### Versions

```shell
System:
    python: 3.8.13 (default, Mar 28 2022, 11:38:47)  [GCC 7.5.0]
executable: /home/tony/miniconda3/bin/python
   machine: Linux-4.15.0-47-generic-x86_64-with-glibc2.17

Python dependencies:
          pip: 22.3.1
   setuptools: 65.5.0
      sklearn: 1.0.2
        numpy: 1.23.5
        scipy: 1.9.3
       Cython: 0.29.32
       pandas: 1.5.2
   matplotlib: 3.5.1
       joblib: 1.1.1
threadpoolctl: 2.2.0

Built with OpenMP: True
```

COMMENT:
Hello,

I don't think this is a bug. In version 1.0.2 the `KernelDensity` estimator only supported floats as the value for the bandwidth parameter: https://scikit-learn.org/1.0/modules/generated/sklearn.neighbors.KernelDensity.html#sklearn.neighbors.KernelDensity

Please try updating to a newer version, like 1.2, and try again.

Labels: Bug, Needs Triage
Increase minimum Cython version to 0.29.33

Require minimum Cython version >= 0.29.33 as from this version on Cython supports `const` fused types with memory views, see release notes https://cython.readthedocs.io/en/latest/src/changes.html#id30 and the related issue #10624.

COMMENT:
I am highly favorable of requiring using `cython>=0.29.33<3.0`.

I think we need in this regards to communicate (and document) performing this update so that developer aren't meeting the compilation errors met with `cython<0.29.33`.

Labels: Build / CI
Increase minimum Cython version to 0.29.33

Require minimum Cython version >= 0.29.33 as from this version on Cython supports `const` fused types with memory views, see release notes https://cython.readthedocs.io/en/latest/src/changes.html#id30 and the related issue #10624.

COMMENT:
I am +1 on setting the minimum version of Cython to 0.29.33. This would remove the need for the `ReadonlyArrayWrapper`.

As for developers, we currently raise an error if the minimum version of Cython is not installed:

https://github.com/scikit-learn/scikit-learn/blob/9e08ed2279c80407f1d4c92a27279f73a2d08bb2/sklearn/_build_utils/__init__.py#L21-L25

Labels: Build / CI
Increase minimum Cython version to 0.29.33

Require minimum Cython version >= 0.29.33 as from this version on Cython supports `const` fused types with memory views, see release notes https://cython.readthedocs.io/en/latest/src/changes.html#id30 and the related issue #10624.

COMMENT:
https://github.com/scikit-learn/scikit-learn/pull/25342 has been opened accordingly.

Labels: Build / CI
Inconsistency between liac-arff and pandas parser in fetch_openml

From https://github.com/fairlearn/fairlearn/pull/1166, we have an inconsistency between liac-arff and pandas parser.

From the ARFF specs, the leading whitespaces are ignored if not between quotes. The pandas `read_csv` will include this space by default. E.g.

```python
>>> import sklearn.datasets as skd
>>> d = skd.fetch_openml(data_id=1590, as_frame=True, parser='pandas')
>>> d.target
0         <=50K
1         <=50K
2          >50K
3          >50K
4         <=50K
          ...  
48837     <=50K
48838      >50K
48839     <=50K
48840     <=50K
48841      >50K
Name: class, Length: 48842, dtype: category
Categories (2, object): [' <=50K', ' >50K']
```

I am unsure that we can easily solve the issue because once read by `read_csv`, we don't have the information about the quotes anymore. I assume that the best that we can provide is to pass any additional keyword argument to `read_csv` to make it flexible enough.

COMMENT:
Checking closer the behaviour of `skipinitialspace`, it works without issue for the case `' >50K'` where it will keep the space within the quote. So we can just turn on the option.

However, I can see that on the side of OpenML, they have an inconsistency between the metadata and the data that we read because the metadata where not created using the ARFF spec for this purpose.

Labels: Bug
⚠️ CI failed on Wheel builder ⚠️

**CI is still failing on [Wheel builder](https://github.com/scikit-learn/scikit-learn/actions/runs/3889482380)** (Jan 11, 2023)

COMMENT:
Apparently, it should be linked with https://github.com/scikit-learn/scikit-learn/pull/25062 where we start to raise an error if the `ConvergenceWarning` is raised. Quite fun to see that it happens only on the Windows builds from the wheel builder but we don't catch it in our normal test.

Labels: Needs Triage
Bisecting Kmeans predict and transform.argmin do not give same results

### Describe the bug

The bisecting KMeans algorithm does not give the same result when using `.predict(X)` and `.transform(X).argmin(1)`. 

I'm not sure what the desired output would be, and whether they should be equal. This, however, does go against how other clusterers (most notably the regular KMeans) work. I think the difference lies in the fact that the predict method works hierarchically through the original tree, while the transform method just calculates the euclidean distance between the terminal cluster centers.


### Steps/Code to Reproduce


```python
from sklearn.cluster import BisectingKMeans, KMeans
from sklearn.datasets import make_blobs

X, y = make_blobs(10000, random_state=44)

bs = BisectingKMeans(n_clusters=32)
bs.fit(X)

pred = bs.predict(X)
pred_2 = bs.transform(X).argmin(1)

# For comparison
km = KMeans(n_clusters=32)
km.fit(X)

pred_km = km.predict(X)
pred_km_2 = km.transform(X).argmin(1)

(pred == pred_2).all()  # False
(pred_km == pred_km_2).all()  # True
```

### Expected Results

pred and pred_2 should be equal I think.

### Actual Results

They are not equal, but pred_km and pred_km_2 are.

### Versions

```shell
System:
    python: 3.9.15 (main, Oct 11 2022, 21:39:54)  [Clang 14.0.0 (clang-1400.0.29.102)]
executable: /Users/stephantulkens/Documents/code/similarity/.venv/bin/python
   machine: macOS-12.5-arm64-arm-64bit

Python dependencies:
      sklearn: 1.2.0
          pip: 22.3.1
   setuptools: 65.6.3
        numpy: 1.24.1
        scipy: 1.9.3
       Cython: None
       pandas: 1.5.2
   matplotlib: 3.6.2
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libomp
       filepath: /Users/stephantulkens/Documents/code/similarity/.venv/lib/python3.9/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
    num_threads: 10

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/stephantulkens/Documents/code/similarity/.venv/lib/python3.9/site-packages/numpy/.dylibs/libopenblas64_.0.dylib
        version: 0.3.21
threading_layer: pthreads
   architecture: armv8
    num_threads: 10

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /Users/stephantulkens/Documents/code/similarity/.venv/lib/python3.9/site-packages/scipy/.dylibs/libopenblasp-r0.3.20.dylib
        version: 0.3.18
threading_layer: pthreads
   architecture: armv8
    num_threads: 10
```

COMMENT:
Since it's expected behavior and not a bug, let me convert this into a discussion

Labels: Bug, Needs Triage
RMSE using mean_squared_error does not return the correct value

### Describe the bug

The RMSE value obtained from mean_squared_error function with the squared parameter set to false return a different value compared to manually root the MSE obtained by the same function

### Steps/Code to Reproduce

```shell
from sklearn.metrics import mean_squared_error
import numpy as np
import math

# calculate All Relevant Metric
rmse = mean_squared_error(testy, ypred, squared=False)
mse = mean_squared_error(testy, ypred)
rmse2 = np.sqrt(mse)
rmse3 = math.sqrt(mse)

#Print All The Result
print(mse)
print(rmse)
print(rmse2)
print(rmse3)
```

### Expected Results

37384.461953883205
193.3506192229112
193.3506192229112
193.3506192229112

### Actual Results

37384.461953883205
78.94719343148691
193.3506192229112
193.3506192229112

### Versions

```shell
System:
    python: 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)]
executable: c:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\python.exe
   machine: Windows-10-10.0.22621-SP0

Python dependencies:
      sklearn: 1.2.0
          pip: 22.3.1
   setuptools: 58.1.0
        numpy: 1.24.1
        scipy: 1.9.3
       Cython: None
       pandas: 1.5.2
   matplotlib: 3.6.2
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 20

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 20

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\scipy.libs\libopenblas-57db09cfe174768fb409a6bb5a530d4c.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 20
```

COMMENT:
I cannot reproduce with actual data:

```python
import numpy as np
from sklearn.metrics import mean_squared_error

rng = np.random.default_rng(0)
y_true = rng.normal(size=10)
y_pred = rng.normal(size=10)

mse = mean_squared_error(y_true, y_pred)
rmse = mean_squared_error(y_true, y_pred, squared=False)

print(mse)
print(rmse)
print(np.sqrt(mse))
```

```
In [1]: %run tmp.py
2.2773552044822623
1.5090908536209018
1.5090908536209018
```

Labels: Bug, Needs Triage
RMSE using mean_squared_error does not return the correct value

### Describe the bug

The RMSE value obtained from mean_squared_error function with the squared parameter set to false return a different value compared to manually root the MSE obtained by the same function

### Steps/Code to Reproduce

```shell
from sklearn.metrics import mean_squared_error
import numpy as np
import math

# calculate All Relevant Metric
rmse = mean_squared_error(testy, ypred, squared=False)
mse = mean_squared_error(testy, ypred)
rmse2 = np.sqrt(mse)
rmse3 = math.sqrt(mse)

#Print All The Result
print(mse)
print(rmse)
print(rmse2)
print(rmse3)
```

### Expected Results

37384.461953883205
193.3506192229112
193.3506192229112
193.3506192229112

### Actual Results

37384.461953883205
78.94719343148691
193.3506192229112
193.3506192229112

### Versions

```shell
System:
    python: 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)]
executable: c:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\python.exe
   machine: Windows-10-10.0.22621-SP0

Python dependencies:
      sklearn: 1.2.0
          pip: 22.3.1
   setuptools: 58.1.0
        numpy: 1.24.1
        scipy: 1.9.3
       Cython: None
       pandas: 1.5.2
   matplotlib: 3.6.2
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 20

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
        version: 0.3.21
threading_layer: pthreads
   architecture: Haswell
    num_threads: 20

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\SRI-LAB-05\AppData\Local\Programs\Python\Python39\Lib\site-packages\scipy.libs\libopenblas-57db09cfe174768fb409a6bb5a530d4c.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 20
```

COMMENT:
@tgnazmi98 could you provide the `y_true` and `y_test`.

Labels: Bug, Needs Triage
_SetOutputMixin changes default order of inheritance

### Describe the bug

Inheriting from `TransformerMixin` now implicitly adds the wrapped `transform` method of superclass to subclasses and as a consequence can change the order in which multiple inheritance is resolved. 
This is caused by the `_SetOutputMixin.__init_subclass__`. 
I don't know if this is documented somewhere but it seems to me like a very tricky behavior that can cause a lot of headache to debug. 

### Steps/Code to Reproduce

```python
from sklearn.base import TransformerMixin

class Base(TransformerMixin):
    def transform(self, X):
        print('Base')

class A(Base):
    pass

class B(Base):
    def transform(self, X):
        print('B')

class C(A, B):
    pass


C().transform(None)
```

### Expected Results

code will print `B`

### Actual Results

code prints `Base`

### Versions

```shell
System:
    python: 3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:42:03) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\Josef.ondrej\Anaconda3\envs\example\python.exe
   machine: Windows-10-10.0.19045-SP0

Python dependencies:
      sklearn: 1.2.0
          pip: 22.3.1
   setuptools: 65.6.3
        numpy: 1.24.1
        scipy: 1.10.0
       Cython: None
       pandas: 1.5.2
   matplotlib: None
       joblib: 1.2.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: mkl
         prefix: libblas
       filepath: C:\Users\Josef.ondrej\Anaconda3\envs\example\Library\bin\libblas.dll
        version: 2022.1-Product
threading_layer: intel
    num_threads: 6

       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: C:\Users\Josef.ondrej\Anaconda3\envs\example\vcomp140.dll
        version: None
    num_threads: 12
```

COMMENT:
I agree that the behaviour is not intuitive.

I went a bit in to understand what was the issue. Basically, the MRO of `C` is the following:

```python
[
    <class '__main__.C'>,
    <class '__main__.A'>,
    <class '__main__.B'>,
    <class '__main__.Base'>,
    <class 'sklearn.base.TransformerMixin'>,
    <class 'sklearn.utils._set_output._SetOutputMixin'>,
    <class 'object'>,
]
```

In `__init_subclass__`, I assume that the `getattr(cls, method)` does not do what we expect because it will go through this MRO and the first `transform` method available is coming from `<class '__main__.A'>` because it inherits from `<class '__main__.Base'>` that expose a `transform` method.

It seems that when we wrap the method, we should not use `getattr` and not go recursively through MRO. We should instead go through the MRO classes and check if the specified class implement the requested method.

Labels: Bug