-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG+1] FIX Hash collisions in the FeatureHasher #7565
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d0ff000
HashingVectorizer: optionaly disable alternate signs
rth 0d9919f
HashingVectorizer updating documentation
rth 28d055f
Adding unit tests for non negative
rth 06779c0
Addressing review comments
rth 9329ba7
Adressing more review comments
rth 34f08a7
Missed a few review comments
rth 2b50a90
Adding an example that produces a hash collision
rth 1364bf3
Adding a alternate_sign parameter to the FeatureHasher
rth b960a19
Adding a mixed-sign test and deprecated directives
rth b390f4c
Added an entry in what's new
rth a85f1ab
Addressing review comments
rth 1e9da45
Merge branch 'master' into hashing_vect-nn
rth a28154c
Merge branch 'master' into hashing_vect-nn
rth f3e0d25
Fixed rst formatting
rth 2d5112e
Merge branch 'master' into hashing_vect-nn
rth c51b45b
Fixing review comments
rth b25e235
Merge branch 'hashing_vect-nn' of github.com:rth/scikit-learn into ha…
rth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,11 +404,20 @@ class HashingVectorizer(BaseEstimator, VectorizerMixin): | |
dtype : type, optional | ||
Type of the matrix returned by fit_transform() or transform(). | ||
|
||
non_negative : boolean, default=False | ||
Whether output matrices should contain non-negative values only; | ||
effectively calls abs on the matrix prior to returning it. | ||
When True, output values can be interpreted as frequencies. | ||
When False, output values will have expected value zero. | ||
alternate_sign : boolean, optional, default True | ||
When True, an alternating sign is added to the features as to | ||
approximately conserve the inner product in the hashed space even for | ||
small n_features. This approach is similar to sparse random projection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need a new feature (or feature added?) tag? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (has been addressed below) |
||
|
||
.. versionadded:: 0.19 | ||
|
||
non_negative : boolean, optional, default False | ||
When True, an absolute value is applied to the features matrix prior to | ||
returning it. When used in conjunction with alternate_sign=True, this | ||
significantly reduces the inner product preservation property. | ||
|
||
.. deprecated:: 0.19 | ||
This option will be removed in 0.21. | ||
|
||
See also | ||
-------- | ||
|
@@ -420,8 +429,8 @@ def __init__(self, input='content', encoding='utf-8', | |
lowercase=True, preprocessor=None, tokenizer=None, | ||
stop_words=None, token_pattern=r"(?u)\b\w\w+\b", | ||
ngram_range=(1, 1), analyzer='word', n_features=(2 ** 20), | ||
binary=False, norm='l2', non_negative=False, | ||
dtype=np.float64): | ||
binary=False, norm='l2', alternate_sign=True, | ||
non_negative=False, dtype=np.float64): | ||
self.input = input | ||
self.encoding = encoding | ||
self.decode_error = decode_error | ||
|
@@ -436,6 +445,7 @@ def __init__(self, input='content', encoding='utf-8', | |
self.ngram_range = ngram_range | ||
self.binary = binary | ||
self.norm = norm | ||
self.alternate_sign = alternate_sign | ||
self.non_negative = non_negative | ||
self.dtype = dtype | ||
|
||
|
@@ -496,6 +506,7 @@ def transform(self, X, y=None): | |
def _get_hasher(self): | ||
return FeatureHasher(n_features=self.n_features, | ||
input_type='string', dtype=self.dtype, | ||
alternate_sign=self.alternate_sign, | ||
non_negative=self.non_negative) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will raise a deprecation warning right? can you wrap it using
ignore_warnings(DeprecatedWarning)
maybe?