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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sklearn/cluster/hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def ward_tree(X, connectivity=None, n_clusters=None, return_distance=False):


# average and complete linkage
def linkage_tree(X, connectivity=None, n_components=None,
def linkage_tree(X, connectivity=None, n_components='deprecated',
n_clusters=None, linkage='complete', affinity="euclidean",
return_distance=False):
"""Linkage agglomerative clustering based on a Feature matrix.
Expand Down Expand Up @@ -365,6 +365,10 @@ def linkage_tree(X, connectivity=None, n_components=None,
--------
ward_tree : hierarchical clustering with ward linkage
"""
if n_components != 'deprecated':
warnings.warn("n_components was deprecated in 0.18"
"will be removed in 0.21", DeprecationWarning)

X = np.asarray(X)
if X.ndim == 1:
X = np.reshape(X, (-1, 1))
Expand Down
14 changes: 14 additions & 0 deletions sklearn/cluster/tests/test_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
from sklearn.utils.testing import assert_warns


def test_deprecation_of_n_components_in_linkage_tree():
rng = np.random.RandomState(0)
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,
linkage_tree,
X.T,
n_components=10)
children_t, n_nodes_t, n_leaves_t, parent_t = linkage_tree(X.T)
assert_array_equal(children, children_t)
assert_equal(n_nodes, n_nodes_t)
assert_equal(n_leaves, n_leaves_t)
assert_equal(parent, parent_t)

def test_linkage_misc():
# Misc tests on linkage
rng = np.random.RandomState(42)
Expand Down