Skip to content

Commit cff2e21

Browse files
authored
Make autosklearn/pipeline PEP8 compliant (#826)
* make components/feature_preprocessing PEP8 compliant * make components/data_preprocessing PEP8 compliant * make components/classification PEP8 compliant * make components/regression PEP8 compliant * make pipeline/* PEP8 compliant * implement PR review requested changes
1 parent 8a7e564 commit cff2e21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+186
-223
lines changed

autosklearn/pipeline/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from abc import ABCMeta
2-
from collections import defaultdict
32

43
import numpy as np
54
from ConfigSpace import Configuration
65
from sklearn.pipeline import Pipeline
7-
from sklearn.utils.validation import check_random_state, check_is_fitted
6+
from sklearn.utils.validation import check_random_state
87

98
from .components.base import AutoSklearnChoice, AutoSklearnComponent
109
import autosklearn.pipeline.create_searchspace_util
@@ -226,7 +225,7 @@ def get_hyperparameter_search_space(self, dataset_properties=None):
226225
return self.config_space
227226

228227
def _get_hyperparameter_search_space(self, include=None, exclude=None,
229-
dataset_properties=None):
228+
dataset_properties=None):
230229
"""Return the configuration space for the CASH problem.
231230
232231
This method should be called by the method
@@ -320,8 +319,10 @@ def _get_base_search_space(self, cs, dataset_properties, exclude,
320319
# if the node isn't a choice we can add it immediately because it
321320
# must be active (if it wasn't, np.sum(matches) would be zero
322321
if not is_choice:
323-
cs.add_configuration_space(node_name,
324-
node.get_hyperparameter_search_space(dataset_properties))
322+
cs.add_configuration_space(
323+
node_name,
324+
node.get_hyperparameter_search_space(dataset_properties),
325+
)
325326
# If the node is a choice, we have to figure out which of its
326327
# choices are actually legal choices
327328
else:
@@ -356,7 +357,7 @@ def __repr__(self):
356357
configuration_string = ''.join(
357358
['configuration={\n ',
358359
',\n '.join(["'%s': %s" % (hp_name, repr(configuration[hp_name]))
359-
for hp_name in sorted(configuration)]),
360+
for hp_name in sorted(configuration)]),
360361
'}'])
361362

362363
if len(self.dataset_properties) > 0:
@@ -397,4 +398,3 @@ def get_additional_run_info(self):
397398
the optimization algorithm.
398399
"""
399400
return self._additional_run_info
400-

autosklearn/pipeline/classification.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,11 @@ def predict_proba(self, X, batch_size=None):
133133
y = np.zeros((X.shape[0], target.shape[1]),
134134
dtype=np.float32)
135135

136-
for k in range(max(1, int(np.ceil(float(X.shape[0]) /
137-
batch_size)))):
136+
for k in range(max(1, int(np.ceil(float(X.shape[0]) / batch_size)))):
138137
batch_from = k * batch_size
139138
batch_to = min([(k + 1) * batch_size, X.shape[0]])
140-
y[batch_from:batch_to] = \
141-
self.predict_proba(X[batch_from:batch_to],
142-
batch_size=None).\
143-
astype(np.float32)
139+
pred_prob = self.predict_proba(X[batch_from:batch_to], batch_size=None)
140+
y[batch_from:batch_to] = pred_prob.astype(np.float32)
144141

145142
return y
146143

@@ -161,7 +158,7 @@ def _get_hyperparameter_search_space(self, include=None, exclude=None,
161158

162159
if dataset_properties is None or not isinstance(dataset_properties, dict):
163160
dataset_properties = dict()
164-
if not 'target_type' in dataset_properties:
161+
if 'target_type' not in dataset_properties:
165162
dataset_properties['target_type'] = 'classification'
166163
if dataset_properties['target_type'] != 'classification':
167164
dataset_properties['target_type'] = 'classification'
@@ -232,7 +229,7 @@ def _get_hyperparameter_search_space(self, include=None, exclude=None,
232229
break
233230
except KeyError:
234231
break
235-
except ValueError as e:
232+
except ValueError:
236233
# Change the default and try again
237234
try:
238235
default = possible_default_classifier.pop()

autosklearn/pipeline/components/classification/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
__author__ = 'feurerm'
22

33
from collections import OrderedDict
4-
import copy
54
import os
65

76
from ..base import AutoSklearnClassificationAlgorithm, find_components, \
87
ThirdPartyComponents, AutoSklearnChoice
98
from ConfigSpace.configuration_space import ConfigurationSpace
109
from ConfigSpace.hyperparameters import CategoricalHyperparameter
11-
from ConfigSpace.conditions import EqualsCondition
1210

1311
classifier_directory = os.path.split(__file__)[0]
1412
_classifiers = find_components(__package__,
@@ -61,11 +59,11 @@ def get_available_components(cls, dataset_properties=None,
6159

6260
if entry.get_properties()['handles_classification'] is False:
6361
continue
64-
if dataset_properties.get('multiclass') is True and entry.get_properties()[
65-
'handles_multiclass'] is False:
62+
if dataset_properties.get('multiclass') is True and \
63+
entry.get_properties()['handles_multiclass'] is False:
6664
continue
67-
if dataset_properties.get('multilabel') is True and available_comp[name]. \
68-
get_properties()['handles_multilabel'] is False:
65+
if dataset_properties.get('multilabel') is True and \
66+
available_comp[name].get_properties()['handles_multilabel'] is False:
6967
continue
7068
components_dict[name] = entry
7169

autosklearn/pipeline/components/classification/adaboost.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
UniformIntegerHyperparameter, CategoricalHyperparameter
44

55
from autosklearn.pipeline.components.base import AutoSklearnClassificationAlgorithm
6-
from autosklearn.pipeline.constants import *
6+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS, SPARSE
77

88

99
class AdaboostClassifier(AutoSklearnClassificationAlgorithm):
@@ -76,4 +76,3 @@ def get_hyperparameter_search_space(dataset_properties=None):
7676

7777
cs.add_hyperparameters([n_estimators, learning_rate, algorithm, max_depth])
7878
return cs
79-

autosklearn/pipeline/components/classification/bernoulli_nb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from autosklearn.pipeline.components.base import (
88
AutoSklearnClassificationAlgorithm,
99
)
10-
from autosklearn.pipeline.constants import *
10+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS, SPARSE
1111
from autosklearn.util.common import check_for_bool
1212

1313

@@ -60,7 +60,7 @@ def get_properties(dataset_properties=None):
6060
@staticmethod
6161
def get_hyperparameter_search_space(dataset_properties=None):
6262
cs = ConfigurationSpace()
63-
63+
6464
# the smoothing parameter is a non-negative float
6565
# I will limit it to 1000 and put it on a logarithmic scale. (SF)
6666
# Please adjust that, if you know a proper range, this is just a guess.
@@ -72,5 +72,5 @@ def get_hyperparameter_search_space(dataset_properties=None):
7272
default_value="True")
7373

7474
cs.add_hyperparameters([alpha, fit_prior])
75-
75+
7676
return cs

autosklearn/pipeline/components/classification/decision_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from autosklearn.pipeline.components.base import \
99
AutoSklearnClassificationAlgorithm
10-
from autosklearn.pipeline.constants import *
10+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS, SPARSE
1111
from autosklearn.pipeline.implementations.util import convert_multioutput_multiclass_to_multilabel
1212
from autosklearn.util.common import check_none
1313

autosklearn/pipeline/components/classification/extra_trees.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import numpy as np
2-
31
from ConfigSpace.configuration_space import ConfigurationSpace
42
from ConfigSpace.hyperparameters import UniformFloatHyperparameter, \
5-
UniformIntegerHyperparameter, CategoricalHyperparameter, \
6-
UnParametrizedHyperparameter, Constant
3+
UniformIntegerHyperparameter, CategoricalHyperparameter, UnParametrizedHyperparameter
74

85
from autosklearn.pipeline.components.base import (
96
AutoSklearnClassificationAlgorithm,
107
IterativeComponentWithSampleWeight,
118
)
12-
from autosklearn.pipeline.constants import *
9+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS, SPARSE
1310
from autosklearn.pipeline.implementations.util import convert_multioutput_multiclass_to_multilabel
1411
from autosklearn.util.common import check_for_bool, check_none
1512

autosklearn/pipeline/components/classification/gaussian_nb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from autosklearn.pipeline.components.base import (
66
AutoSklearnClassificationAlgorithm,
77
)
8-
from autosklearn.pipeline.constants import *
8+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS
99

1010

1111
class GaussianNB(AutoSklearnClassificationAlgorithm):
@@ -57,4 +57,3 @@ def get_properties(dataset_properties=None):
5757
def get_hyperparameter_search_space(dataset_properties=None):
5858
cs = ConfigurationSpace()
5959
return cs
60-

autosklearn/pipeline/components/classification/gradient_boosting.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
AutoSklearnClassificationAlgorithm,
1111
IterativeComponent,
1212
)
13-
from autosklearn.pipeline.constants import *
13+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS
1414
from autosklearn.util.common import check_none
1515

1616

@@ -121,7 +121,9 @@ def iterative_fit(self, X, y, n_iter=2, refit=False):
121121

122122
self.estimator.fit(X, y)
123123

124-
if self.estimator.max_iter >= self.max_iter or self.estimator.max_iter > self.estimator.n_iter_:
124+
if self.estimator.max_iter >= self.max_iter \
125+
or self.estimator.max_iter > self.estimator.n_iter_:
126+
125127
self.fully_fit_ = True
126128

127129
return self
@@ -195,4 +197,3 @@ def get_hyperparameter_search_space(dataset_properties=None):
195197
cs.add_conditions([n_iter_no_change_cond, validation_fraction_cond])
196198

197199
return cs
198-

autosklearn/pipeline/components/classification/k_nearest_neighbors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from ConfigSpace.configuration_space import ConfigurationSpace
2-
from ConfigSpace.hyperparameters import CategoricalHyperparameter, \
3-
Constant, UniformIntegerHyperparameter
2+
from ConfigSpace.hyperparameters import CategoricalHyperparameter, UniformIntegerHyperparameter
43

54
from autosklearn.pipeline.components.base import AutoSklearnClassificationAlgorithm
6-
from autosklearn.pipeline.constants import *
5+
from autosklearn.pipeline.constants import DENSE, UNSIGNED_DATA, PREDICTIONS, SPARSE
76

87

98
class KNearestNeighborsClassifier(AutoSklearnClassificationAlgorithm):

0 commit comments

Comments
 (0)