8000 [BUG] Underflows in LabelPropagation and LabelSpreading should be ignored. · Issue #9313 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[BUG] Underflows in LabelPropagation and LabelSpreading should be ignored. #9313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
musically-ut opened this issue Jul 10, 2017 · 3 comments
Closed

Comments

@musically-ut
Copy link
Contributor

Description

LabelPropagation with the rbf kernel should ignore underflow errors.

Steps/Code to Reproduce

Example taken from #9292.

from sklearn.datasets import fetch_mldata
from sklearn.semi_supervised import label_propagation
import numpy

numpy.seterr(all='raise')

mnist = fetch_mldata('MNIST original', data_home="./tmp")

X = mnist.data[1:10000]
y = mnist.target[1:10000]

# Use only 300 labeled examples
y[300:] = -1

lp_model = label_propagation.LabelSpreading(kernel='rbf', n_neighbors=7, n_jobs=-1)
lp_model.fit(X,y)

Expected Results

No error should be thrown.

Actual Results

Traceback (most recent call last):
  File "reproduce.py", line 21, in <module>
    lp_model.fit(X,y)
  File "/share/mug/gentoo/anaconda3/envs/ssl-py3/lib/python3.6/site-packages/sklearn/semi_supervised/label_propagation.py", line 234, in fit
    graph_matrix = self._build_graph()
  File "/share/mug/gentoo/anaconda3/envs/ssl-py3/lib/python3.6/site-packages/sklearn/semi_supervised/label_propagation.py", line 511, in _build_graph
    affinity_matrix = self._get_kernel(self.X_)
  File "/share/mug/gentoo/anaconda3/envs/ssl-py3/lib/python3.6/site-packages/sklearn/semi_supervised/label_propagation.py", line 131, in _get_kernel
    return rbf_kernel(X, X, gamma=self.gamma)
  File "/share/mug/gentoo/anaconda3/envs/ssl-py3/lib/python3.6/site-packages/sklearn/metrics/pairwise.py", line 837, in rbf_kernel
    np.exp(K, K)    # exponentiate K in-place
FloatingPointError: underflow encountered in exp
@warut-vijit
Copy link
Contributor

claiming for now unless this has already been solved @musically-ut

@musically-ut
Copy link
Contributor Author

You have a 'Go ahead' from my side. 👍

@jjerphan
Copy link
Member

I cannot reproduce:

import numpy
from sklearn.datasets import fetch_openml
from sklearn.semi_supervised import LabelSpreading

numpy.seterr(all='raise')

X, y = fetch_openml('mnist_784', version=1, return_X_y=True, as_frame=False)
X = X[1:10000]
y = y[1:10000].astype(int)

# Use only 300 labeled examples
y[300:] = -1
lp_model = LabelSpreading(kernel='rbf', n_neighbors=7, n_jobs=-1)

# Completes correctly
lp_model.fit(X,y)

This was fixed by #19271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
0