Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,7 @@
"""
The :mod:`sklearn.experimental` module provides importable modules that enable
the use of experimental features or estimators.
The features and estimators that are experimental aren't subject to
deprecation cycles. Use them at your own risks!
"""

View file

@ -0,0 +1,36 @@
"""Enables histogram-based gradient boosting estimators.
The API and results of these estimators might change without any deprecation
cycle.
Importing this file dynamically sets the
: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.
"""
from ..ensemble._hist_gradient_boosting.gradient_boosting import (
HistGradientBoostingClassifier,
HistGradientBoostingRegressor
)
from .. import ensemble
# use settattr to avoid mypy errors when monkeypatching
setattr(ensemble, "HistGradientBoostingClassifier",
HistGradientBoostingClassifier)
setattr(ensemble, "HistGradientBoostingRegressor",
HistGradientBoostingRegressor)
ensemble.__all__ += ['HistGradientBoostingClassifier',
'HistGradientBoostingRegressor']

View file

@ -0,0 +1,20 @@
"""Enables IterativeImputer
The API and results of this estimator might change without any deprecation
cycle.
Importing this file dynamically sets :class:`sklearn.impute.IterativeImputer`
as an attribute of the impute module::
>>> # explicitly require this experimental feature
>>> from sklearn.experimental import enable_iterative_imputer # noqa
>>> # now you can import normally from impute
>>> from sklearn.impute import IterativeImputer
"""
from ..impute._iterative import IterativeImputer
from .. import impute
# use settattr to avoid mypy errors when monkeypatching
setattr(impute, 'IterativeImputer', IterativeImputer)
impute.__all__ += ['IterativeImputer']

View file

@ -0,0 +1,45 @@
"""Tests for making sure experimental imports work as expected."""
import textwrap
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 = """
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
"""
assert_run_python_script(textwrap.dedent(bad_imports))

View file

@ -0,0 +1,39 @@
"""Tests for making sure experimental imports work as expected."""
import textwrap
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_iterative_imputer
from sklearn.impute import IterativeImputer
"""
assert_run_python_script(textwrap.dedent(good_import))
good_import_with_ensemble_first = """
import sklearn.ensemble
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
"""
assert_run_python_script(textwrap.dedent(good_import_with_ensemble_first))
bad_imports = """
import pytest
with pytest.raises(ImportError):
from sklearn.impute import IterativeImputer
import sklearn.experimental
with pytest.raises(ImportError):
from sklearn.impute import IterativeImputer
"""
assert_run_python_script(textwrap.dedent(bad_imports))