From 5220007240c78713d07e6590230dc311327a306e Mon Sep 17 00:00:00 2001 From: Saulo Martiello Mastelini Date: Sat, 16 Nov 2024 14:19:31 -0300 Subject: [PATCH] format --- river/ensemble/streaming_random_patches.py | 16 ++++++++++++---- river/forest/adaptive_random_forest.py | 9 +++++++-- river/rules/amrules.py | 5 ++++- river/tree/hoeffding_adaptive_tree_regressor.py | 4 +++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/river/ensemble/streaming_random_patches.py b/river/ensemble/streaming_random_patches.py index 0cd0dd61f9..415b30be10 100644 --- a/river/ensemble/streaming_random_patches.py +++ b/river/ensemble/streaming_random_patches.py @@ -161,7 +161,9 @@ def _generate_subspaces(self, features: list): # Generate n_models subspaces from all possible # feature combinations of size k self._subspaces = [] - for i, combination in enumerate(itertools.cycle(itertools.combinations(features, k))): + for i, combination in enumerate( + itertools.cycle(itertools.combinations(features, k)) + ): if i == self.n_models: break self._subspaces.append(list(combination)) @@ -171,7 +173,8 @@ def _generate_subspaces(self, features: list): # subspaces without worrying about repetitions. else: self._subspaces = [ - random_subspace(all_features=features, k=k, rng=self._rng) for _ in range(self.n_models) + random_subspace(all_features=features, k=k, rng=self._rng) + for _ in range(self.n_models) ] else: # k == 0 or k > n_features (subspace size is larger than the @@ -180,8 +183,13 @@ def _generate_subspaces(self, features: list): def _init_ensemble(self, features: list): self._generate_subspaces(features=features) - subspace_indexes = list(range(self.n_models)) # For matching subspaces with ensemble members - if self.training_method == self._TRAIN_RANDOM_PATCHES or self.training_method == self._TRAIN_RANDOM_SUBSPACES: + subspace_indexes = list( + range(self.n_models) + ) # For matching subspaces with ensemble members + if ( + self.training_method == self._TRAIN_RANDOM_PATCHES + or self.training_method == self._TRAIN_RANDOM_SUBSPACES + ): # Shuffle indexes self._rng.shuffle(subspace_indexes) diff --git a/river/forest/adaptive_random_forest.py b/river/forest/adaptive_random_forest.py index ea5a2811df..791e614d88 100644 --- a/river/forest/adaptive_random_forest.py +++ b/river/forest/adaptive_random_forest.py @@ -162,7 +162,8 @@ def learn_one(self, x: dict, y: base.typing.Target, **kwargs): y_true=y, y_pred=( model.predict_proba_one(x) - if isinstance(self.metric, metrics.base.ClassificationMetric) and not self.metric.requires_labels + if isinstance(self.metric, metrics.base.ClassificationMetric) + and not self.metric.requires_labels else y_pred ), ) @@ -188,7 +189,11 @@ def learn_one(self, x: dict, y: base.typing.Target, **kwargs): self._warning_tracker[i] += 1 if not self._drift_detection_disabled: - drift_input = drift_input if drift_input is not None else self._drift_detector_input(i, y, y_pred) + drift_input = ( + drift_input + if drift_input is not None + else self._drift_detector_input(i, y, y_pred) + ) self._drift_detectors[i].update(drift_input) if self._drift_detectors[i].drift_detected: diff --git a/river/rules/amrules.py b/river/rules/amrules.py index ac3c44312a..245f71c1f4 100644 --- a/river/rules/amrules.py +++ b/river/rules/amrules.py @@ -389,7 +389,10 @@ def learn_one(self, x: dict, y: base.typing.RegTarget, w: int = 1): self._default_rule.learn_one(x, y, w) expanded = False - if self._default_rule.total_weight - self._default_rule.last_expansion_attempt_at >= self.n_min: + if ( + self._default_rule.total_weight - self._default_rule.last_expansion_attempt_at + >= self.n_min + ): updated_rule, expanded = self._default_rule.expand(self.delta, self.tau) if expanded: diff --git a/river/tree/hoeffding_adaptive_tree_regressor.py b/river/tree/hoeffding_adaptive_tree_regressor.py index 8087208ff0..6c609cc8f4 100644 --- a/river/tree/hoeffding_adaptive_tree_regressor.py +++ b/river/tree/hoeffding_adaptive_tree_regressor.py @@ -304,7 +304,9 @@ def _new_leaf(self, initial_stats=None, parent=None, is_active=True): return new_adaptive - def _branch_selector(self, numerical_feature=True, multiway_split=False) -> type[AdaBranchRegressor]: + def _branch_selector( + self, numerical_feature=True, multiway_split=False + ) -> type[AdaBranchRegressor]: """Create a new split node.""" if numerical_feature: if not multiway_split: