-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG+1] - DeprecationWarning for n_components parameter for linkage_tree #9309
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
Conversation
Update from base Jul-04-2017
Change 10JUL2017
Needs a test, thanks! |
@jnothman Why can't i use this as a test? |
@@ -44,6 +44,9 @@ def test_linkage_misc(): | |||
assert_raises(ValueError, linkage_tree, X, linkage='foo') | |||
assert_raises(ValueError, linkage_tree, X, connectivity=np.ones((4, 4))) | |||
|
|||
# Test for warning of deprecation of n_components in linkage_tree | |||
children, n_nodes, n_leaves, parent = assert_warns(UserWarning, linkage_tree, n_components=10) |
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.
Put it in a separate test function, please. You should probably assert that output is identical to without the n_components.
with ignore_warnings(): | ||
# Test for warning of deprecation of n_components in linkage_tree | ||
children, n_nodes, n_leaves, parent = assert_warns(DeprecationWarning, linkage_tree,this_X.T, n_components=10) | ||
children1, n_nodes1, n_leaves1, parent1 = linkage_tree(this_X.T, n_components=10) |
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.
What's the point in this line?
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.
Without it, you shouldn't need the ignore_warnings
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.
To compare the output with and without n_components. To make sure it's same.. is it not required ?
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.
The previous line will calculate the same. As long as we believe assert_warns works, and we do
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.
i have removed the lines and i have made it check only for the warning.
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.
Almost there
def test_deprecation_of_n_components_in_linkage_tree(): | ||
rng = np.random.RandomState(0) | ||
X = rng.randn(50, 100) | ||
for tree_builder in _TREE_BUILDERS.values(): |
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 variable is unused in the loop
rng = np.random.RandomState(0) | ||
X = rng.randn(50, 100) | ||
for tree_builder in _TREE_BUILDERS.values(): | ||
for this_X in (X, X[0]): |
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.
Testing with X alone is fine
@@ -44,6 +56,7 @@ def test_linkage_misc(): | |||
assert_raises(ValueError, linkage_tree, X, linkage='foo') | |||
assert_raises(ValueError, linkage_tree, X, connectivity=np.ones((4, 4))) | |||
|
|||
|
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.
Please remove this blank line
@jnothman All checks have passed. Please take a look. TIA! |
X = rng.randn(50, 100) | ||
# Test for warning of deprecation of n_components in linkage_tree | ||
children, n_nodes, n_leaves, parent = assert_warns( | ||
DeprecationWarning, |
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 indentation is a bit unconventional
linkage_tree, | ||
X.T, | ||
n_components=10) | ||
|
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.
I had suggested comparing children, n_nodes, n_leaves, parent
to linkage_tree(X.T)
sklearn/cluster/hierarchical.py
Outdated
@@ -365,6 +365,10 @@ def linkage_tree(X, connectivity=None, n_components=None, | |||
-------- | |||
ward_tree : hierarchical clustering with ward linkage | |||
""" | |||
if n_components is not None: |
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.
To be sure, we should really be testing against a different value, like if n_components != 'deprecated'
and setting the default to 'deprecated'
so that a user explicitly passing None will receive the warning.
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.
LGTM
Thanks @sharanry |
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
…ree (scikit-learn#9309) * Depreciation warning for n_components in sklearn/cluster/hierarchical.py * typo fix * Whitespace fix * Update hierarchical.py * Added test * Added test-v2 * Test for deprecation * Test function name change * Updated test * Update test_hierarchical.py * fixing flake8 errors * removed blank line * modifying test * Change condition for deprecation warning * Change indentation and compare function output * fix flake8 errors * Update test_hierarchical.py
Reference Issue
Fixes #9307
What does this implement/fix? Explain your changes.
Adds DeprecationWarning to n_components parameter which is no longer being used in linkage_tree function.
Any other comments?
No.