Skip to content

[MRG] Fixes #8174: deprecation warning #8177

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

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 10 additions & 0 deletions sklearn/cluster/birch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def _split_node(node, threshold, branching_factor):


class _CFNode(object):

"""Each node in a CFTree is called a CFNode.

The CFNode can have a maximum of branching_factor
Expand Down Expand Up @@ -134,6 +135,7 @@ class _CFNode(object):
view of ``init_sq_norm_``.

"""

def __init__(self, threshold, branching_factor, is_leaf, n_features):
self.threshold = threshold
self.branching_factor = branching_factor
Expand Down Expand Up @@ -241,6 +243,7 @@ def insert_cf_subcluster(self, subcluster):


class _CFSubcluster(object):

"""Each subcluster in a CFNode is called a CFSubcluster.

A CFSubcluster can have a CFNode has its child.
Expand Down Expand Up @@ -275,6 +278,7 @@ class _CFSubcluster(object):
Squared norm of the subcluster. Used to prevent recomputing when
pairwise minimum distances are computed.
"""

def __init__(self, linear_sum=None):
if linear_sum is None:
self.n_samples_ = 0
Expand Down Expand Up @@ -322,6 +326,7 @@ def radius(self):


class Birch(BaseEstimator, TransformerMixin, ClusterMixin):

"""Implements the Birch clustering algorithm.

Every new sample is inserted into the root of the Clustering Feature
Expand Down Expand Up @@ -565,6 +570,11 @@ def transform(self, X, y=None):
X_trans : {array-like, sparse matrix}, shape (n_samples, n_clusters)
Transformed data.
"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, 'subcluster_centers_')
return euclidean_distances(X, self.subcluster_centers_)

Expand Down
8 changes: 7 additions & 1 deletion sklearn/cluster/k_means_.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ def _init_centroids(X, k, init, random_state=None, x_squared_norms=None,


class KMeans(BaseEstimator, ClusterMixin, TransformerMixin):

"""K-Means clustering

Read more in the :ref:`User Guide <k_means>`.
Expand Down Expand Up @@ -928,8 +929,12 @@ def transform(self, X, y=None):
X_new : array, shape [n_samples, k]
X transformed in the new space.
"""
check_is_fitted(self, 'cluster_centers_')
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, 'cluster_centers_')
X = self._check_test_data(X)
return self._transform(X)

Expand Down Expand Up @@ -1183,6 +1188,7 @@ def _mini_batch_convergence(model, iteration_idx, n_iter, tol,


class MiniBatchKMeans(KMeans):

"""Mini-Batch K-Means clustering

Read more in the :ref:`User Guide <mini_batch_kmeans>`.
Expand Down
10 changes: 9 additions & 1 deletion sklearn/decomposition/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
# License: BSD 3 clause

import warnings

import numpy as np
from scipy import linalg

Expand All @@ -20,11 +22,13 @@


class _BasePCA(six.with_metaclass(ABCMeta, BaseEstimator, TransformerMixin)):

"""Base class for PCA methods.

Warning: This class should not be used directly.
Use derived classes instead.
"""

def get_covariance(self):
"""Compute data covariance with the generative model.

Expand Down Expand Up @@ -97,7 +101,6 @@ def fit(X, y=None):
Returns the instance itself.
"""


def transform(self, X, y=None):
"""Apply dimensionality reduction to X.

Expand Down Expand Up @@ -125,6 +128,11 @@ def transform(self, X, y=None):
IncrementalPCA(batch_size=3, copy=True, n_components=2, whiten=False)
>>> ipca.transform(X) # doctest: +SKIP
"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, ['mean_', 'components_'], all_or_any=all)

X = check_array(X)
Expand Down
19 changes: 16 additions & 3 deletions sklearn/decomposition/dict_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort
# License: BSD 3 clause

import warnings

import time
import sys
import itertools
Expand Down Expand Up @@ -145,7 +147,7 @@ def _sparse_encode(X, dictionary, gram, cov=None, algorithm='lasso_lars',

elif algorithm == 'threshold':
new_code = ((np.sign(cov) *
np.maximum(np.abs(cov) - regularization, 0)).T)
np.maximum(np.abs(cov) - regularization, 0)).T)

elif algorithm == 'omp':
# TODO: Should verbose argument be passed to this?
Expand Down Expand Up @@ -722,8 +724,8 @@ def dict_learning_online(X, n_components=2, alpha=1, n_iter=100,
sys.stdout.flush()
elif verbose:
if verbose > 10 or ii % ceil(100. / verbose) == 0:
print ("Iteration % 3i (elapsed time: % 3is, % 4.1fmn)"
% (ii, dt, dt / 60))
print("Iteration % 3i (elapsed time: % 3is, % 4.1fmn)"
% (ii, dt, dt / 60))

this_code = sparse_encode(this_X, dictionary.T, algorithm=method,
alpha=alpha, n_jobs=n_jobs).T
Expand Down Expand Up @@ -777,6 +779,7 @@ def dict_learning_online(X, n_components=2, alpha=1, n_iter=100,


class SparseCodingMixin(TransformerMixin):

"""Sparse coding mixin"""

def _set_sparse_coding_params(self, n_components,
Expand Down Expand Up @@ -809,6 +812,11 @@ def transform(self, X, y=None):
Transformed data

"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, 'components_')

# XXX : kwargs is not documented
Expand All @@ -832,6 +840,7 @@ def transform(self, X, y=None):


class SparseCoder(BaseEstimator, SparseCodingMixin):

"""Sparse coding

Finds a sparse representation of data against a fixed, precomputed
Expand Down Expand Up @@ -917,6 +926,7 @@ def fit(self, X, y=None):


class DictionaryLearning(BaseEstimator, SparseCodingMixin):

"""Dictionary learning

Finds a dictionary (a set of atoms) that can best be used to represent data
Expand Down Expand Up @@ -1028,6 +1038,7 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin):
SparsePCA
MiniBatchSparsePCA
"""

def __init__(self, n_components=None, alpha=1, max_iter=1000, tol=1e-8,
fit_algorithm='lars', transform_algorithm='omp',
transform_n_nonzero_coefs=None, transform_alpha=None,
Expand Down Expand Up @@ -1083,6 +1094,7 @@ def fit(self, X, y=None):


class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):

"""Mini-batch dictionary learning

Finds a dictionary (a set of atoms) that can best be used to represent data
Expand Down Expand Up @@ -1194,6 +1206,7 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):
MiniBatchSparsePCA

"""

def __init__(self, n_components=None, alpha=1, n_iter=1000,
fit_algorithm='lars', n_jobs=1, batch_size=3,
shuffle=True, dict_init=None, transform_algorithm='omp',
Expand Down
14 changes: 11 additions & 3 deletions sklearn/decomposition/fastica_.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def g(x, fun_args):
n_components = min(n, p)
if (n_components > min(n, p)):
n_components = min(n, p)
warnings.warn('n_components is too large: it will be set to %s' % n_components)
warnings.warn(
'n_components is too large: it will be set to %s' % n_components)

if whiten:
# Centering the columns (ie the variables)
Expand All @@ -316,8 +317,8 @@ def g(x, fun_args):
X1 = as_float_array(X, copy=False) # copy has been taken care of

if w_init is None:
w_init = np.asarray(random_state.normal(size=(n_components,
n_components)), dtype=X1.dtype)
w_init = np.asarray(random_state.normal(
size=(n_components, n_components)), dtype=X1.dtype)

else:
w_init = np.asarray(w_init)
Expand Down Expand Up @@ -374,6 +375,7 @@ def g(x, fun_args):


class FastICA(BaseEstimator, TransformerMixin):

"""FastICA: a fast algorithm for Independent Component Analysis.

Read more in the :ref:`User Guide <ICA>`.
Expand Down Expand Up @@ -439,6 +441,7 @@ def my_g(x):
pp. 411-430`

"""

def __init__(self, n_components=None, algorithm='parallel', whiten=True,
fun='logcosh', fun_args=None, max_iter=200, tol=1e-4,
w_init=None, random_state=None):
Expand Down Expand Up @@ -539,6 +542,11 @@ def transform(self, X, y=None, copy=True):
-------
X_new : array-like, shape (n_samples, n_components)
"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, 'mixing_')

X = check_array(X, copy=copy, dtype=FLOAT_DTYPES)
Expand Down
8 changes: 8 additions & 0 deletions sklearn/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# License: BSD 3 clause

import warnings
from math import log, sqrt

import numpy as np
Expand Down Expand Up @@ -105,6 +106,7 @@ def _infer_dimension_(spectrum, n_samples, n_features):


class PCA(_BasePCA):

"""Principal component analysis (PCA)

Linear dimensionality reduction using Singular Value Decomposition of the
Expand Down Expand Up @@ -558,6 +560,7 @@ def score(self, X, y=None):
"DOES NOT store whiten ``components_``. Apply transform to get "
"them.")
class RandomizedPCA(BaseEstimator, TransformerMixin):

"""Principal component analysis (PCA) using randomized SVD

.. deprecated:: 0.18
Expand Down Expand Up @@ -736,6 +739,11 @@ def transform(self, X, y=None):
X_new : array-like, shape (n_samples, n_components)

"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

check_is_fitted(self, 'mean_')

X = check_array(X)
Expand Down
7 changes: 7 additions & 0 deletions sklearn/feature_extraction/dict_vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Dan Blanchard <dblanchard@ets.org>
# License: BSD 3 clause

import warnings
from array import array
from collections import Mapping
from operator import itemgetter
Expand All @@ -25,6 +26,7 @@ def _tosequence(X):


class DictVectorizer(BaseEstimator, TransformerMixin):

"""Transforms lists of feature-value mappings to vectors.

This transformer turns lists of mappings (dict-like objects) of feature
Expand Down Expand Up @@ -289,6 +291,11 @@ def transform(self, X, y=None):
Xa : {array, sparse matrix}
Feature vectors; always 2-d.
"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

if self.sparse:
return self._transform(X, fitting=False)

Expand Down
7 changes: 7 additions & 0 deletions sklearn/feature_extraction/hashing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Author: Lars Buitinck
# License: BSD 3 clause

import warnings
import numbers

import numpy as np
Expand All @@ -16,6 +17,7 @@ def _iteritems(d):


class FeatureHasher(BaseEstimator, TransformerMixin):

"""Implements feature hashing, aka the hashing trick.

This class turns sequences of symbolic feature names (strings) into
Expand Down Expand Up @@ -133,6 +135,11 @@ def transform(self, raw_X, y=None):
Feature matrix, for use with estimators or further transformers.

"""
if y is not None:
warnings.warn('y is deprecated and will be'
' removed in a future version',
DeprecationWarning)

raw_X = iter(raw_X)
if self.input_type == "dict":
raw_X = (_iteritems(d) for d in raw_X)
Expand Down
Loading