File tree
3 files changed
+74
-8
lines changed- doc/whats_new
- sklearn/cluster
- tests
3 files changed
+74
-8
lines changedLines changed: 12 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
70 | 70 |
| |
71 | 71 |
| |
72 | 72 |
| |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
73 | 82 |
| |
74 | 83 |
| |
75 |
| - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
76 | 87 |
| |
77 | 88 |
| |
78 | 89 |
| |
|
Lines changed: 31 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
747 | 747 |
| |
748 | 748 |
| |
749 | 749 |
| |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
750 | 757 |
| |
751 | 758 |
| |
752 | 759 |
| |
| |||
776 | 783 |
| |
777 | 784 |
| |
778 | 785 |
| |
779 |
| - | |
| 786 | + | |
| 787 | + | |
780 | 788 |
| |
781 | 789 |
| |
782 | 790 |
| |
| |||
795 | 803 |
| |
796 | 804 |
| |
797 | 805 |
| |
798 |
| - | |
| 806 | + | |
| 807 | + | |
799 | 808 |
| |
800 | 809 |
| |
801 | 810 |
| |
802 | 811 |
| |
803 | 812 |
| |
804 | 813 |
| |
805 | 814 |
| |
| 815 | + | |
806 | 816 |
| |
807 | 817 |
| |
808 | 818 |
| |
| |||
879 | 889 |
| |
880 | 890 |
| |
881 | 891 |
| |
882 |
| - | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
883 | 896 |
| |
884 | 897 |
| |
885 | 898 |
| |
| |||
891 | 904 |
| |
892 | 905 |
| |
893 | 906 |
| |
| 907 | + | |
| 908 | + | |
894 | 909 |
| |
895 | 910 |
| |
896 |
| - | |
| 911 | + | |
897 | 912 |
| |
898 | 913 |
| |
899 | 914 |
| |
| |||
999 | 1014 |
| |
1000 | 1015 |
| |
1001 | 1016 |
| |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
1002 | 1024 |
| |
1003 | 1025 |
| |
1004 | 1026 |
| |
| |||
1028 | 1050 |
| |
1029 | 1051 |
| |
1030 | 1052 |
| |
1031 |
| - | |
| 1053 | + | |
| 1054 | + | |
1032 | 1055 |
| |
1033 | 1056 |
| |
1034 | 1057 |
| |
| |||
1049 | 1072 |
| |
1050 | 1073 |
| |
1051 | 1074 |
| |
1052 |
| - | |
| 1075 | + | |
1053 | 1076 |
| |
1054 | 1077 |
| |
1055 | 1078 |
| |
1056 |
| - | |
| 1079 | + | |
| 1080 | + | |
1057 | 1081 |
| |
1058 | 1082 |
| |
1059 | 1083 |
| |
|
Lines changed: 31 additions & 0 deletions
@@ -143,6 +143,37 @@ def test_zero_cosine_linkage_tree():
143
143
assert_raise_message(ValueError, msg, linkage_tree, X, affinity='cosine')
144
144
145
145
146
+@pytest.mark.parametrize('n_clusters, distance_threshold',
147
+ [(None, 0.5), (10, None)])
148
+@pytest.mark.parametrize('compute_distances', [True, False])
149
+@pytest.mark.parametrize('linkage', ["ward", "complete", "average", "single"])
150
+def test_agglomerative_clustering_distances(n_clusters,
151
+ compute_distances,
152
+ distance_threshold,
153
+ linkage):
154
+ # Check that when `compute_distances` is True or `distance_threshold` is
155
+ # given, the fitted model has an attribute `distances_`.
156
+ rng = np.random.RandomState(0)
157
+ mask = np.ones([10, 10], dtype=bool)
158
+ n_samples = 100
159
+ X = rng.randn(n_samples, 50)
160
+ connectivity = grid_to_graph(*mask.shape)
161
+
162
+ clustering = AgglomerativeClustering(n_clusters=n_clusters,
163
+ connectivity=connectivity,
164
+ linkage=linkage,
165
+ distance_threshold=distance_threshold,
166
+ compute_distances=compute_distances)
167
+ clustering.fit(X)
168
+ if compute_distances or (distance_threshold is not None):
169
+ assert hasattr(clustering, 'distances_')
170
+ n_children = clustering.children_.shape[0]
171
+ n_nodes = n_children + 1
172
+ assert clustering.distances_.shape == (n_nodes-1, )
173
+ else:
174
+ assert not hasattr(clustering, 'distances_')
175
+
176
+
146
177
def test_agglomerative_clustering():
147
178
# Check that we obtain the correct number of clusters with
148
179
# agglomerative clustering.
0 commit comments