Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 20 commits into from
Jul 18, 2017

Conversation

sharanry
Copy link
Contributor

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.

@jnothman
Copy link
Member

Needs a test, thanks!

@sharanry
Copy link
Contributor Author

sharanry commented Jul 10, 2017

@jnothman
children, n_nodes, n_leaves, parent = assert_warns(UserWarning, linkage_tree, n_components=10)

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)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

@sharanry sharanry Jul 10, 2017

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 ?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@jnothman jnothman left a 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():
Copy link
Member

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]):
Copy link
Member

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)))


Copy link
Member

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

@sharanry
Copy link
Contributor Author

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

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)

Copy link
Member

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)

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

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.

@sharanry sharanry changed the title Issue 9307: DeprecationWarning for n_components parameter for linkage_tree [MRG] - DeprecationWarning for n_components parameter for linkage_tree Jul 10, 2017
Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jnothman jnothman changed the title [MRG] - DeprecationWarning for n_components parameter for linkage_tree [MRG+1] - DeprecationWarning for n_components parameter for linkage_tree Jul 11, 2017
@TomDLT
Copy link
Member

TomDLT commented Jul 18, 2017

Thanks @sharanry

@TomDLT TomDLT merged commit bd4953d into scikit-learn:master Jul 18, 2017
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request Aug 6, 2017
…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
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
…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
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
…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
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…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
AishwaryaRK pushed a commit to AishwaryaRK/scikit-learn that referenced this pull request Aug 29, 2017
…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
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…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
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

n_components parameter unused in linkage_tree
3 participants