MNT Import linear assignment from scipy#13465
Conversation
merge fork
merge fork
merge fork
| as the algorithm incorporated in SciPy will be used instead. | ||
|
|
||
| """ | ||
| # Based on original code by Brain Clapper, adapted to NumPy by Gael Varoquaux. |
There was a problem hiding this comment.
please use the warnings module to raise a deprecation warning here (so that it appears whenever the module is imported)
| @@ -4,7 +4,7 @@ | |||
| import numpy as np | |||
There was a problem hiding this comment.
we don't need this file. It can be removed entirely. Scipy tests their implementation.
There was a problem hiding this comment.
Actually let's leave it in to maintain code coverage. Use the version in master, only changing it to ignore deprecation warnings during import. That way we will be sure to remove it in 0.23.
sklearn/utils/linear_assignment_.py
Outdated
| # Deprecation warning for module | ||
| warnings.warn( | ||
| "This module is deprecated in 0.21 and will removed from 0.23 " | ||
| "as the algorithm incorporated in SciPy will be used instead.", ImportWarning) |
There was a problem hiding this comment.
Use a DeprecationWarning, rather
jnothman
left a comment
There was a problem hiding this comment.
Sorry, that was in response to an old change.
| import numpy as np | ||
|
|
||
| # XXX we should be testing the public API here | ||
| from sklearn.utils.linear_assignment_ import _hungarian |
There was a problem hiding this comment.
you need to ignore the warning here too.. or just put the import inside the test function
There was a problem hiding this comment.
moved the import inside test function
|
|
||
| import numpy as np | ||
|
|
||
| # XXX we should be testing the public API here |
There was a problem hiding this comment.
Remove this and the spare blank lines
| # License: BSD | ||
|
|
||
| import numpy as np | ||
| # TODO: Remove this test module as the methods being tested |
There was a problem hiding this comment.
Please add a line above with # 0.23 so we know when to remove this file
sklearn/utils/linear_assignment_.py
Outdated
| the original ordering. | ||
| """ | ||
| warnings.warn( | ||
| "This method is deprecated in 0.21 and will removed from 0.23 " |
There was a problem hiding this comment.
Maybe indicate the function name and what to use instead:
The linear_assignment function is deprecated [...] Use scipy.optimize.linear_sum_assignment instead
sklearn/utils/linear_assignment_.py
Outdated
|
|
||
| # Deprecation warning for module | ||
| warnings.warn( | ||
| "This module is deprecated in 0.21 and will removed from 0.23 " |
There was a problem hiding this comment.
| "This module is deprecated in 0.21 and will removed from 0.23 " | |
| "The linear_assignment_ module is deprecated in 0.21 and will removed from 0.23 " |
sklearn/metrics/cluster/bicluster.py
Outdated
| similarity = _jaccard | ||
| matrix = _pairwise_similarity(a, b, similarity) | ||
| indices = linear_assignment(1. - matrix) | ||
| row, col = linear_sum_assignment(1. - matrix) |
There was a problem hiding this comment.
| row, col = linear_sum_assignment(1. - matrix) | |
| row_indices, col_indices = linear_sum_assignment(1. - matrix) |
sklearn/metrics/cluster/bicluster.py
Outdated
|
|
||
| from sklearn.utils.linear_assignment_ import linear_assignment | ||
| from scipy.optimize import linear_sum_assignment | ||
| from sklearn.utils.validation import check_consistent_length, check_array |
There was a problem hiding this comment.
It's not you, but can you please change this toa relative import:
from ...utils.validation import check_consistent_length, check_array
Also Nitpick for pep8 compliance: the scipy import should be right below the numpy import, and there should be a blank line before the sklearn import:
import numpy as np
from scipy.optimize import linear_sum_assignment
from ...utils.validation import check_consistent_length, check_array
sklearn/utils/linear_assignment_.py
Outdated
| the original ordering. | ||
| """ | ||
| warnings.warn( | ||
| "The _hungarian function is deprecated in 0.21 " |
There was a problem hiding this comment.
| "The _hungarian function is deprecated in 0.21 " | |
| "The linear_assignment function is deprecated in 0.21 " |
NicolasHug
left a comment
There was a problem hiding this comment.
Last comment, LGTM, thanks @praths007
sklearn/utils/linear_assignment_.py
Outdated
|
|
||
| # Deprecation warning for module | ||
| warnings.warn( | ||
| "The linear_assignment function is deprecated in 0.21 " |
There was a problem hiding this comment.
| "The linear_assignment function is deprecated in 0.21 " | |
| "The linear_assignment_ module is deprecated in 0.21 " |
|
Thanks @praths007 |
This reverts commit a57cd4e.
This reverts commit a57cd4e.
Reference Issues/PRs
linear_assignment can now be imported from scipy #13464
What does this implement/fix? Explain your changes.
Removed the use of sklearn.utils.linear_assignment_ and _hungarian and replaced it with scipy.optimize.linear_sum_assignment
Tweaked test case for _hungarian so that it works with scipy.optimize.linear_sum_assignment
Any other comments?
more info can be found here #13464