Skip to content

Commit b1a453b

Browse files
eddiebergmanmfeurer
andcommitted
Clearup warnings (#1238)
* np.bool deprecation * Invalid escape sequence \_ * Series specify dtype * drop na requires keyword args deprecation * unspecified np.int size deprecated, use int instead * deprecated unspeicifed np.int precision * Element wise comparison failed, will raise error in the future * Specify explicit dtype for empty series * metric warnings for mismatch between y_pred and y_true label count * Quantile transformer n_quantiles larger than n_samples warning ignored * Silenced convergence warnings * pass sklearn args as keywords * np.bool deprecation * Invalid escape sequence \_ * Series specify dtype * drop na requires keyword args deprecation * unspecified np.int size deprecated, use int instead * deprecated unspeicifed np.int precision * Element wise comparison failed, will raise error in the future * Specify explicit dtype for empty series * metric warnings for mismatch between y_pred and y_true label count * Quantile transformer n_quantiles larger than n_samples warning ignored * Silenced convergence warnings * pass sklearn args as keywords * flake8'd * flake8'd * Fixed CategoricalImputation not accounting for sparse matrices * Updated to use distro for linux distribution * Ignore convergence warnings for gaussian process regressor * Averaging metrics now use zero_division parameter * Readded scorers to module scope * flake8'd * Fix * Fixed dtype for metalearner no run * Catch gaussian process iterative fit warning * Moved ignored warnings to tests * Correctly type pd.Series * Revert back to usual iterative fit * Readded missing iteration increment * Removed odd backslash * Fixed imputer for sparse matrices * Ignore warnings we are aware about in tests * Flake'd: * Revert "Fixed imputer for sparse matrices" This reverts commit 05675ad. * Revert "Revert "Fixed imputer for sparse matrices"" This reverts commit d031b0d. * Back to default values * Reverted to default behaviour with comment * Added xfail test to document * flaked * Fixed test, moved to np.testing for assertion * Update autosklearn/pipeline/components/data_preprocessing/categorical_encoding/encoding.py Co-authored-by: Matthias Feurer <feurerm@informatik.uni-freiburg.de> Co-authored-by: Matthias Feurer <feurerm@informatik.uni-freiburg.de>
1 parent 5ad0f0e commit b1a453b

File tree

4 files changed

+85
-19
lines changed

4 files changed

+85
-19
lines changed

autosklearn/metalearning/optimizers/metalearn_optimizer/metalearner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _learn(self, exclude_double_configurations=True):
111111
except KeyError:
112112
# TODO should I really except this?
113113
self.logger.info("Could not find runs for instance %s" % task_id)
114-
runs[task_id] = pd.Series([], name=task_id, dtype=float)
114+
runs[task_id] = pd.Series([], name=task_id, dtype=np.float64)
115115

116116
runs = pd.DataFrame(runs)
117117

autosklearn/pipeline/components/regression/gaussian_process.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ def fit(self, X, y):
3737
normalize_y=True
3838
)
3939

40-
if y.ndim == 2 and y.shape[1] == 1:
41-
y = y.flatten()
42-
4340
self.estimator.fit(X, y)
4441

4542
return self

test/test_pipeline/test_classification.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88
import unittest
99
import unittest.mock
10+
import warnings
1011

1112
from joblib import Memory
1213
import numpy as np
@@ -18,6 +19,7 @@
1819
import sklearn.ensemble
1920
import sklearn.svm
2021
from sklearn.utils.validation import check_is_fitted
22+
from sklearn.exceptions import ConvergenceWarning
2123

2224
from ConfigSpace.configuration_space import ConfigurationSpace
2325
from ConfigSpace.hyperparameters import CategoricalHyperparameter
@@ -32,7 +34,42 @@
3234
from autosklearn.pipeline.constants import \
3335
DENSE, SPARSE, UNSIGNED_DATA, PREDICTIONS, SIGNED_DATA, INPUT
3436

35-
from test.test_pipeline.ignored_warnings import classifier_warnings, ignore_warnings
37+
ignored_warnings = [
38+
(
39+
UserWarning, ( # From QuantileTransformer
40+
r"n_quantiles \(\d+\) is greater than the total number of samples \(\d+\)\."
41+
r" n_quantiles is set to n_samples\."
42+
)
43+
),
44+
(
45+
UserWarning, ( # From FastICA
46+
r"n_components is too large: it will be set to \d+"
47+
)
48+
49+
),
50+
(
51+
ConvergenceWarning, ( # From Liblinear
52+
r"Liblinear failed to converge, increase the number of iterations\."
53+
)
54+
),
55+
(
56+
ConvergenceWarning, ( # From SGD
57+
r"Maximum number of iteration reached before convergence\. Consider increasing"
58+
r" max_iter to improve the fit\."
59+
)
60+
),
61+
(
62+
ConvergenceWarning, ( # From MLP
63+
r"Stochastic Optimizer: Maximum iterations \(\d+\) reached and the"
64+
r" optimization hasn't converged yet\."
65+
)
66+
),
67+
(
68+
UserWarning, ( # From LDA (Linear Discriminant Analysis)
69+
r"Variables are collinear"
70+
)
71+
),
72+
]
3673

3774

3875
class DummyClassifier(AutoSklearnClassificationAlgorithm):
@@ -498,7 +535,10 @@ def _test_configurations(
498535
check_is_fitted(step)
499536

500537
try:
501-
with ignore_warnings(classifier_warnings):
538+
with warnings.catch_warnings():
539+
for category, message in ignored_warnings:
540+
warnings.filterwarnings('ignore', category=category, message=message)
541+
502542
cls.fit(X_train, Y_train)
503543

504544
# After fit, all components should be tagged as fitted

test/test_pipeline/test_regression.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
import unittest
66
import unittest.mock
7+
import warnings
78

89
from joblib import Memory
910
import numpy as np
@@ -13,6 +14,7 @@
1314
import sklearn.ensemble
1415
import sklearn.svm
1516
from sklearn.utils.validation import check_is_fitted
17+
from sklearn.exceptions import ConvergenceWarning
1618

1719
from ConfigSpace.configuration_space import ConfigurationSpace
1820
from ConfigSpace.hyperparameters import CategoricalHyperparameter
@@ -26,7 +28,32 @@
2628
from autosklearn.pipeline.util import get_dataset
2729
from autosklearn.pipeline.constants import SPARSE, DENSE, SIGNED_DATA, UNSIGNED_DATA, PREDICTIONS
2830

29-
from test.test_pipeline.ignored_warnings import regressor_warnings, ignore_warnings
31+
ignored_warnings = [
32+
(
33+
UserWarning, ( # From QuantileTransformer
34+
r"n_quantiles \(\d+\) is greater than the total number of samples \(\d+\)\."
35+
r" n_quantiles is set to n_samples\."
36+
)
37+
),
38+
(
39+
ConvergenceWarning, ( # From GaussianProcesses
40+
r"The optimal value found for dimension \d+ of parameter \w+ is close"
41+
r" to the specified (upper|lower) bound .*(Increasing|Decreasing) the bound"
42+
r" and calling fit again may find a better value."
43+
)
44+
),
45+
(
46+
UserWarning, ( # From FastICA
47+
r"n_components is too large: it will be set to \d+"
48+
)
49+
),
50+
(
51+
ConvergenceWarning, ( # From SGD
52+
r"Maximum number of iteration reached before convergence\. Consider increasing"
53+
r" max_iter to improve the fit\."
54+
)
55+
),
56+
]
3057

3158

3259
class SimpleRegressionPipelineTest(unittest.TestCase):
@@ -180,19 +207,21 @@ def _test_configurations(self, configurations_space, make_sparse=False,
180207
check_is_fitted(step)
181208

182209
try:
183-
with ignore_warnings(regressor_warnings):
184-
cls.fit(X_train, Y_train)
210+
with warnings.catch_warnings():
211+
for category, message in ignored_warnings:
212+
warnings.filterwarnings('ignore', category=category, message=message)
185213

186-
# After fit, all components should be tagged as fitted
187-
# by sklearn. Check is fitted raises an exception if that
188-
# is not the case
189-
try:
190-
for name, step in cls.named_steps.items():
191-
check_is_fitted(step)
192-
except sklearn.exceptions.NotFittedError:
193-
self.fail("config={} raised NotFittedError unexpectedly!".format(
194-
config
195-
))
214+
cls.fit(X_train, Y_train)
215+
# After fit, all components should be tagged as fitted
216+
# by sklearn. Check is fitted raises an exception if that
217+
# is not the case
218+
try:
219+
for name, step in cls.named_steps.items():
220+
check_is_fitted(step)
221+
except sklearn.exceptions.NotFittedError:
222+
self.fail("config={} raised NotFittedError unexpectedly!".format(
223+
config
224+
))
196225

197226
cls.predict(X_test)
198227
except MemoryError:

0 commit comments

Comments
 (0)