8000 MNT remove boston from the common test / estimator checks by glemaitre · Pull Request #17356 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT remove boston from the common test / estimator checks #17356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions sklearn/utils/estimator_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
from .import shuffle
from .validation import has_fit_parameter, _num_samples
from ..preprocessing import StandardScaler
from ..datasets import (load_iris, load_boston, make_blobs,
from ..preprocessing import scale
from ..datasets import (load_iris, make_blobs,
make_multilabel_classification, make_regression)


BOSTON = None
REGRESSION_DATASET = None
CROSS_DECOMPOSITION = ['PLSCanonical', 'PLSRegression', 'CCA', 'PLSSVD']


Expand Down Expand Up @@ -495,15 +496,16 @@ def check_estimator(Estimator, generate_only=False):
warnings.warn(str(exception), SkipTestWarning)


def _boston_subset(n_samples=200):
global BOSTON
if BOSTON is None:
X, y = load_boston(return_X_y=True)
X, y = shuffle(X, y, random_state=0)
X, y = X[:n_samples], y[:n_samples]
def _regression_dataset():
global REGRESSION_DATASET
if REGRESSION_DATASET is None:
X, y = make_regression(
n_samples=200, n_features=10, n_informative=1,
bias=5.0, noise=20, random_state=42,
)
X = StandardScaler().fit_transform(X)
BOSTON = X, y
return BOSTON
REGRESSION_DATASET = X, y
return REGRESSION_DATASET


def _set_checking_parameters(estimator):
Expand Down Expand Up @@ -1227,7 +1229,7 @@ def check_transformer_data_not_an_array(name, transformer):

@ignore_warnings(category=FutureWarning)
def check_transformers_unfitted(name, transformer):
X, y = _boston_subset()
X, y = _regression_dataset()

transformer = clone(transformer)
with assert_raises((AttributeError, ValueError), msg="The unfitted "
Expand Down Expand Up @@ -2052,7 +2054,7 @@ def check_estimators_unfitted(name, estimator_orig):
Unfitted estimators should raise a NotFittedError.
"""
# Common test for Regressors, Classifiers and Outlier detection estimators
X, y = _boston_subset()
X, y = _regression_dataset()

estimator = clone(estimator_orig)
for method in ('decision_function', 'predict', 'predict_proba',
Expand Down Expand Up @@ -2188,7 +2190,7 @@ def check_classifiers_classes(name, classifier_orig):

@ignore_warnings(category=FutureWarning)
def check_regressors_int(name, regressor_orig):
X, _ = _boston_subset()
X, _ = _regression_dataset()
X = _pairwise_estimator_convert_X(X[:50], regressor_orig)
rnd = np.random.RandomState(0)
y = rnd.randint(3, size=X.shape[0])
Expand Down Expand Up @@ -2217,11 +2219,10 @@ def check_regressors_int(name, regressor_orig):
@ignore_warnings(category=FutureWarning)
def check_regressors_train(name, regressor_orig, readonly_memmap=False,
X_dtype=np.float64):
X, y = _boston_subset()
X, y = _regression_dataset()
X = X.astype(X_dtype)
X = _pairwise_estimator_convert_X(X, regressor_orig)
y = StandardScaler().fit_transform(y.reshape(-1, 1)) # X is already scaled
y = y.ravel()
y = scale(y) # X is already scaled
regressor = clone(regressor_orig)
y = _enforce_estimator_tags_y(regressor, y)
if name in CROSS_DECOMPOSITION:
Expand Down Expand Up @@ -2501,7 +2502,7 @@ def check_classifier_data_not_an_array(name, estimator_orig):

@ignore_warnings(category=FutureWarning)
def check_regressor_data_not_an_array(name, estimator_orig):
X, y = _boston_subset(n_samples=50)
X, y = _regression_dataset()
X = _pairwise_estimator_convert_X(X, estimator_orig)
y = _enforce_estimator_tags_y(estimator_orig, y)
for obj_type in ["NotAnArray", "PandasDataframe"]:
Expand Down Expand Up @@ -2781,7 +2782,9 @@ def check_set_params(name, estimator_orig):
def check_classifiers_regression_target(name, estimator_orig):
# Check if classifier throws an exception when fed regression targets

X, y = load_boston(return_X_y=True)
X, y = _regression_dataset()

X = X + 1 + abs(X.min(axis=0)) # be sure that X is non-negative
e = clone(estimator_orig)
msg = 'Unknown label type: '
if not e._get_tags()["no_validation"]:
Expand Down
0