|
24 | 24 | from . import _hierarchical
|
25 | 25 | from ._feature_agglomeration import AgglomerationTransform
|
26 | 26 | from .fast_dict import IntFloatDict, average_merge, max_merge,\
|
27 |
| - WeightedEdge |
| 27 | + WeightedEdge |
28 | 28 |
|
29 | 29 |
|
30 | 30 | ###############################################################################
|
@@ -295,21 +295,21 @@ def linkage_tree(X, connectivity=None, n_components=None, copy=True,
|
295 | 295 | X = np.reshape(X, (-1, 1))
|
296 | 296 | n_samples, n_features = X.shape
|
297 | 297 |
|
298 |
| - linkage_choices = { |
299 |
| - 'complete': (hierarchy.complete, max_merge), |
300 |
| - 'average': (hierarchy.weighted, average_merge), |
301 |
| - } |
| 298 | + linkage_choices = {'complete': (hierarchy.complete, max_merge), |
| 299 | + 'average': (hierarchy.weighted, average_merge), |
| 300 | + } |
302 | 301 | try:
|
303 | 302 | scipy_func, join_func = linkage_choices[linkage]
|
304 | 303 | except KeyError:
|
305 |
| - raise ValueError('Unknown linkage option, linkage should be one ' |
| 304 | + raise ValueError( |
| 305 | + 'Unknown linkage option, linkage should be one ' |
306 | 306 | 'of %s, but %s was given' % (linkage_choices.keys(), linkage))
|
307 | 307 |
|
308 | 308 | if connectivity is None:
|
309 | 309 | if n_clusters is not None:
|
310 | 310 | warnings.warn('Early stopping is implemented only for '
|
311 |
| - 'structured clustering (i.e. with ' |
312 |
| - 'explicit connectivity.', stacklevel=2) |
| 311 | + 'structured clustering (i.e. with ' |
| 312 | + 'explicit connectivity.', stacklevel=2) |
313 | 313 | out = scipy_func(X)
|
314 | 314 | children_ = out[:, :2].astype(np.int)
|
315 | 315 | return children_, 1, n_samples, None
|
@@ -351,14 +351,13 @@ def linkage_tree(X, connectivity=None, n_components=None, copy=True,
|
351 | 351 | connectivity = connectivity.tolil()
|
352 | 352 | # We are storing the graph in a list of IntFloatDict
|
353 | 353 | for ind, (data, row) in enumerate(zip(connectivity.data,
|
354 |
| - connectivity.rows)): |
| 354 | + connectivity.rows)): |
355 | 355 | A[ind] = IntFloatDict(np.asarray(row, dtype=np.int32),
|
356 |
| - np.asarray(data, dtype=np.float64)) |
| 356 | + np.asarray(data, dtype=np.float64)) |
357 | 357 | # We keep only the upper triangular for the heap
|
358 | 358 | # Generator expressions are faster than arrays on the following
|
359 | 359 | [inertia.append(WeightedEdge(d, ind, r))
|
360 |
| - for r, d in zip(row, data) |
361 |
| - if r < ind] |
| 360 | + for r, d in zip(row, data) if r < ind] |
362 | 361 | del connectivity
|
363 | 362 |
|
364 | 363 | heapify(inertia)
|
@@ -502,8 +501,8 @@ def fit(self, X):
|
502 | 501 |
|
503 | 502 | if not self.linkage in _TREE_BUILDERS:
|
504 | 503 | raise ValueError("Unknown linkage type %s."
|
505 |
| - "Valid options are %s" % (self.linkage, |
506 |
| - _TREE_BUILDERS.keys())) |
| 504 | + "Valid options are %s" % (self.linkage, |
| 505 | + _TREE_BUILDERS.keys())) |
507 | 506 | tree_builder = _TREE_BUILDERS[self.linkage]
|
508 | 507 |
|
509 | 508 | if not self.connectivity is None:
|
|
0 commit comments