Skip to content

Commit 8a5a645

Browse files
committed
flake8
1 parent 8a5e3a6 commit 8a5a645

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

sklearn/ensemble/forest.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class and a random sample with replacement of the same size from all
123123
random_instance = check_random_state(random_state)
124124
sample_indices = np.empty(n_class*min_count, dtype=int)
125125

126-
for i, cls, count, indices in zip(range(n_class), classes, class_counts, class_indices):
126+
for i, cls, count, indices in zip(range(n_class), classes, class_counts,
127+
class_indices):
127128
random_instances = random_instance.randint(0, count, min_count)
128129
random_indices = indices[random_instances]
129130
sample_indices[i*min_count:(i+1)*min_count] = random_indices
@@ -158,7 +159,8 @@ def _parallel_build_trees(tree, forest, X, y, sample_weight, tree_idx, n_trees,
158159
if balance_data is None:
159160
indices = _generate_sample_indices(tree.random_state, n_samples)
160161
else:
161-
indices = _generate_balanced_sample_indices(tree.random_state, balance_data)
162+
indices = _generate_balanced_sample_indices(tree.random_state,
163+
balance_data)
162164

163165
sample_counts = bincount(indices, minlength=n_samples)
164166
curr_sample_weight *= sample_counts
@@ -278,8 +280,8 @@ def fit(self, X, y, sample_weight=None):
278280
Parameters
279281
----------
280282
X : array-like or sparse matrix of shape = [n_samples, n_features]
281-
The training input samples. Internally, its dtype will be converted to
282-
``dtype=np.float32``. If a sparse matrix is provided, it will be
283+
The training input samples. Internally, its dtype will be converted
284+
to ``dtype=np.float32``. If a sparse matrix is provided, it will be
283285
converted into a sparse ``csc_matrix``.
284286
285287
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
@@ -326,8 +328,6 @@ def fit(self, X, y, sample_weight=None):
326328
self.n_outputs_ = y.shape[1]
327329

328330
y, expanded_class_weight = self._validate_y_class_weight(y)
329-
# if self.balanced and self.n_outputs_ > 1:
330-
# raise NotImplementedError("Multi-output balanced random forest is not impemented.")
331331

332332
if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
333333
y = np.ascontiguousarray(y, dtype=DOUBLE)
@@ -373,7 +373,8 @@ def fit(self, X, y, sample_weight=None):
373373
random_state=random_state)
374374
trees.append(tree)
375375

376-
balance_data = _get_class_balance_data(y) if self.balanced else None
376+
balance_data = _get_class_balance_data(y)\
377+
if self.balanced else None
377378

378379
# Parallel loop: we use the threading backend as the Cython code
379380
# for fitting the trees is internally releasing the Python GIL
@@ -542,7 +543,8 @@ def _validate_y_class_weight(self, y):
542543

543544
y_store_unique_indices = np.zeros(y.shape, dtype=np.int)
544545
for k in range(self.n_outputs_):
545-
classes_k, y_store_unique_indices[:, k] = np.unique(y[:, k], return_inverse=True)
546+
classes_k, y_store_unique_indices[:, k] = np.unique(
547+
y[:, k], return_inverse=True)
546548
self.classes_.append(classes_k)
547549
self.n_classes_.append(classes_k.shape[0])
548550
y = y_store_unique_indices
@@ -552,16 +554,18 @@ def _validate_y_class_weight(self, y):
552554
if isinstance(self.class_weight, six.string_types):
553555
if self.class_weight not in valid_presets:
554556
raise ValueError('Valid presets for class_weight include '
555-
'"balanced" and "balanced_subsample". Given "%s".'
557+
'"balanced" and "balanced_subsample". '
558+
'Given "%s".'
556559
% self.class_weight)
557560
if self.warm_start:
558-
warn('class_weight presets "balanced" or "balanced_subsample" are '
561+
warn('class_weight presets "balanced" or '
562+
'"balanced_subsample" are '
559563
'not recommended for warm_start if the fitted data '
560564
'differs from the full dataset. In order to use '
561-
'"balanced" weights, use compute_class_weight("balanced", '
562-
'classes, y). In place of y you can use a large '
563-
'enough sample of the full training set target to '
564-
'properly estimate the class frequency '
565+
'"balanced" weights, use compute_class_weight('
566+
'"balanced", classes, y). In place of y you can use a'
567+
'large enough sample of the full training set target '
568+
'to properly estimate the class frequency '
565569
'distributions. Pass the resulting weights as the '
566570
'class_weight parameter.')
567571

@@ -617,8 +621,8 @@ def predict_proba(self, X):
617621
618622
The predicted class probabilities of an input sample are computed as
619623
the mean predicted class probabilities of the trees in the forest. The
620-
class probability of a single tree is the fraction of samples of the same
621-
class in a leaf.
624+
class probability of a single tree is the fraction of samples of the
625+
same class in a leaf.
622626
623627
Parameters
624628
----------
@@ -1376,8 +1380,9 @@ class ExtraTreesClassifier(ForestClassifier):
13761380
weights inversely proportional to class frequencies in the input data
13771381
as ``n_samples / (n_classes * np.bincount(y))``
13781382
1379-
The "balanced_subsample" mode is the same as "balanced" except that weights are
1380-
computed based on the bootstrap sample for every tree grown.
1383+
The "balanced_subsample" mode is the same as "balanced" except that
1384+
weights are computed based on the bootstrap sample for every tree
1385+
grown.
13811386
13821387
For multi-output, the weights of each column of y will be multiplied.
13831388

0 commit comments

Comments
 (0)