Talip7/scikit-learn-issues-multilabel huggingface dataset:
kernel_approximation.Nystroem with precomputed kernel

### Describe the bug

I am trying to get a Nystroem approximation of a pre computed kernel but it throws an error if I use n_components anything less than the number of datapoints. Unless my understanding is wrong, does this not defeat the point of the approximation? Please advise, code below:



I have come from this resolved issue https://github.com/scikit-learn/scikit-learn/issues/14641 

### Steps/Code to Reproduce

```python
from sklearn.svm import SVC
from sklearn.kernel_approximation import Nystroem
 
# data shape (3000,50)
# kernel matrix shape (3000,3000)
clf = SVC()
feature_map_nystroem = Nystroem(
    kernel = 'precomputed',
    random_state=1,
    n_components=300
)
kernel_transformed = feature_map_nystroem.fit_transform(kernel)
clf.fit(kernel_transformed, y)
```



### Expected Results

I expect this to work. 

### Actual Results

Instead it gives error:

```python
in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy)
    153 if precomputed:
    154     if X.shape[1] != Y.shape[0]:
--> 155 raise ValueError("Precomputed metric requires shape "

    156                 "(n_queries, n_indexed). Got (%d, %d) "
    157                          "for %d indexed." %
    158                          (X.shape[0], X.shape[1], Y.shape[0]))
    159 elif X.shape[1] != Y.shape[1]:
    160     raise ValueError("Incompatible dimension for X and Y matrices: "
    161                      "X.shape[1] == %d while Y.shape[1] == %d" % (
    162                          X.shape[1], Y.shape[1]))
 
ValueError: Precomputed metric requires shape (n_queries, n_indexed). Got (300, 3000) for 300 indexed.
```

### Versions

```shell
System:
    python: 3.8.19 (default, Mar 20 2024, 19:58:24)  [GCC 11.2.0]
executable: /opt/conda/miniconda3/envs/python3.8/bin/python
   machine: Linux-6.1.0-21-cloud-amd64-x86_64-with-glibc2.17
 
Python dependencies:
          pip: 24.0
   setuptools: 63.1.0
      sklearn: 0.24.2
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 3.0.10
       pandas: 1.2.5
   matplotlib: 3.4.3
       joblib: 1.4.2
threadpoolctl: 3.5.0
```

COMMENT:
Thanks for reporting this.

Two questions: you are using a fairly old version of scikit-learn, does the problem also occur with the latest released version? Can you please provide a minimal code snippet that reproduces the problem (this will help with reproducing and debugging the issue)?

Labels: Bug
kernel_approximation.Nystroem with precomputed kernel

### Describe the bug

I am trying to get a Nystroem approximation of a pre computed kernel but it throws an error if I use n_components anything less than the number of datapoints. Unless my understanding is wrong, does this not defeat the point of the approximation? Please advise, code below:



I have come from this resolved issue https://github.com/scikit-learn/scikit-learn/issues/14641 

### Steps/Code to Reproduce

```python
from sklearn.svm import SVC
from sklearn.kernel_approximation import Nystroem
 
# data shape (3000,50)
# kernel matrix shape (3000,3000)
clf = SVC()
feature_map_nystroem = Nystroem(
    kernel = 'precomputed',
    random_state=1,
    n_components=300
)
kernel_transformed = feature_map_nystroem.fit_transform(kernel)
clf.fit(kernel_transformed, y)
```



### Expected Results

I expect this to work. 

### Actual Results

Instead it gives error:

```python
in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy)
    153 if precomputed:
    154     if X.shape[1] != Y.shape[0]:
--> 155 raise ValueError("Precomputed metric requires shape "

    156                 "(n_queries, n_indexed). Got (%d, %d) "
    157                          "for %d indexed." %
    158                          (X.shape[0], X.shape[1], Y.shape[0]))
    159 elif X.shape[1] != Y.shape[1]:
    160     raise ValueError("Incompatible dimension for X and Y matrices: "
    161                      "X.shape[1] == %d while Y.shape[1] == %d" % (
    162                          X.shape[1], Y.shape[1]))
 
ValueError: Precomputed metric requires shape (n_queries, n_indexed). Got (300, 3000) for 300 indexed.
```

### Versions

```shell
System:
    python: 3.8.19 (default, Mar 20 2024, 19:58:24)  [GCC 11.2.0]
executable: /opt/conda/miniconda3/envs/python3.8/bin/python
   machine: Linux-6.1.0-21-cloud-amd64-x86_64-with-glibc2.17
 
Python dependencies:
          pip: 24.0
   setuptools: 63.1.0
      sklearn: 0.24.2
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 3.0.10
       pandas: 1.2.5
   matplotlib: 3.4.3
       joblib: 1.4.2
threadpoolctl: 3.5.0
```

COMMENT:
I have upgraded  sklearn and python to 1.5.0 and 3.11 respectively and still the same error persists

Here’s some code that reproduces the error 

```python
from sklearn.svm import SVC
from sklearn.kernel_approximation import Nystroem
from sklearn import datasets
from sklearn.metrics.pairwise import rbf_kernel

X, y = datasets.load_digits(n_class=9, return_X_y=True)
data = X / 16.
kernel = rbf_kernel(data)

clf = SVC()
feature_map_nystroem = Nystroem(
    kernel = 'precomputed',
    random_state=1,
    n_components=100
)
kernel_transformed = feature_map_nystroem.fit_transform(kernel)
clf.fit(kernel_transformed, y)
```

Labels: Bug
kernel_approximation.Nystroem with precomputed kernel

### Describe the bug

I am trying to get a Nystroem approximation of a pre computed kernel but it throws an error if I use n_components anything less than the number of datapoints. Unless my understanding is wrong, does this not defeat the point of the approximation? Please advise, code below:



I have come from this resolved issue https://github.com/scikit-learn/scikit-learn/issues/14641 

### Steps/Code to Reproduce

```python
from sklearn.svm import SVC
from sklearn.kernel_approximation import Nystroem
 
# data shape (3000,50)
# kernel matrix shape (3000,3000)
clf = SVC()
feature_map_nystroem = Nystroem(
    kernel = 'precomputed',
    random_state=1,
    n_components=300
)
kernel_transformed = feature_map_nystroem.fit_transform(kernel)
clf.fit(kernel_transformed, y)
```



### Expected Results

I expect this to work. 

### Actual Results

Instead it gives error:

```python
in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy)
    153 if precomputed:
    154     if X.shape[1] != Y.shape[0]:
--> 155 raise ValueError("Precomputed metric requires shape "

    156                 "(n_queries, n_indexed). Got (%d, %d) "
    157                          "for %d indexed." %
    158                          (X.shape[0], X.shape[1], Y.shape[0]))
    159 elif X.shape[1] != Y.shape[1]:
    160     raise ValueError("Incompatible dimension for X and Y matrices: "
    161                      "X.shape[1] == %d while Y.shape[1] == %d" % (
    162                          X.shape[1], Y.shape[1]))
 
ValueError: Precomputed metric requires shape (n_queries, n_indexed). Got (300, 3000) for 300 indexed.
```

### Versions

```shell
System:
    python: 3.8.19 (default, Mar 20 2024, 19:58:24)  [GCC 11.2.0]
executable: /opt/conda/miniconda3/envs/python3.8/bin/python
   machine: Linux-6.1.0-21-cloud-amd64-x86_64-with-glibc2.17
 
Python dependencies:
          pip: 24.0
   setuptools: 63.1.0
      sklearn: 0.24.2
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 3.0.10
       pandas: 1.2.5
   matplotlib: 3.4.3
       joblib: 1.4.2
threadpoolctl: 3.5.0
```

COMMENT:
Thanks for the reproducer. I get the same results as you. However, I don't know enough about the Nystroem implementation to help solve this. Let's see if we can find someone who does know more about this.

I am not even sure I know how exactly to use `Nystroem` with a precomputed kernel.

Labels: Bug
kernel_approximation.Nystroem with precomputed kernel

### Describe the bug

I am trying to get a Nystroem approximation of a pre computed kernel but it throws an error if I use n_components anything less than the number of datapoints. Unless my understanding is wrong, does this not defeat the point of the approximation? Please advise, code below:



I have come from this resolved issue https://github.com/scikit-learn/scikit-learn/issues/14641 

### Steps/Code to Reproduce

```python
from sklearn.svm import SVC
from sklearn.kernel_approximation import Nystroem
 
# data shape (3000,50)
# kernel matrix shape (3000,3000)
clf = SVC()
feature_map_nystroem = Nystroem(
    kernel = 'precomputed',
    random_state=1,
    n_components=300
)
kernel_transformed = feature_map_nystroem.fit_transform(kernel)
clf.fit(kernel_transformed, y)
```



### Expected Results

I expect this to work. 

### Actual Results

Instead it gives error:

```python
in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy)
    153 if precomputed:
    154     if X.shape[1] != Y.shape[0]:
--> 155 raise ValueError("Precomputed metric requires shape "

    156                 "(n_queries, n_indexed). Got (%d, %d) "
    157                          "for %d indexed." %
    158                          (X.shape[0], X.shape[1], Y.shape[0]))
    159 elif X.shape[1] != Y.shape[1]:
    160     raise ValueError("Incompatible dimension for X and Y matrices: "
    161                      "X.shape[1] == %d while Y.shape[1] == %d" % (
    162                          X.shape[1], Y.shape[1]))
 
ValueError: Precomputed metric requires shape (n_queries, n_indexed). Got (300, 3000) for 300 indexed.
```

### Versions

```shell
System:
    python: 3.8.19 (default, Mar 20 2024, 19:58:24)  [GCC 11.2.0]
executable: /opt/conda/miniconda3/envs/python3.8/bin/python
   machine: Linux-6.1.0-21-cloud-amd64-x86_64-with-glibc2.17
 
Python dependencies:
          pip: 24.0
   setuptools: 63.1.0
      sklearn: 0.24.2
        numpy: 1.21.6
        scipy: 1.10.1
       Cython: 3.0.10
       pandas: 1.2.5
   matplotlib: 3.4.3
       joblib: 1.4.2
threadpoolctl: 3.5.0
```

COMMENT:
Not sure if I understand the implementation of Nystroem.

For the precomputed case, in L1018 below, perhaps we also sample the columns of X to get a smaller kernel matrix. I think this will satisfy `check_pairwise_arrays`.
https://github.com/scikit-learn/scikit-learn/blob/53ed13cc3d4ea385d72c8799552b7cd7a97d3c86/sklearn/kernel_approximation.py#L1016-L1026

Labels: Bug
DOC Broken link: Working with Text Data Tutorial Setup

### Describe the issue linked to the documentation

In the setup section of the [Working With Text Data](https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html) tutorial, it says: 

The source of this tutorial can be found within your scikit-learn folder:
`scikit-learn/doc/tutorial/text_analytics/`
The source can also be found [on Github](https://github.com/scikit-learn/scikit-learn/tree/main/doc/tutorial/text_analytics).

However, the `doc/tutorial` folder has been deleted (#29104), so both of these instructions are broken. 

### Suggest a potential alternative/fix

Either put the required data back in the repository somewhere, or adjust the tutorial so that there is no longer any references to this setup. The only parts of the tutorial which really require the setup are the exercises, which refer to running on the dataset created from `scikit-learn/doc/tutorial/text_analytics/data/languages/fetch_data.py`.

COMMENT:
Hi @jaderrrr, The data has been removed in the development version of scikit-learn (1.6.0dev0) but you're following the documention of the stable version (1.5.0). This tutorial has actually been removed as well in the doc of the dev version (https://scikit-learn.org/dev/). If you still want to follow this tutorial I would suggest `git checkout 1.5.0` or retrieve the data on github, in the 1.5.X branch (https://github.com/scikit-learn/scikit-learn/tree/1.5.X/doc/tutorial). Note that these tutorial haven't been maintainted in a while so they might use an outdated API and not work anymore.

Labels: Documentation
DOC Broken link: Working with Text Data Tutorial Setup

### Describe the issue linked to the documentation

In the setup section of the [Working With Text Data](https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html) tutorial, it says: 

The source of this tutorial can be found within your scikit-learn folder:
`scikit-learn/doc/tutorial/text_analytics/`
The source can also be found [on Github](https://github.com/scikit-learn/scikit-learn/tree/main/doc/tutorial/text_analytics).

However, the `doc/tutorial` folder has been deleted (#29104), so both of these instructions are broken. 

### Suggest a potential alternative/fix

Either put the required data back in the repository somewhere, or adjust the tutorial so that there is no longer any references to this setup. The only parts of the tutorial which really require the setup are the exercises, which refer to running on the dataset created from `scikit-learn/doc/tutorial/text_analytics/data/languages/fetch_data.py`.

COMMENT:
Thanks @jeremiedbb, I will do that :)

Labels: Documentation
DOC Broken link: Working with Text Data Tutorial Setup

### Describe the issue linked to the documentation

In the setup section of the [Working With Text Data](https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html) tutorial, it says: 

The source of this tutorial can be found within your scikit-learn folder:
`scikit-learn/doc/tutorial/text_analytics/`
The source can also be found [on Github](https://github.com/scikit-learn/scikit-learn/tree/main/doc/tutorial/text_analytics).

However, the `doc/tutorial` folder has been deleted (#29104), so both of these instructions are broken. 

### Suggest a potential alternative/fix

Either put the required data back in the repository somewhere, or adjust the tutorial so that there is no longer any references to this setup. The only parts of the tutorial which really require the setup are the exercises, which refer to running on the dataset created from `scikit-learn/doc/tutorial/text_analytics/data/languages/fetch_data.py`.

COMMENT:
I'm wondering if we should do a redirection.

Labels: Documentation
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
Hi @bme-git, I don't think that there's a contradiction here. The user guide (https://scikit-learn.org/stable/modules/svm.html) doesn't state that "ovo" is the default, just that it's a possibility. Maybe it could be reworked a bit to make it clearer and start by presenting the default, and then comparing with the alternative. Would you be interested in opening a PR ?

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
Hi @jeremiedbb, thank you for the comment. I read both documentation parts again and agree with you (I was probably too reading too fast the first time). I think it would be good to add to the text to mention the default assignment (which is not ovo).

Proposal: _To provide a consistent interface with other classifiers, the decision_function_shape option allows to monotonically transform the results of the “one-versus-one” classifiers to a “one-vs-rest” decision function of shape (n_samples, n_classes), **which is the default setting of the parameter (default=’ovr’)**._ 

Regarding the PR - you would probably have to guide me.

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
I've added the "good first issue" label to highlight this issue to people who want to make their first contribution. If you want to tackle it @bme-git that would be great, but if not - no worries.

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
@betatim In case @bme-git does not want to tackle it, I'd like to take over :)

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
I'm in, but I have to set up git etc. first. I like to use this for learning.

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
hello is this  issue still open ?

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
I’d like to work on this; PR coming shortly if that’s OK.

Labels: Documentation, good first issue
Support Vector Machines - Multi-class classification --> wrong default approach

### Describe the issue linked to the documentation

Documentation on main page for Support Vector Machines (https://scikit-learn.org/stable/modules/svm.html) seems to be outdated. Under 1.4.1.1 it says: _**SVC and NuSVC implement the “one-versus-one” approach for multi-class classification.**_

The documentation of SVC (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC) correctly states 'ovr' as default for 'decision_function_shape': _**decision_function_shape{‘ovo’, ‘ovr’}, default=’ovr’**_

### Suggest a potential alternative/fix

Revision of the documentation with updated default approach for SVC.

COMMENT:
@Kalyan1210 this issue is closed, the original author already submitted a PR to improve the doc to make it clearer which option is the default.

Labels: Documentation, good first issue
BUG: Stable docs intersphinx has a duplicate std:term:y

When building with intersphinx we get a warning which you can replicate with `intersphinx` directly
```
$ python -m sphinx.ext.intersphinx https://scikit-learn.org/stable/objects.inv | grep "    y "
WARNING:sphinx.sphinx.util.inventory:inventory <> contains multiple definitions for std:term:y
    y                                                                                : glossary.html#term-y
```
Only one term shows up in the `grep` presumably because intersphinx chooses one of the two, but the `WARNING` line actually shows up in doc builds.

COMMENT:
Thanks for reporting this. Could this be because https://github.com/scikit-learn/scikit-learn/blob/main/doc/glossary.rst defines an entry for both `y` and `Y`?

Labels: Needs Triage