8000 MNT Makes modules in tree and ensemble private by adrinjalali · Pull Request #14964 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT Makes modules in tree and ensemble private #14964

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 19 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ sklearn/linear_model/sag_fast.pyx
# TODO: Remove in 0.24
# All of these files should have a match in _build_utils/deprecated_modules.py
sklearn/utils/mocking.py

sklearn/ensemble/bagging.py
sklearn/ensemble/base.py
sklearn/ensemble/forest.py
sklearn/ensemble/gradient_boosting.py
sklearn/ensemble/iforest.py
sklearn/ensemble/stacking.py
sklearn/ensemble/voting.py
sklearn/ensemble/weight_boosting.py
sklearn/tree/export.py
sklearn/tree/tree.py

sklearn/utils/weight_vector.py
sklearn/utils/seq_dataset.py
sklearn/utils/fast_dict.py
Expand Down
10 changes: 10 additions & 0 deletions sklearn/_build_utils/deprecated_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
_DEPRECATED_MODULES = {
('_mocking', 'sklearn.utils.mocking', 'sklearn.utils'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: skip line


('_bagging', 'sklearn.ensemble.bagging', 'sklearn.ensemble'),
('_base', & 8000 #39;sklearn.ensemble.base', 'sklearn.ensemble'),
('_forest', 'sklearn.ensemble.forest', 'sklearn.ensemble'),
('_gb', 'sklearn.ensemble.gradient_boosting', 'sklearn.ensemble'),
('_iforest', 'sklearn.ensemble.iforest', 'sklearn.ensemble'),
('_voting', 'sklearn.ensemble.voting', 'sklearn.ensemble'),
('_weight_boosting', 'sklearn.ensemble.weight_boosting', 'sklearn.ensemble'),
('_classes', 'sklearn.tree.tree', 'sklearn.tree'),
('_export', 'sklearn.tree.export', 'sklearn.tree'),

('_weight_vector', 'sklearn.utils.weight_vector', 'sklearn.utils'),
('_seq_dataset', 'sklearn.utils.seq_dataset', 'sklearn.utils'),
('_fast_dict', 'sklearn.utils.fast_dict', 'sklearn.utils'),
Expand Down
37 changes: 16 additions & 21 deletions sklearn/ensemble/__init__.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
classification, regression and anomaly detection.
"""

from .base import BaseEnsemble
from .forest import RandomForestClassifier
from .forest import RandomForestRegressor
from .forest import RandomTreesEmbedding
from .forest import ExtraTreesClassifier
from .forest import ExtraTreesRegressor
from .bagging import BaggingClassifier
from .bagging import BaggingRegressor
from .iforest import IsolationForest
from .weight_boosting import AdaBoostClassifier
from .weight_boosting import AdaBoostRegressor
from .gradient_boosting import GradientBoostingClassifier
from .gradient_boosting import GradientBoostingRegressor
from .voting import VotingClassifier
from .voting import VotingRegressor
from ._base import BaseEnsemble
from ._forest import RandomForestClassifier
from ._forest import RandomForestRegressor
from ._forest import RandomTreesEmbedding
from ._forest import ExtraTreesClassifier
from ._forest import ExtraTreesRegressor
from ._bagging import BaggingClassifier
from ._bagging import BaggingRegressor
from ._iforest import IsolationForest
from ._weight_boosting import AdaBoostClassifier
from ._weight_boosting import AdaBoostRegressor
from ._gb import GradientBoostingClassifier
from ._gb import GradientBoostingRegressor
from ._voting import VotingClassifier
from ._voting import VotingRegressor
from ._stacking import StackingClassifier
from ._stacking import StackingRegressor

from . import bagging
from . import forest
from . import weight_boosting
from . import gradient_boosting
from . import partial_dependence

__all__ = ["BaseEnsemble",
Expand All @@ -35,5 +31,4 @@
"GradientBoostingRegressor", "AdaBoostClassifier",
"AdaBoostRegressor", "VotingClassifier", "VotingRegressor",
"StackingClassifier", "StackingRegressor",
"bagging", "forest", "gradient_boosting",
"partial_dependence", "weight_boosting"]
"partial_dependence"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from joblib import Parallel, delayed

from .base import BaseEnsemble, _partition_estimators
from ._base import BaseEnsemble, _partition_estimators
from ..base import ClassifierMixin, RegressorMixin
from ..metrics import r2_score, accuracy_score
from ..tree import DecisionTreeClassifier, DecisionTreeRegressor
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sklearn/ensemble/forest.py → sklearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
from ..tree._tree import DTYPE, DOUBLE
from ..utils import check_random_state, check_array, compute_sample_weight
from ..exceptions import DataConversionWarning
from .base import BaseEnsemble, _partition_estimators
from ._base import BaseEnsemble, _partition_estimators
from ..utils.fixes import _joblib_parallel_args
from ..utils.multiclass import check_classification_targets
from ..utils.validation import check_is_fitted
Expand Down
F438
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from abc import abstractmethod
import warnings

from .base import BaseEnsemble
from ._base import BaseEnsemble
from ..base import ClassifierMixin
from ..base import RegressorMixin
from ..base import BaseEstimator
Expand All @@ -44,7 +44,7 @@

from time import time
from ..model_selection import train_test_split
from ..tree.tree import DecisionTreeRegressor
from ..tree import DecisionTreeRegressor
from ..tree._tree import DTYPE, DOUBLE
from ..tree._tree import TREE_LEAF
from . import _gb_losses
Expand Down
3 changes: 1 addition & 2 deletions sklearn/ensemble/iforest.py → sklearn/ensemble/_iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
# License: BSD 3 clause


import numbers
import numpy as np
from scipy.sparse import issparse
Expand All @@ -19,7 +18,7 @@
from ..utils.validation import check_is_fitted, _num_samples
from ..base import OutlierMixin

from .bagging import BaseBagging
from ._bagging import BaseBagging

__all__ = ["IsolationForest"]

Expand Down
6 changes: 2 additions & 4 deletions sklearn/ensemble/_stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
from ..base import clone
from ..base import ClassifierMixin, RegressorMixin, TransformerMixin
from ..base import is_classifier, is_regressor
from ..base import MetaEstimatorMixin

from .base import _parallel_fit_estimator
from .base import _BaseHeterogeneousEnsemble
from ._base import _parallel_fit_estimator
from ._base import _BaseHeterogeneousEnsemble

from ..linear_model import LogisticRegression
from ..linear_model import RidgeCV
Expand All @@ -26,7 +25,6 @@
from ..preprocessing import LabelEncoder

from ..utils import Bunch
from ..utils.metaestimators import _BaseComposition
from ..utils.metaestimators import if_delegate_has_method
from ..utils.multiclass import check_classification_targets
from ..utils.validation import check_is_fitted
Expand Down
4 changes: 2 additions & 2 deletions sklearn/ensemble/voting.py → sklearn/ensemble/_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from ..base import RegressorMixin
from ..base import TransformerMixin
from ..base import clone
from .base import _parallel_fit_estimator
from .base import _BaseHeterogeneousEnsemble
from ._base import _parallel_fit_estimator
from ._base import _BaseHeterogeneousEnsemble
from ..preprocessing import LabelEncoder
from ..utils import Bunch
from ..utils.validation import check_is_fitted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from scipy.special import xlogy

from .base import BaseEnsemble
from ._base import BaseEnsemble
from ..base import ClassifierMixin, RegressorMixin, is_classifier, is_regressor

from ..tree import DecisionTreeClassifier, DecisionTreeRegressor
Expand Down
2 changes: 1 addition & 1 deletion sklearn/ensemble/partial_dependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ..tree._tree import DTYPE
from ..utils import deprecated

from .gradient_boosting import BaseGradientBoosting
from ._gb import BaseGradientBoosting


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion sklearn/ensemble/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from sklearn.datasets import load_iris
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble.base import _set_random_states
from sklearn.ensemble._base import _set_random_states
from sklearn.linear_model import Perceptron
from collections import OrderedDict
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
Expand Down
2 changes: 1 addition & 1 deletion sklearn/ensemble/tests/test_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from sklearn.utils.validation import check_random_state
from sklearn.utils.fixes import comb

from sklearn.tree.tree import SPARSE_SPLITTERS
from sklearn.tree._classes import SPARSE_SPLITTERS


# toy sample
Expand Down
6 changes: 3 additions & 3 deletions sklearn/ensemble/tests/test_iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from sklearn.model_selection import ParameterGrid
from sklearn.ensemble import IsolationForest
from sklearn.ensemble.iforest import _average_path_length
from sklearn.ensemble._iforest import _average_path_length
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston, load_iris
from sklearn.utils import check_random_state
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_iforest_warm_start():
# mock get_chunk_n_rows to actually test more than one chunk (here one
# chunk = 3 rows:
@patch(
"sklearn.ensemble.iforest.get_chunk_n_rows",
"sklearn.ensemble._iforest.get_chunk_n_rows",
side_effect=Mock(**{"return_value": 3}),
)
@pytest.mark.parametrize(
Expand All @@ -304,7 +304,7 @@ def test_iforest_chunks_works1(

# idem with chunk_size = 5 rows
@patch(
"sklearn.ensemble.iforest.get_chunk_n_rows",
"sklearn.ensemble._iforest.get_chunk_n_rows",
side_effect=Mock(**{"return_value": 10}),
)
@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions sklearn/ensemble/tests/test_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import AdaBoostRegressor
from sklearn.ensemble import weight_boosting
from sklearn.ensemble._weight_boosting import _samme_proba
from scipy.sparse import csc_matrix
from scipy.sparse import csr_matrix
from scipy.sparse import coo_matrix
Expand Down Expand Up @@ -64,7 +64,7 @@ def predict_proba(self, X):
return probs
mock = MockEstimator()

samme_proba = weight_boosting._samme_proba(mock, 3, np.ones_like(probs))
samme_proba = _samme_proba(mock, 3, np.ones_like(probs))

assert_array_equal(samme_proba.shape, probs.shape)
assert np.isfinite(samme_proba).all()
Expand Down
2 changes: 1 addition & 1 deletion sklearn/inspection/partial_dependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..utils.validation import check_is_fitted
from ..tree._tree import DTYPE
from ..exceptions import NotFittedError
from ..ensemble.gradient_boosting import BaseGradientBoosting
from ..ensemble._gb import BaseGradientBoosting
from sklearn.ensemble._hist_gradient_boosting.gradient_boosting import (
BaseHistGradientBoosting)

Expand Down
11 changes: 11 additions & 0 deletions sklearn/tests/test_import_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
# appropriate error message.

@pytest.mark.parametrize('deprecated_path, importee', (
('sklearn.tree.tree', 'DecisionTreeClassifier'),
('sklearn.tree.export', 'export_graphviz'),

('sklearn.ensemble.base', 'BaseEnsemble'),
('sklearn.ensemble.forest', 'RandomForestClassifier'),
('sklearn.ensemble.bagging', 'BaggingClassifier'),
('sklearn.ensemble.iforest', 'IsolationForest'),
('sklearn.ensemble.weight_boosting', 'AdaBoostClassifier'),
('sklearn.ensemble.gradient_boosting', 'GradientBoostingClassifier'),
('sklearn.ensemble.voting', 'VotingClassifier'),

('sklearn.neural_network.rbm', 'BernoulliRBM'),
('sklearn.neural_network.multilayer_perceptron', 'MLPClassifier'),

Expand Down
14 changes: 8 additions & 6 deletions sklearn/tree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
classification and regression.
"""

from .tree import DecisionTreeClassifier
from .tree import DecisionTreeRegressor
from .tree import ExtraTreeClassifier
from .tree import ExtraTreeRegressor
from .export import export_graphviz, plot_tree, export_text
from ._classes import BaseDecisionTree
from ._classes import DecisionTreeClassifier
from ._classes import DecisionTreeRegressor
from ._classes import ExtraTreeClassifier
from ._classes import ExtraTreeRegressor
from ._export import export_graphviz, plot_tree, export_text

__all__ = ["DecisionTreeClassifier", "DecisionTreeRegressor",
__all__ = ["BaseDecisionTree",
"DecisionTreeClassifier", "DecisionTreeRegressor",
"ExtraTreeClassifier", "ExtraTreeRegressor", "export_graphviz",
"plot_tree", "export_text"]
File renamed without changes.
3 changes: 1 addition & 2 deletions sklearn/tree/export.py → sklearn/tree/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# Giuseppe Vettigli <vettigli@gmail.com>
# License: BSD 3 clause
from io import StringIO

from numbers import Integral

import numpy as np
Expand Down Expand Up @@ -833,7 +832,7 @@ def export_text(decision_tree, feature_names=None, max_depth=10,

>>> from sklearn.datasets import load_iris
>>> from sklearn.tree import DecisionTreeClassifier
>>> from sklearn.tree.export import export_text
>>> from sklearn.tree import export_text
>>> iris = load_iris()
>>> X = iris['data']
>>> y = iris['target']
Expand Down
4 changes: 2 additions & 2 deletions sklearn/tree/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

from sklearn import tree
from sklearn.tree._tree import TREE_LEAF, TREE_UNDEFINED
from sklearn.tree.tree import CRITERIA_CLF
from sklearn.tree.tree import CRITERIA_REG
from sklearn.tree._classes import CRITERIA_CLF
from sklearn.tree._classes import CRITERIA_REG
from sklearn import datasets

from sklearn.utils import compute_sample_weight
Expand Down
0