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

Preprocessing.normalize() with parameter "return_norm" raise UnboundLocalError for sparse matrix #7771

Closed
luang008 opened this Issue Oct 27, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@luang008
Contributor

luang008 commented Oct 27, 2016

Description

UnboundLocalError raised when using preprocessing.normalize with parameter "return_norm=True".

Steps/Code to Reproduce

import numpy as np
from scipy.sparse import csr_matrix
from sklearn import preprocessing

rows = [1,2]
cols = [1,2]
vals = [1,2]
mat = csr_matrix((vals,(rows,cols)),shape=(3,3))
normed_mat, norm = preprocessing.normalize(mat,return_norm=True)

Expected Results

NotImplementedError raised for sparse matrix or support returning norms for sparse matrix.

Actual Results

"UnboundLocalError: local variable 'norms' referenced before assignment"

Versions

0.18

@luang008 luang008 changed the title from Preprocessing.normalize parameter "return_norm" raise UnboundLocalError for sparse matrix to Preprocessing.normalize() with parameter "return_norm" raise UnboundLocalError for sparse matrix Oct 27, 2016

@luang008

This comment has been minimized.

Show comment
Hide comment
@luang008

luang008 Oct 27, 2016

Contributor

Seems that this is new for version 0.18. Preprocessing.normalize() in version 0.16.1 doesn't have parameter "return_norm". The normalization for sparse matrix is handled by "inplace_csr_row_normalize_l2" function. That's how the error is raised.

Contributor

luang008 commented Oct 27, 2016

Seems that this is new for version 0.18. Preprocessing.normalize() in version 0.16.1 doesn't have parameter "return_norm". The normalization for sparse matrix is handled by "inplace_csr_row_normalize_l2" function. That's how the error is raised.

@amueller

This comment has been minimized.

Show comment
Hide comment
@amueller

amueller Oct 27, 2016

Member

I guess we should add

norms = NotImplemented

at the beginning of the issparse block. Do you want to create a PR with a test?

Member

amueller commented Oct 27, 2016

I guess we should add

norms = NotImplemented

at the beginning of the issparse block. Do you want to create a PR with a test?

@luang008

This comment has been minimized.

Show comment
Hide comment
@luang008

luang008 Oct 28, 2016

Contributor

Sure. Sounds like a good plan for this Saturday afternoon.

Contributor

luang008 commented Oct 28, 2016

Sure. Sounds like a good plan for this Saturday afternoon.

@jnothman jnothman added this to the 0.18.1 milestone Oct 29, 2016

@jnothman jnothman added the Bug label Oct 29, 2016

@jnothman jnothman closed this in #7789 Nov 22, 2016

jnothman added a commit that referenced this issue Nov 22, 2016

adis300 added a commit to adis300/scikit-learn that referenced this issue Dec 13, 2016

sergeyf added a commit to sergeyf/scikit-learn that referenced this issue Feb 28, 2017

Sundrique added a commit to Sundrique/scikit-learn that referenced this issue Jun 14, 2017

NelleV added a commit to NelleV/scikit-learn that referenced this issue Aug 11, 2017

paulha added a commit to paulha/scikit-learn that referenced this issue Aug 19, 2017

maskani-moh added a commit to maskani-moh/scikit-learn that referenced this issue Nov 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment