Skip to content
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
Labels
Bug
Milestone

Comments

@luang008
Copy link
Contributor

@luang008 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 Preprocessing.normalize parameter "return_norm" raise UnboundLocalError for sparse matrix Preprocessing.normalize() with parameter "return_norm" raise UnboundLocalError for sparse matrix Oct 27, 2016
@luang008
Copy link
Contributor Author

@luang008 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
Copy link
Member

@amueller 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
Copy link
Contributor Author

@luang008 luang008 commented Oct 28, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.