diff --git a/asv_benchmarks/benchmarks/ensemble.py b/asv_benchmarks/benchmarks/ensemble.py index c46ac07c84475..8977eb0d10f20 100644 --- a/asv_benchmarks/benchmarks/ensemble.py +++ b/asv_benchmarks/benchmarks/ensemble.py @@ -1,4 +1,3 @@ -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import (RandomForestClassifier, GradientBoostingClassifier, HistGradientBoostingClassifier) diff --git a/benchmarks/bench_hist_gradient_boosting.py b/benchmarks/bench_hist_gradient_boosting.py index 82eb64faeb462..533861b1b63e4 100644 --- a/benchmarks/bench_hist_gradient_boosting.py +++ b/benchmarks/bench_hist_gradient_boosting.py @@ -4,8 +4,6 @@ import matplotlib.pyplot as plt import numpy as np from sklearn.model_selection import train_test_split -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.datasets import make_classification diff --git a/benchmarks/bench_hist_gradient_boosting_adult.py b/benchmarks/bench_hist_gradient_boosting_adult.py index 5b47fcb3a6678..49109cfc049bb 100644 --- a/benchmarks/bench_hist_gradient_boosting_adult.py +++ b/benchmarks/bench_hist_gradient_boosting_adult.py @@ -4,7 +4,6 @@ from sklearn.model_selection import train_test_split from sklearn.datasets import fetch_openml from sklearn.metrics import accuracy_score, roc_auc_score -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble._hist_gradient_boosting.utils import ( get_equivalent_estimator) diff --git a/benchmarks/bench_hist_gradient_boosting_categorical_only.py b/benchmarks/bench_hist_gradient_boosting_categorical_only.py index 6c69b32eff26f..d3d7a871b41d2 100644 --- a/benchmarks/bench_hist_gradient_boosting_categorical_only.py +++ b/benchmarks/bench_hist_gradient_boosting_categorical_only.py @@ -3,7 +3,6 @@ from sklearn.preprocessing import KBinsDiscretizer from sklearn.datasets import make_classification -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble._hist_gradient_boosting.utils import ( get_equivalent_estimator) diff --git a/benchmarks/bench_hist_gradient_boosting_higgsboson.py b/benchmarks/bench_hist_gradient_boosting_higgsboson.py index 2c74bb8818343..4e795a18ae2ce 100644 --- a/benchmarks/bench_hist_gradient_boosting_higgsboson.py +++ b/benchmarks/bench_hist_gradient_boosting_higgsboson.py @@ -9,8 +9,6 @@ from joblib import Memory from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, roc_auc_score -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble._hist_gradient_boosting.utils import ( get_equivalent_estimator) diff --git a/benchmarks/bench_hist_gradient_boosting_threading.py b/benchmarks/bench_hist_gradient_boosting_threading.py index 61803fb5cb9cc..6ab5de294dced 100644 --- a/benchmarks/bench_hist_gradient_boosting_threading.py +++ b/benchmarks/bench_hist_gradient_boosting_threading.py @@ -7,8 +7,6 @@ from threadpoolctl import threadpool_limits import sklearn from sklearn.model_selection import train_test_split -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.datasets import make_classification diff --git a/doc/conf.py b/doc/conf.py index 6768aab208a99..ba6b0595a7d44 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -358,7 +358,6 @@ def __call__(self, directory): # enable experimental module so that experimental estimators can be # discovered properly by sphinx -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.experimental import enable_iterative_imputer # noqa from sklearn.experimental import enable_halving_search_cv # noqa diff --git a/doc/developers/maintainer.rst b/doc/developers/maintainer.rst index e4115e87025c7..8fd439c984660 100644 --- a/doc/developers/maintainer.rst +++ b/doc/developers/maintainer.rst @@ -363,10 +363,17 @@ deprecation cycle. To create an experimental module, you can just copy and modify the content of `enable_hist_gradient_boosting.py -`_, +`__, or `enable_iterative_imputer.py -`_. +`_. + +.. note:: + + These are permalink as in 0.24, where these estimators are still + experimental. They might be stable at the time of reading - hence the + permalink. See below for instructions on the transition from experimental + to stable. Note that the public import path must be to a public subpackage (like ``sklearn/ensemble`` or ``sklearn/impute``), not just a ``.py`` module. @@ -379,14 +386,15 @@ in the future when the features aren't experimental anymore. To avoid type checker (e.g. mypy) errors a direct import of experimental estimators should be done in the parent module, protected by the ``if typing.TYPE_CHECKING`` check. See `sklearn/ensemble/__init__.py -`_, +`_, or `sklearn/impute/__init__.py -`_ +`_ for an example. Please also write basic tests following those in `test_enable_hist_gradient_boosting.py -`_. +`__. + Make sure every user-facing code you write explicitly mentions that the feature is experimental, and add a ``# noqa`` comment to avoid pep8-related warnings:: @@ -402,3 +410,14 @@ sklearn.experimental import *`` **does not work**. Note that some experimental classes / functions are not included in the :mod:`sklearn.experimental` module: ``sklearn.datasets.fetch_openml``. + +Once the feature become stable, remove all `enable_my_experimental_feature` +in the scikit-learn code (even feature highlights etc.) and make the +`enable_my_experimental_feature` a no-op that just raises a warning: +`enable_hist_gradient_boosting.py +`__. +The file should stay there indefinitely as we don't want to break users code: +we just incentivize them to remove that import with the warning. + +Also update the tests accordingly: `test_enable_hist_gradient_boosting.py +`__. diff --git a/doc/modules/ensemble.rst b/doc/modules/ensemble.rst index c891b4d275b9a..329215406c39c 100644 --- a/doc/modules/ensemble.rst +++ b/doc/modules/ensemble.rst @@ -467,7 +467,7 @@ trees. .. note:: - Scikit-learn 0.21 introduces two new experimental implementations of + Scikit-learn 0.21 introduces two new implementations of gradient boosting trees, namely :class:`HistGradientBoostingClassifier` and :class:`HistGradientBoostingRegressor`, inspired by `LightGBM `__ (See [LightGBM]_). @@ -898,7 +898,7 @@ based on permutation of the features. Histogram-Based Gradient Boosting ================================= -Scikit-learn 0.21 introduced two new experimental implementations of +Scikit-learn 0.21 introduced two new implementations of gradient boosting trees, namely :class:`HistGradientBoostingClassifier` and :class:`HistGradientBoostingRegressor`, inspired by `LightGBM `__ (See [LightGBM]_). @@ -920,15 +920,6 @@ estimators is slightly different, and some of the features from :class:`GradientBoostingClassifier` and :class:`GradientBoostingRegressor` are not yet supported, for instance some loss functions. -These estimators are still **experimental**: their predictions -and their API might change without any deprecation cycle. To use them, you -need to explicitly import ``enable_hist_gradient_boosting``:: - - >>> # explicitly require this experimental feature - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa - >>> # now you can import normally from ensemble - >>> from sklearn.ensemble import HistGradientBoostingClassifier - .. topic:: Examples: * :ref:`sphx_glr_auto_examples_inspection_plot_partial_dependence.py` @@ -941,7 +932,6 @@ Most of the parameters are unchanged from One exception is the ``max_iter`` parameter that replaces ``n_estimators``, and controls the number of iterations of the boosting process:: - >>> from sklearn.experimental import enable_hist_gradient_boosting >>> from sklearn.ensemble import HistGradientBoostingClassifier >>> from sklearn.datasets import make_hastie_10_2 @@ -992,7 +982,6 @@ with missing values should go to the left or right child, based on the potential gain. When predicting, samples with missing values are assigned to the left or right child consequently:: - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa >>> from sklearn.ensemble import HistGradientBoostingClassifier >>> import numpy as np @@ -1146,7 +1135,6 @@ You can specify a monotonic constraint on each feature using the constraint, while -1 and 1 indicate a negative and positive constraint, respectively:: - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa >>> from sklearn.ensemble import HistGradientBoostingRegressor ... # positive, negative, and no constraint on the 3 features diff --git a/doc/whats_new/v0.21.rst b/doc/whats_new/v0.21.rst index cf9886a6636af..8012fd02b4733 100644 --- a/doc/whats_new/v0.21.rst +++ b/doc/whats_new/v0.21.rst @@ -420,6 +420,11 @@ Support for Python 3.4 and below has been officially dropped. >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa >>> # now you can import normally from sklearn.ensemble >>> from sklearn.ensemble import HistGradientBoostingClassifier + + .. note:: + Update: since version 1.0, these estimators are not experimental + anymore and you don't need to use `from sklearn.experimental import + enable_hist_gradient_boosting`. :pr:`12807` by :user:`Nicolas Hug`. diff --git a/doc/whats_new/v1.0.rst b/doc/whats_new/v1.0.rst index 2b108d2f0e197..24da0bf7aea45 100644 --- a/doc/whats_new/v1.0.rst +++ b/doc/whats_new/v1.0.rst @@ -130,6 +130,11 @@ Changelog target. Additional private refactoring was performed. :pr:`19162` by :user:`Guillaume Lemaitre `. +- |Enhancement| :class:`~sklearn.ensemble.HistGradientBoostingClassifier` and + :class:`~sklearn.ensemble.HistGradientBoostingRegressor` are no longer + experimental. They are now considered stable and are subject to the same + deprecation cycles as all other estimators. :pr:`19799` by `Nicolas Hug`_. + :mod:`sklearn.feature_extraction` ................................. diff --git a/examples/ensemble/plot_gradient_boosting_categorical.py b/examples/ensemble/plot_gradient_boosting_categorical.py index 820a508f4de3c..876a1ca21ec4c 100644 --- a/examples/ensemble/plot_gradient_boosting_categorical.py +++ b/examples/ensemble/plot_gradient_boosting_categorical.py @@ -45,7 +45,6 @@ # As a baseline, we create an estimator where the categorical features are # dropped: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.pipeline import make_pipeline from sklearn.compose import make_column_transformer diff --git a/examples/ensemble/plot_monotonic_constraints.py b/examples/ensemble/plot_monotonic_constraints.py index 8b3f69f1d542e..c173ef35cf311 100644 --- a/examples/ensemble/plot_monotonic_constraints.py +++ b/examples/ensemble/plot_monotonic_constraints.py @@ -18,7 +18,6 @@ This example was inspired by the `XGBoost documentation `_. """ -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.inspection import plot_partial_dependence import numpy as np diff --git a/examples/ensemble/plot_stack_predictors.py b/examples/ensemble/plot_stack_predictors.py index c07068b060c57..afa48c62d8d0b 100644 --- a/examples/ensemble/plot_stack_predictors.py +++ b/examples/ensemble/plot_stack_predictors.py @@ -160,7 +160,6 @@ def load_ames_housing(): rf_pipeline # %% -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor gbdt_pipeline = make_pipeline( diff --git a/examples/inspection/plot_partial_dependence.py b/examples/inspection/plot_partial_dependence.py index 927857d845f9e..ac8d20ec9f155 100644 --- a/examples/inspection/plot_partial_dependence.py +++ b/examples/inspection/plot_partial_dependence.py @@ -134,7 +134,6 @@ # Let's now fit a :class:`~sklearn.ensemble.HistGradientBoostingRegressor` and # compute the partial dependence on the same features. -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor print("Training HistGradientBoostingRegressor...") diff --git a/examples/linear_model/plot_poisson_regression_non_normal_loss.py b/examples/linear_model/plot_poisson_regression_non_normal_loss.py index 9541be1f62b24..7ebda543b4059 100644 --- a/examples/linear_model/plot_poisson_regression_non_normal_loss.py +++ b/examples/linear_model/plot_poisson_regression_non_normal_loss.py @@ -258,7 +258,6 @@ def score_estimator(estimator, df_test): # least-squares loss. Here we only fit trees with the Poisson loss to keep this # example concise. -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.preprocessing import OrdinalEncoder diff --git a/examples/release_highlights/plot_release_highlights_0_22_0.py b/examples/release_highlights/plot_release_highlights_0_22_0.py index d9efc9a520af1..cc0cfe674c61d 100644 --- a/examples/release_highlights/plot_release_highlights_0_22_0.py +++ b/examples/release_highlights/plot_release_highlights_0_22_0.py @@ -131,7 +131,6 @@ # support for missing values (NaNs). This means that there is no need for # imputing data when training or predicting. -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier X = np.array([0, 1, 2, np.nan]).reshape(-1, 1) diff --git a/examples/release_highlights/plot_release_highlights_0_23_0.py b/examples/release_highlights/plot_release_highlights_0_23_0.py index a34c23b4912be..364cd7958003e 100644 --- a/examples/release_highlights/plot_release_highlights_0_23_0.py +++ b/examples/release_highlights/plot_release_highlights_0_23_0.py @@ -36,7 +36,6 @@ import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import PoissonRegressor -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor n_samples, n_features = 1000, 20 @@ -124,7 +123,6 @@ from matplotlib import pyplot as plt from sklearn.model_selection import train_test_split from sklearn.inspection import plot_partial_dependence -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor n_samples = 500 diff --git a/sklearn/ensemble/__init__.py b/sklearn/ensemble/__init__.py index ae86349ad9af0..0a78a774cca36 100644 --- a/sklearn/ensemble/__init__.py +++ b/sklearn/ensemble/__init__.py @@ -2,8 +2,6 @@ The :mod:`sklearn.ensemble` module includes ensemble-based methods for classification, regression and anomaly detection. """ -import typing - from ._base import BaseEnsemble from ._forest import RandomForestClassifier from ._forest import RandomForestRegressor @@ -21,13 +19,9 @@ from ._voting import VotingRegressor from ._stacking import StackingClassifier from ._stacking import StackingRegressor - -if typing.TYPE_CHECKING: - # Avoid errors in type checkers (e.g. mypy) for experimental estimators. - # TODO: remove this check once the estimator is no longer experimental. - from ._hist_gradient_boosting.gradient_boosting import ( # noqa - HistGradientBoostingRegressor, HistGradientBoostingClassifier - ) +from ._hist_gradient_boosting.gradient_boosting import ( + HistGradientBoostingRegressor, HistGradientBoostingClassifier +) __all__ = ["BaseEnsemble", "RandomForestClassifier", "RandomForestRegressor", @@ -37,4 +31,5 @@ "GradientBoostingRegressor", "AdaBoostClassifier", "AdaBoostRegressor", "VotingClassifier", "VotingRegressor", "StackingClassifier", "StackingRegressor", + 'HistGradientBoostingClassifier', 'HistGradientBoostingRegressor', ] diff --git a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py index c35f79bd79251..d3b62a5df784a 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py +++ b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py @@ -887,17 +887,6 @@ class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting): This implementation is inspired by `LightGBM `_. - .. note:: - - This estimator is still **experimental** for now: the predictions - and the API might change without any deprecation cycle. To use it, - you need to explicitly import ``enable_hist_gradient_boosting``:: - - >>> # explicitly require this experimental feature - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa - >>> # now you can import normally from ensemble - >>> from sklearn.ensemble import HistGradientBoostingRegressor - Read more in the :ref:`User Guide `. .. versionadded:: 0.21 @@ -1040,8 +1029,6 @@ class HistGradientBoostingRegressor(RegressorMixin, BaseHistGradientBoosting): Examples -------- - >>> # To use this experimental feature, we need to explicitly ask for it: - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa >>> from sklearn.ensemble import HistGradientBoostingRegressor >>> from sklearn.datasets import load_diabetes >>> X, y = load_diabetes(return_X_y=True) @@ -1156,17 +1143,6 @@ class HistGradientBoostingClassifier(ClassifierMixin, This implementation is inspired by `LightGBM `_. - .. note:: - - This estimator is still **experimental** for now: the predictions - and the API might change without any deprecation cycle. To use it, - you need to explicitly import ``enable_hist_gradient_boosting``:: - - >>> # explicitly require this experimental feature - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa - >>> # now you can import normally from ensemble - >>> from sklearn.ensemble import HistGradientBoostingClassifier - Read more in the :ref:`User Guide `. .. versionadded:: 0.21 @@ -1304,8 +1280,6 @@ class HistGradientBoostingClassifier(ClassifierMixin, Examples -------- - >>> # To use this experimental feature, we need to explicitly ask for it: - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa >>> from sklearn.ensemble import HistGradientBoostingClassifier >>> from sklearn.datasets import load_iris >>> X, y = load_iris(return_X_y=True) diff --git a/sklearn/ensemble/_hist_gradient_boosting/tests/test_compare_lightgbm.py b/sklearn/ensemble/_hist_gradient_boosting/tests/test_compare_lightgbm.py index 4a6c4dbbb32c7..f34dffab2671c 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/tests/test_compare_lightgbm.py +++ b/sklearn/ensemble/_hist_gradient_boosting/tests/test_compare_lightgbm.py @@ -4,8 +4,6 @@ import numpy as np import pytest -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble._hist_gradient_boosting.binning import _BinMapper diff --git a/sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py index 265b4cf20f8f3..b2322f29f85d1 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py +++ b/sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py @@ -13,8 +13,6 @@ from sklearn.exceptions import NotFittedError from sklearn.compose import make_column_transformer -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble._hist_gradient_boosting.loss import _LOSSES diff --git a/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py b/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py index 29fc95d4bb070..725f9f6537865 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py +++ b/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py @@ -10,7 +10,6 @@ compute_node_value ) from sklearn.ensemble._hist_gradient_boosting.histogram import HistogramBuilder -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier diff --git a/sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py b/sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py index 2417de4f6cc63..044a6237bc54d 100644 --- a/sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py +++ b/sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py @@ -7,8 +7,6 @@ from sklearn.base import clone from sklearn.datasets import make_classification, make_regression -# To use this experimental feature, we need to explicitly ask for it: -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.metrics import check_scoring diff --git a/sklearn/experimental/enable_hist_gradient_boosting.py b/sklearn/experimental/enable_hist_gradient_boosting.py index d7ceefbd58a2f..f0416ac013e96 100644 --- a/sklearn/experimental/enable_hist_gradient_boosting.py +++ b/sklearn/experimental/enable_hist_gradient_boosting.py @@ -1,36 +1,21 @@ -"""Enables histogram-based gradient boosting estimators. +"""This is now a no-op and can be safely removed from your code. -The API and results of these estimators might change without any deprecation -cycle. - -Importing this file dynamically sets the +It used to enable the use of :class:`~sklearn.ensemble.HistGradientBoostingClassifier` and -:class:`~sklearn.ensemble.HistGradientBoostingRegressor` as attributes of the -ensemble module:: - - >>> # explicitly require this experimental feature - >>> from sklearn.experimental import enable_hist_gradient_boosting # noqa - >>> # now you can import normally from ensemble - >>> from sklearn.ensemble import HistGradientBoostingClassifier - >>> from sklearn.ensemble import HistGradientBoostingRegressor - - -The ``# noqa`` comment comment can be removed: it just tells linters like -flake8 to ignore the import, which appears as unused. +:class:`~sklearn.ensemble.HistGradientBoostingRegressor` when they were still +:term:`experimental`, but these estimators are now stable and can be imported +normally from `sklearn.ensemble`. """ +# Don't remove this file, we don't want to break users code just because the +# feature isn't experimental anymore. -from ..ensemble._hist_gradient_boosting.gradient_boosting import ( - HistGradientBoostingClassifier, - HistGradientBoostingRegressor -) -from .. import ensemble +import warnings -# use settattr to avoid mypy errors when monkeypatching -setattr(ensemble, "HistGradientBoostingClassifier", - HistGradientBoostingClassifier) -setattr(ensemble, "HistGradientBoostingRegressor", - HistGradientBoostingRegressor) -ensemble.__all__ += ['HistGradientBoostingClassifier', - 'HistGradientBoostingRegressor'] +warnings.warn( + "Since version 1.0, " + "it is not needed to import enable_hist_gradient_boosting anymore. " + "HistGradientBoostingClassifier and HistGradientBoostingRegressor are now " + "stable and can be normally imported from sklearn.ensemble." +) diff --git a/sklearn/experimental/tests/test_enable_hist_gradient_boosting.py b/sklearn/experimental/tests/test_enable_hist_gradient_boosting.py index 06c0976d95a1f..8ea365fed6e59 100644 --- a/sklearn/experimental/tests/test_enable_hist_gradient_boosting.py +++ b/sklearn/experimental/tests/test_enable_hist_gradient_boosting.py @@ -5,41 +5,10 @@ from sklearn.utils._testing import assert_run_python_script -def test_imports_strategies(): - # Make sure different import strategies work or fail as expected. - - # Since Python caches the imported modules, we need to run a child process - # for every test case. Else, the tests would not be independent - # (manually removing the imports from the cache (sys.modules) is not - # recommended and can lead to many complications). - - good_import = """ - from sklearn.experimental import enable_hist_gradient_boosting - from sklearn.ensemble import GradientBoostingClassifier - from sklearn.ensemble import GradientBoostingRegressor - """ - assert_run_python_script(textwrap.dedent(good_import)) - - good_import_with_ensemble_first = """ - import sklearn.ensemble - from sklearn.experimental import enable_hist_gradient_boosting - from sklearn.ensemble import GradientBoostingClassifier - from sklearn.ensemble import GradientBoostingRegressor - """ - assert_run_python_script(textwrap.dedent(good_import_with_ensemble_first)) - - bad_imports = """ +def test_import_raises_warning(): + code = """ import pytest - - with pytest.raises(ImportError): - from sklearn.ensemble import HistGradientBoostingClassifier - - with pytest.raises(ImportError): - from sklearn.ensemble._hist_gradient_boosting import ( - HistGradientBoostingClassifier) - - import sklearn.experimental - with pytest.raises(ImportError): - from sklearn.ensemble import HistGradientBoostingClassifier + with pytest.warns(UserWarning, match="it is not needed to import"): + from sklearn.experimental import enable_hist_gradient_boosting # noqa """ - assert_run_python_script(textwrap.dedent(bad_imports)) + assert_run_python_script(textwrap.dedent(code)) diff --git a/sklearn/feature_selection/tests/test_from_model.py b/sklearn/feature_selection/tests/test_from_model.py index 37b5c105e1daa..17488b397b0c8 100644 --- a/sklearn/feature_selection/tests/test_from_model.py +++ b/sklearn/feature_selection/tests/test_from_model.py @@ -10,7 +10,6 @@ from sklearn.linear_model import LogisticRegression, SGDClassifier, Lasso from sklearn.svm import LinearSVC from sklearn.feature_selection import SelectFromModel -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import (RandomForestClassifier, HistGradientBoostingClassifier) from sklearn.linear_model import PassiveAggressiveClassifier diff --git a/sklearn/feature_selection/tests/test_sequential.py b/sklearn/feature_selection/tests/test_sequential.py index 2ca22517ef956..163f7acba6ce1 100644 --- a/sklearn/feature_selection/tests/test_sequential.py +++ b/sklearn/feature_selection/tests/test_sequential.py @@ -8,7 +8,6 @@ from sklearn.feature_selection import SequentialFeatureSelector from sklearn.datasets import make_regression from sklearn.linear_model import LinearRegression -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingRegressor diff --git a/sklearn/inspection/tests/test_partial_dependence.py b/sklearn/inspection/tests/test_partial_dependence.py index 51dd6e53e4304..f79b2aca3beae 100644 --- a/sklearn/inspection/tests/test_partial_dependence.py +++ b/sklearn/inspection/tests/test_partial_dependence.py @@ -15,7 +15,6 @@ from sklearn.ensemble import GradientBoostingClassifier from sklearn.ensemble import GradientBoostingRegressor from sklearn.ensemble import RandomForestRegressor -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.ensemble import HistGradientBoostingRegressor from sklearn.linear_model import LinearRegression diff --git a/sklearn/model_selection/tests/test_search.py b/sklearn/model_selection/tests/test_search.py index 25c4ce8cc22f7..b74e250e94192 100644 --- a/sklearn/model_selection/tests/test_search.py +++ b/sklearn/model_selection/tests/test_search.py @@ -69,7 +69,6 @@ from sklearn.impute import SimpleImputer from sklearn.pipeline import Pipeline from sklearn.linear_model import Ridge, SGDClassifier, LinearRegression -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.model_selection.tests.common import OneTimeSplitter diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index 85d2f7b6e07ca..93f19cdb8a93f 100644 --- a/sklearn/tests/test_pipeline.py +++ b/sklearn/tests/test_pipeline.py @@ -36,7 +36,6 @@ from sklearn.datasets import load_iris from sklearn.preprocessing import StandardScaler from sklearn.feature_extraction.text import CountVectorizer -from sklearn.experimental import enable_hist_gradient_boosting # noqa from sklearn.ensemble import HistGradientBoostingClassifier from sklearn.impute import SimpleImputer