def test_all_estimators_filter_estimator_types(estimator_type): estimators = all_estimators(estimator_types=estimator_type, return_names=False) assert isinstance(estimators, list) # assert len(estimators) > 0 if isinstance(estimator_type, str): estimator_type = VALID_ESTIMATOR_BASE_TYPE_LOOKUP[estimator_type] assert all( [issubclass(estimator, estimator_type) for estimator in estimators])
def test_all_estimators_exclude_estimators(exclude_estimators): estimators = all_estimators(return_names=True, exclude_estimators=exclude_estimators) assert isinstance(estimators, list) assert len(estimators) > 0 names, estimators = list(zip(*estimators)) if not isinstance(exclude_estimators, list): exclude_estimators = [exclude_estimators] for estimator in exclude_estimators: assert estimator not in names
def test_all_estimators_return_names(return_names): estimators = all_estimators(return_names=return_names) assert isinstance(estimators, list) assert len(estimators) > 0 if return_names: assert all([isinstance(estimator, tuple) for estimator in estimators]) names, estimators = list(zip(*estimators)) assert all([isinstance(name, str) for name in names]) assert all([ name == estimator.__name__ for name, estimator in zip(names, estimators) ]) assert all([isinstance(estimator, type) for estimator in estimators])
# -*- coding: utf-8 -*- import numpy as np import pytest from sktime.utils import all_estimators from sktime.utils._testing.panel import make_transformer_problem from sktime.tests._config import ESTIMATOR_TEST_PARAMS PAIRWISE_TRANSFORMERS = all_estimators(estimator_types="transformer-pairwise", return_names=False) PAIRWISE_TRANSFORMERS_PANEL = all_estimators( estimator_types="transformer-pairwise-panel", return_names=False) EXPECTED_SHAPE = (4, 5) X1_tab = make_transformer_problem( n_instances=4, n_columns=4, n_timepoints=5, random_state=1, return_numpy=True, panel=False, ) X2_tab = make_transformer_problem( n_instances=5, n_columns=5, n_timepoints=5, random_state=2, return_numpy=True, panel=False, )
from sktime.forecasting.tests._config import TEST_OOS_FHS from sktime.forecasting.tests._config import TEST_STEP_LENGTHS from sktime.forecasting.tests._config import TEST_WINDOW_LENGTHS from sktime.forecasting.tests._config import TEST_YS from sktime.forecasting.tests._config import VALID_INDEX_FH_COMBINATIONS from sktime.performance_metrics.forecasting import smape_loss from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing.forecasting import _make_fh from sktime.utils._testing.forecasting import assert_correct_pred_time_index from sktime.utils._testing.forecasting import get_expected_index_for_update_predict from sktime.utils._testing.forecasting import make_forecasting_problem from sktime.utils.validation.forecasting import check_fh # get all forecasters FORECASTERS = all_estimators(estimator_types="forecaster", return_names=False) FH0 = 1 # testing data y = make_forecasting_problem() y_train, y_test = temporal_train_test_split(y, train_size=0.75) @pytest.mark.parametrize("Forecaster", FORECASTERS) def test_fitted_params(Forecaster): f = _construct_instance(Forecaster) f.fit(y_train, fh=FH0) try: params = f.get_fitted_params() assert isinstance(params, dict)
import pandas as pd import pytest from sktime.forecasting.base._sktime import _SktimeForecaster from sktime.forecasting.base._sktime import _BaseWindowForecaster from sktime.forecasting.base._sktime import _OptionalForecastingHorizonMixin from sktime.forecasting.base._sktime import _RequiredForecastingHorizonMixin from sktime.forecasting.model_selection import temporal_train_test_split from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing.forecasting import make_forecasting_problem # get all forecasters FORECASTERS = [ forecaster for (name, forecaster) in all_estimators(estimator_types="forecaster") if issubclass(forecaster, _SktimeForecaster) ] FH0 = 1 WINDOW_FORECASTERS = [ forecaster for (name, forecaster) in all_estimators(estimator_types="forecaster") if issubclass(forecaster, _BaseWindowForecaster) ] # testing data y = make_forecasting_problem() y_train, y_test = temporal_train_test_split(y, train_size=0.75)
# -*- coding: utf-8 -*- import numpy as np from sktime.dists_kernels.compose_tab_to_panel import AggrDist from sktime.dists_kernels.scipy_dist import ScipyDist from sktime.utils._testing.panel import make_transformer_problem from sktime.utils import all_estimators PAIRWISE_TRANSFORMERS_TAB = all_estimators( estimator_types="transformer-pairwise", return_names=False) AGGFUNCS = [ np.mean, np.std, np.var, np.sum, np.prod, np.min, np.max, np.argmin, np.argmax, np.any, ] X1_num_pan = make_transformer_problem(n_instances=4, n_columns=4, n_timepoints=5, random_state=1, return_numpy=True) X2_num_pan = make_transformer_problem(n_instances=5, n_columns=5, n_timepoints=5,
import pytest from sktime.tests._config import VALID_TRANSFORMER_TYPES from sktime.transformations.base import BaseTransformer from sktime.transformations.base import _PanelToPanelTransformer from sktime.transformations.base import _PanelToTabularTransformer from sktime.transformations.base import _SeriesToPrimitivesTransformer from sktime.transformations.base import _SeriesToSeriesTransformer from sktime.utils import all_estimators from sktime.utils import _has_tag from sktime.utils._testing.estimator_checks import _assert_array_almost_equal from sktime.utils._testing.estimator_checks import _construct_instance from sktime.utils._testing.estimator_checks import _make_args from sktime.utils.data_processing import is_nested_dataframe ALL_TRANSFORMERS = all_estimators(estimator_types="transformer", return_names=False) @pytest.mark.parametrize("Estimator", ALL_TRANSFORMERS) def test_all_transformers(Estimator): check_transformer(Estimator) def check_transformer(Estimator): for check in _yield_transformer_checks(Estimator): check(Estimator) def _construct_fit_transform(Estimator, **kwargs): estimator = _construct_instance(Estimator)
] import numpy as np import pytest from sktime.series_as_features.tests._config import ACCEPTED_OUTPUT_TYPES from sktime.tests._config import EXCLUDE_ESTIMATORS from sktime.tests._config import NON_STATE_CHANGING_METHODS from sktime.transformations.base import _PanelToPanelTransformer from sktime.transformations.base import _PanelToTabularTransformer from sktime.utils import all_estimators from sktime.utils._testing.estimator_checks import _construct_instance from sktime.utils._testing.estimator_checks import _make_args CLASSIFIERS = all_estimators("classifier", return_names=False, exclude_estimators=EXCLUDE_ESTIMATORS) REGRESSORS = all_estimators("regressor", return_names=False, exclude_estimators=EXCLUDE_ESTIMATORS) PANEL_TRANSFORMERS = all_estimators( estimator_types=[_PanelToPanelTransformer, _PanelToTabularTransformer], return_names=False, exclude_estimators=EXCLUDE_ESTIMATORS, ) PANEL_ESTIMATORS = CLASSIFIERS + REGRESSORS + PANEL_TRANSFORMERS # We here only check the ouput for a single number of classes N_CLASSES = 3
# coding: utf-8 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file) __author__ = ["Markus Löning"] __all__ = [] import numpy as np import pandas as pd import pytest from sktime.tests._config import EXCLUDED from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing import _make_args ALL_CLASSIFIERS = [ e[1] for e in all_estimators(estimator_type="classifier") if e[0] not in EXCLUDED ] ALL_REGRESSORS = [ e[1] for e in all_estimators(estimator_type="regressor") if e[0] not in EXCLUDED ] N_CLASSES = 3 ACCEPTED_OUTPUT_TYPES = (np.ndarray, pd.Series) @pytest.mark.parametrize("Estimator", [*ALL_CLASSIFIERS, *ALL_REGRESSORS]) def test_series_as_features_multivariate_input(Estimator): # check if multivariate input is correctly handled
] import numpy as np import pandas as pd import pytest from sktime.forecasting.base._sktime import BaseSktimeForecaster from sktime.forecasting.base._sktime import OptionalForecastingHorizonMixin from sktime.forecasting.base._sktime import RequiredForecastingHorizonMixin from sktime.forecasting.model_selection import temporal_train_test_split from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing.forecasting import make_forecasting_problem # get all forecasters FORECASTERS = [forecaster for (name, forecaster) in all_estimators(estimator_type="forecaster") if issubclass(forecaster, BaseSktimeForecaster)] FH0 = 1 # testing data y = make_forecasting_problem() y_train, y_test = temporal_train_test_split(y, train_size=0.75) # test _y setting @pytest.mark.parametrize("Forecaster", FORECASTERS) def test_oh_setting(Forecaster): # check _y and cutoff is None after construction f = _construct_instance(Forecaster) assert f._y is None assert f.cutoff is None
#!/usr/bin/env python3 -u # -*- coding: utf-8 -*- # copyright: sktime developers, BSD-3-Clause License (see LICENSE file) __author__ = ["Markus Löning"] __all__ = ["test_estimator"] import pytest from sktime.tests._config import EXCLUDE_ESTIMATORS from sktime.tests._config import EXCLUDED_TESTS from sktime.utils import all_estimators from sktime.utils._testing.estimator_checks import check_estimator ALL_ESTIMATORS = all_estimators(return_names=False, exclude_estimators=EXCLUDE_ESTIMATORS) @pytest.mark.parametrize("Estimator", ALL_ESTIMATORS) def test_estimator(Estimator): # We run a number of basic checks on all estimators to ensure correct # implementation of our framework and compatibility with scikit-learn. check_estimator(Estimator, EXCLUDED_TESTS.get(Estimator.__name__, []))
#!/usr/bin/env python3 -u # coding: utf-8 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file) __author__ = ["Markus Löning"] __all__ = [] import numpy as np import pytest from sktime.tests.test_all_estimators import EXCLUDED from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing import _make_args ALL_SERIES_AS_FEATURES_TRANSFORMERS = [ e[1] for e in all_estimators("series_as_features_transformer") if e[0] not in EXCLUDED ] @pytest.mark.parametrize("Transformer", ALL_SERIES_AS_FEATURES_TRANSFORMERS) def test_transformed_data_has_same_index_as_input_data(Transformer): transformer = _construct_instance(Transformer) X, y = _make_args(transformer, "fit") Xt = transformer.fit_transform(X, y) np.testing.assert_array_equal(X.index, Xt.index)
# -*- coding: utf-8 -*- import pandas as pd import pytest from sktime.utils._testing.estimator_checks import _construct_instance, _make_args from sktime.utils import all_estimators ALL_ANNOTATORS = all_estimators(estimator_types="series-annotator", return_names=False) @pytest.mark.parametrize("Estimator", ALL_ANNOTATORS) def test_output_type(Estimator): estimator = _construct_instance(Estimator) args = _make_args(estimator, "fit") estimator.fit(*args) args = _make_args(estimator, "predict") y_pred = estimator.predict(*args) assert isinstance(y_pred, pd.Series)
__author__ = ["Markus Löning"] __all__ = [] import numpy as np import pandas as pd import pytest from sktime.tests._config import EXCLUDED_ESTIMATORS from sktime.tests._config import NON_STATE_CHANGING_METHODS from sktime.utils import all_estimators from sktime.utils._testing import _construct_instance from sktime.utils._testing import _make_args CLASSIFIERS = [ e[1] for e in all_estimators(estimator_type="classifier") if e[0] not in EXCLUDED_ESTIMATORS ] REGRESSORS = [ e[1] for e in all_estimators(estimator_type="regressor") if e[0] not in EXCLUDED_ESTIMATORS ] SERIES_AS_FEATURES_TRANSFORMERS = [ e[1] for e in all_estimators(estimator_type="series_as_features_transformer") if e[0] not in EXCLUDED_ESTIMATORS ]
#!/usr/bin/env python3 -u # coding: utf-8 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file) __author__ = ["Markus Löning"] __all__ = ["test_estimator"] import pytest from sktime.tests._config import EXCLUDED from sktime.utils import all_estimators from sktime.utils._testing.estimator_checks import check_estimator ALL_ESTIMATORS = [e[1] for e in all_estimators() if e[0] not in EXCLUDED] @pytest.mark.parametrize("Estimator", ALL_ESTIMATORS) def test_estimator(Estimator): # We run a number of basic checks on all estimators to ensure correct # implementation of our framework and compatibility with scikit-learn check_estimator(Estimator)