Skip to content

Commit

Permalink
[MRG] More deprecation for 0.24 (scikit-learn#17142)
Browse files Browse the repository at this point in the history
* normalize_components in sparsePCA

* changed default strategy of Dummy to prior and removed outputs_2d ttribute

* removed usage of None to drop estimator in ensemble and behaviour param of IsolationForest

* remove support for drop=None in Voting

* removed some warning decorators

* remove feature_extraction.extract_patches

* removed VectorizerMixin and copy parameter from TFIDFVectorizer

* kernel.set_params now raises attributeerror

* removed fig from plot_partial_dependence

* removed iid parameter of search estimators

* removed brier_scorer

* raise error in split when shuffle is False and random_state is not None

* removed MultiOutputEstimator

* removed base classes of NaiveBayes

* removed drop from pipeline

* removed utils in random_projection

* removed presort and classes_ in trees

* flake8

* fixed some tests

* flake

* fixed docstring

* fixed other one

* some left

* mmmm
  • Loading branch information
NicolasHug authored May 20, 2020
1 parent 1931e14 commit ac8cbb3
Show file tree
Hide file tree
Showing 40 changed files with 165 additions and 904 deletions.
56 changes: 3 additions & 53 deletions sklearn/decomposition/_sparse_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort
# License: BSD 3 clause

import warnings

import numpy as np

from ..utils import check_random_state, check_array
Expand All @@ -14,22 +12,6 @@
from ._dict_learning import dict_learning, dict_learning_online


# FIXME: remove in 0.24
def _check_normalize_components(normalize_components, estimator_name):
if normalize_components != 'deprecated':
if normalize_components:
warnings.warn(
"'normalize_components' has been deprecated in 0.22 and "
"will be removed in 0.24. Remove the parameter from the "
" constructor.", FutureWarning
)
else:
raise NotImplementedError(
"normalize_components=False is not supported starting from "
"0.22. Remove this parameter from the constructor."
)


class SparsePCA(TransformerMixin, BaseEstimator):
"""Sparse Principal Components Analysis (SparsePCA)
Expand Down Expand Up @@ -85,16 +67,6 @@ class SparsePCA(TransformerMixin, BaseEstimator):
across multiple function calls.
See :term:`Glossary <random_state>`.
normalize_components : 'deprecated'
This parameter does not have any effect. The components are always
normalized.
.. versionadded:: 0.20
.. deprecated:: 0.22
``normalize_components`` is deprecated in 0.22 and will be removed
in 0.24.
Attributes
----------
components_ : array, [n_components, n_features]
Expand Down Expand Up @@ -140,8 +112,7 @@ class SparsePCA(TransformerMixin, BaseEstimator):
@_deprecate_positional_args
def __init__(self, n_components=None, *, alpha=1, ridge_alpha=0.01,
max_iter=1000, tol=1e-8, method='lars', n_jobs=None,
U_init=None, V_init=None, verbose=False, random_state=None,
normalize_components='deprecated'):
U_init=None, V_init=None, verbose=False, random_state=None):
self.n_components = n_components
self.alpha = alpha
self.ridge_alpha = ridge_alpha
Expand All @@ -153,7 +124,6 @@ def __init__(self, n_components=None, *, alpha=1, ridge_alpha=0.01,
self.V_init = V_init
self.verbose = verbose
self.random_state = random_state
self.normalize_components = normalize_components

def fit(self, X, y=None):
"""Fit the model from data in X.
Expand All @@ -174,10 +144,6 @@ def fit(self, X, y=None):
random_state = check_random_state(self.random_state)
X = self._validate_data(X)

_check_normalize_components(
self.normalize_components, self.__class__.__name__
)

self.mean_ = X.mean(axis=0)
X = X - self.mean_

Expand Down Expand Up @@ -304,16 +270,6 @@ class MiniBatchSparsePCA(SparsePCA):
across multiple function calls.
See :term:`Glossary <random_state>`.
normalize_components : 'deprecated'
This parameter does not have any effect. The components are always
normalized.
.. versionadded:: 0.20
.. deprecated:: 0.22
``normalize_components`` is deprecated in 0.22 and will be removed
in 0.24.
Attributes
----------
components_ : array, [n_components, n_features]
Expand Down Expand Up @@ -357,13 +313,11 @@ class MiniBatchSparsePCA(SparsePCA):
@_deprecate_positional_args
def __init__(self, n_components=None, *, alpha=1, ridge_alpha=0.01,
n_iter=100, callback=None, batch_size=3, verbose=False,
shuffle=True, n_jobs=None, method='lars', random_state=None,
normalize_components='deprecated'):
shuffle=True, n_jobs=None, method='lars', random_state=None):
super().__init__(
n_components=n_components, alpha=alpha, verbose=verbose,
ridge_alpha=ridge_alpha, n_jobs=n_jobs, method=method,
random_state=random_state,
normalize_components=normalize_components)
random_state=random_state)
self.n_iter = n_iter
self.callback = callback
self.batch_size = batch_size
Expand All @@ -388,10 +342,6 @@ def fit(self, X, y=None):
random_state = check_random_state(self.random_state)
X = self._validate_data(X)

_check_normalize_components(
self.normalize_components, self.__class__.__name__
)

self.mean_ = X.mean(axis=0)
X = X - self.mean_

Expand Down
1 change: 0 additions & 1 deletion sklearn/decomposition/_truncated_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class TruncatedSVD(TransformerMixin, BaseEstimator):
--------
>>> from sklearn.decomposition import TruncatedSVD
>>> from scipy.sparse import random as sparse_random
>>> from sklearn.random_projection import sparse_random_matrix
>>> X = sparse_random(100, 100, density=0.01, format='csr',
... random_state=42)
>>> svd = TruncatedSVD(n_components=5, n_iter=7, random_state=42)
Expand Down
20 changes: 0 additions & 20 deletions sklearn/decomposition/tests/test_sparse_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,6 @@ def test_pca_vs_spca():
assert_allclose(results_test_pca, results_test_spca)


@pytest.mark.parametrize("spca", [SparsePCA, MiniBatchSparsePCA])
def test_spca_deprecation_warning(spca):
rng = np.random.RandomState(0)
Y, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng)

warn_msg = "'normalize_components' has been deprecated in 0.22"
with pytest.warns(FutureWarning, match=warn_msg):
spca(normalize_components=True).fit(Y)


@pytest.mark.parametrize("spca", [SparsePCA, MiniBatchSparsePCA])
def test_spca_error_unormalized_components(spca):
rng = np.random.RandomState(0)
Y, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng)

err_msg = "normalize_components=False is not supported starting "
with pytest.raises(NotImplementedError, match=err_msg):
spca(normalize_components=False).fit(Y)


@pytest.mark.parametrize("SPCA", [SparsePCA, MiniBatchSparsePCA])
@pytest.mark.parametrize("n_components", [None, 3])
def test_spca_n_components_(SPCA, n_components):
Expand Down
48 changes: 9 additions & 39 deletions sklearn/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
from .utils.random import _random_choice_csc
from .utils.stats import _weighted_percentile
from .utils.multiclass import class_distribution
from .utils import deprecated
from .utils.validation import _deprecate_positional_args


class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
"""
DummyClassifier is a classifier that makes predictions using simple rules.
Expand All @@ -33,7 +33,7 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
Parameters
----------
strategy : str, default="stratified"
strategy : str, default="prior"
Strategy to use to generate predictions.
* "stratified": generates predictions by respecting the training
Expand All @@ -47,14 +47,9 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
the user. This is useful for metrics that evaluate a non-majority
class
.. versionchanged:: 0.22
The default value of `strategy` will change to "prior" in version
0.24. Starting from version 0.22, a warning will be raised if
`strategy` is not explicitly set.
.. versionadded:: 0.17
Dummy Classifier now supports prior fitting strategy using
parameter *prior*.
.. versionchanged:: 0.24
The default value of `strategy` has changed to "prior" in version
0.24.
random_state : int, RandomState instance or None, optional, default=None
Controls the randomness to generate the predictions when
Expand Down Expand Up @@ -99,7 +94,7 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
0.75
"""
@_deprecate_positional_args
def __init__(self, *, strategy="warn", random_state=None,
def __init__(self, *, strategy="prior", random_state=None,
constant=None):
self.strategy = strategy
self.random_state = random_state
Expand All @@ -126,16 +121,11 @@ def fit(self, X, y, sample_weight=None):
allowed_strategies = ("most_frequent", "stratified", "uniform",
"constant", "prior")

# TODO: Remove in 0.24
if self.strategy == "warn":
warnings.warn("The default value of strategy will change from "
"stratified to prior in 0.24.", FutureWarning)
self._strategy = "stratified"
elif self.strategy not in allowed_strategies:
if self.strategy not in allowed_strategies:
raise ValueError("Unknown strategy type: %s, expected one of %s."
% (self.strategy, allowed_strategies))
else:
self._strategy = self.strategy

self._strategy = self.strategy

if self._strategy == "uniform" and sp.issparse(y):
y = y.toarray()
Expand Down Expand Up @@ -395,16 +385,6 @@ def score(self, X, y, sample_weight=None):
X = np.zeros(shape=(len(y), 1))
return super().score(X, y, sample_weight)

# mypy error: Decorated property not supported
@deprecated( # type: ignore
"The outputs_2d_ attribute is deprecated in version 0.22 "
"and will be removed in version 0.24. It is equivalent to "
"n_outputs_ > 1."
)
@property
def outputs_2d_(self):
return self.n_outputs_ != 1


class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
"""
Expand Down Expand Up @@ -624,13 +604,3 @@ def score(self, X, y, sample_weight=None):
if X is None:
X = np.zeros(shape=(len(y), 1))
return super().score(X, y, sample_weight)

# mypy error: Decorated property not supported
@deprecated( # type: ignore
"The outputs_2d_ attribute is deprecated in version 0.22 "
"and will be removed in version 0.24. It is equivalent to "
"n_outputs_ > 1."
)
@property
def outputs_2d_(self):
return self.n_outputs_ != 1
14 changes: 2 additions & 12 deletions sklearn/ensemble/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from abc import ABCMeta, abstractmethod
import numbers
import warnings
from typing import List

import numpy as np
Expand Down Expand Up @@ -227,16 +226,7 @@ def _validate_estimators(self):
# defined by MetaEstimatorMixin
self._validate_names(names)

# FIXME: deprecate the usage of None to drop an estimator from the
# ensemble. Remove in 0.24
if any(est is None for est in estimators):
warnings.warn(
"Using 'None' to drop an estimator from the ensemble is "
"deprecated in 0.22 and support will be dropped in 0.24. "
"Use the string 'drop' instead.", FutureWarning
)

has_estimator = any(est not in (None, 'drop') for est in estimators)
has_estimator = any(est != 'drop' for est in estimators)
if not has_estimator:
raise ValueError(
"All estimators are dropped. At least one is required "
Expand All @@ -247,7 +237,7 @@ def _validate_estimators(self):
else is_regressor)

for est in estimators:
if est not in (None, 'drop') and not is_estimator_type(est):
if est != 'drop' and not is_estimator_type(est):
raise ValueError(
"The estimator {} should be a {}.".format(
est.__class__.__name__, is_estimator_type.__name__[3:]
Expand Down
29 changes: 0 additions & 29 deletions sklearn/ensemble/_iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ class IsolationForest(OutlierMixin, BaseBagging):
:obj:`joblib.parallel_backend` context. ``-1`` means using all
processors. See :term:`Glossary <n_jobs>` for more details.
behaviour : str, default='deprecated'
This parameter has no effect, is deprecated, and will be removed.
.. versionadded:: 0.20
``behaviour`` is added in 0.20 for back-compatibility purpose.
.. deprecated:: 0.20
``behaviour='old'`` is deprecated in 0.20 and will not be possible
in 0.22.
.. deprecated:: 0.22
``behaviour`` parameter is deprecated in 0.22 and removed in
0.24.
random_state : int or RandomState, default=None
Controls the pseudo-randomness of the selection of the feature
and split values for each branching step and each tree in the forest.
Expand Down Expand Up @@ -192,7 +178,6 @@ def __init__(self, *,
max_features=1.,
bootstrap=False,
n_jobs=None,
behaviour='deprecated',
random_state=None,
verbose=0,
warm_start=False):
Expand All @@ -212,7 +197,6 @@ def __init__(self, *,
random_state=random_state,
verbose=verbose)

self.behaviour = behaviour
self.contamination = contamination

def _set_oob_score(self, X, y):
Expand Down Expand Up @@ -247,19 +231,6 @@ def fit(self, X, y=None, sample_weight=None):
self : object
Fitted estimator.
"""
if self.behaviour != 'deprecated':
if self.behaviour == 'new':
warn(
"'behaviour' is deprecated in 0.22 and will be removed "
"in 0.24. You should not pass or set this parameter.",
FutureWarning
)
else:
raise NotImplementedError(
"The old behaviour of IsolationForest is not implemented "
"anymore. Remove the 'behaviour' parameter."
)

X = check_array(X, accept_sparse=['csc'])
if issparse(X):
# Pre-sort indices to avoid that each individual tree of the
Expand Down
Loading

0 comments on commit ac8cbb3

Please sign in to comment.