Skip to content

Commit 6f783de

Browse files
authored
[MRG+2] Update the repo for release (#295)
* Get rid of deprecations * Some more modifications * more modifs and fixes * remove flake8 error * some fixes * fix * Fixes * Fixes * Add SCML and change version number * add warning for scml, and fix doc generation * small fix * fix
1 parent 43a60c9 commit 6f783de

22 files changed

+93
-1060
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ metric-learn contains efficient Python implementations of several popular superv
1111
- Information Theoretic Metric Learning (ITML)
1212
- Sparse Determinant Metric Learning (SDML)
1313
- Least Squares Metric Learning (LSML)
14+
- Sparse Compositional Metric Learning (SCML)
1415
- Neighborhood Components Analysis (NCA)
1516
- Local Fisher Discriminant Analysis (LFDA)
1617
- Relative Components Analysis (RCA)

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
u'Bellet and Nathalie Vauquier')
2525
author = (u'CJ Carey, Yuan Tang, William de Vazelhes, Aurélien Bellet and '
2626
u'Nathalie Vauquier')
27-
version = '0.5.0'
28-
release = '0.5.0'
27+
version = '0.6.0'
28+
release = '0.6.0'
2929
language = 'en'
3030

3131
exclude_patterns = ['_build']

doc/modules.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
metric_learn
2+
============
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
metric_learn

doc/supervised.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ classes will be large. To do so, we fit the metric learner (example:
5050
>>> from metric_learn import NCA
5151
>>> nca = NCA(random_state=42)
5252
>>> nca.fit(X, y)
53-
NCA(init=None, max_iter=100, n_components=None, num_dims='deprecated',
53+
NCA(init='auto', max_iter=100, n_components=None,
5454
preprocessor=None, random_state=42, tol=None, verbose=False)
5555

5656

doc/weakly_supervised.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ are respected.
135135
>>> mmc = MMC(random_state=42)
136136
>>> mmc.fit(tuples, y)
137137
MMC(A0='deprecated', convergence_threshold=0.001, diagonal=False,
138-
diagonal_c=1.0, init=None, max_iter=100, max_proj=10000,
138+
diagonal_c=1.0, init='auto', max_iter=100, max_proj=10000,
139139
preprocessor=None, random_state=42, verbose=False)
140140

141141
Or alternatively (using a preprocessor):
@@ -250,8 +250,8 @@ tuples).
250250
>>> y_pairs = np.array([1, -1])
251251
>>> mmc = MMC(random_state=42)
252252
>>> mmc.fit(pairs, y_pairs)
253-
MMC(A0='deprecated', convergence_threshold=0.001, diagonal=False,
254-
diagonal_c=1.0, init=None, max_iter=100, max_proj=10000, preprocessor=None,
253+
MMC(convergence_threshold=0.001, diagonal=False,
254+
diagonal_c=1.0, init='auto', max_iter=100, max_proj=10000, preprocessor=None,
255255
random_state=42, verbose=False)
256256

257257
Here, we learned a metric that puts the two first points closer

examples/plot_metric_learning_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def plot_tsne(X, y, colormap=plt.cm.Paired):
289289
# - See more in the documentation of the class :py:class:`LFDA
290290
# <metric_learn.LFDA>`
291291

292-
lfda = metric_learn.LFDA(k=2, num_dims=2)
292+
lfda = metric_learn.LFDA(k=2, n_components=2)
293293
X_lfda = lfda.fit_transform(X, y)
294294

295295
plot_tsne(X_lfda, y)

metric_learn/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.5.0'
1+
__version__ = '0.6.0'

metric_learn/base_metric.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import numpy as np
1010
from abc import ABCMeta, abstractmethod
1111
from ._util import ArrayIndexer, check_input, validate_vector
12-
import warnings
1312

1413

1514
class BaseMetricLearner(BaseEstimator, metaclass=ABCMeta):
@@ -285,15 +284,6 @@ def metric_fun(u, v, squared=False):
285284

286285
get_metric.__doc__ = BaseMetricLearner.get_metric.__doc__
287286

288-
def metric(self):
289-
"""Deprecated. Will be removed in v0.6.0. Use `get_mahalanobis_matrix`
290-
instead"""
291-
# TODO: remove this method in version 0.6.0
292-
warnings.warn(("`metric` is deprecated since version 0.5.0 and will be "
293-
"removed in 0.6.0. Use `get_mahalanobis_matrix` instead."),
294-
DeprecationWarning)
295-
return self.get_mahalanobis_matrix()
296-
297287
def get_mahalanobis_matrix(self):
298288
"""Returns a copy of the Mahalanobis matrix learned by the metric learner.
299289

metric_learn/itml.py

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
Information Theoretic Metric Learning (ITML)
33
"""
44

5-
import warnings
65
import numpy as np
7-
from sklearn.exceptions import ChangedBehaviorWarning
86
from sklearn.metrics import pairwise_distances
97
from sklearn.utils.validation import check_array
108
from sklearn.base import TransformerMixin
@@ -19,23 +17,17 @@ class _BaseITML(MahalanobisMixin):
1917
_tuple_size = 2 # constraints are pairs
2018

2119
def __init__(self, gamma=1., max_iter=1000, convergence_threshold=1e-3,
22-
prior='identity', A0='deprecated', verbose=False,
20+
prior='identity', verbose=False,
2321
preprocessor=None, random_state=None):
2422
self.gamma = gamma
2523
self.max_iter = max_iter
2624
self.convergence_threshold = convergence_threshold
2725
self.prior = prior
28-
self.A0 = A0
2926
self.verbose = verbose
3027
self.random_state = random_state
3128
super(_BaseITML, self).__init__(preprocessor)
3229

3330
def _fit(self, pairs, y, bounds=None):
34-
if self.A0 != 'deprecated':
35-
warnings.warn('"A0" parameter is not used.'
36-
' It has been deprecated in version 0.5.0 and will be'
37-
'removed in 0.6.0. Use "prior" instead.',
38-
DeprecationWarning)
3931
pairs, y = self._prepare_inputs(pairs, y,
4032
type_of_inputs='tuples')
4133
# init bounds
@@ -155,11 +147,6 @@ class ITML(_BaseITML, _PairsClassifierMixin):
155147
(n_features, n_features), that will be used as such to set the
156148
prior.
157149
158-
A0 : Not used
159-
.. deprecated:: 0.5.0
160-
`A0` was deprecated in version 0.5.0 and will
161-
be removed in 0.6.0. Use 'prior' instead.
162-
163150
verbose : bool, optional (default=False)
164151
If True, prints information while learning
165152
@@ -276,21 +263,10 @@ class ITML_Supervised(_BaseITML, TransformerMixin):
276263
convergence_threshold : float, optional (default=1e-3)
277264
Tolerance of the optimization procedure.
278265
279-
num_labeled : Not used
280-
.. deprecated:: 0.5.0
281-
`num_labeled` was deprecated in version 0.5.0 and will
282-
be removed in 0.6.0.
283-
284266
num_constraints : int, optional (default=None)
285267
Number of constraints to generate. If None, default to `20 *
286268
num_classes**2`.
287269
288-
bounds : Not used
289-
.. deprecated:: 0.5.0
290-
`bounds` was deprecated in version 0.5.0 and will
291-
be removed in 0.6.0. Set `bounds` at fit time instead :
292-
`itml_supervised.fit(X, y, bounds=...)`
293-
294270
prior : string or numpy array, optional (default='identity')
295271
Initialization of the Mahalanobis matrix. Possible options are
296272
'identity', 'covariance', 'random', and a numpy array of shape
@@ -313,11 +289,6 @@ class ITML_Supervised(_BaseITML, TransformerMixin):
313289
(n_features, n_features), that will be used as such to set the
314290
prior.
315291
316-
A0 : Not used
317-
.. deprecated:: 0.5.0
318-
`A0` was deprecated in version 0.5.0 and will
319-
be removed in 0.6.0. Use 'prior' instead.
320-
321292
verbose : bool, optional (default=False)
322293
If True, prints information while learning
323294
@@ -368,18 +339,15 @@ class ITML_Supervised(_BaseITML, TransformerMixin):
368339
"""
369340

370341
def __init__(self, gamma=1.0, max_iter=1000, convergence_threshold=1e-3,
371-
num_labeled='deprecated', num_constraints=None,
372-
bounds='deprecated', prior='identity', A0='deprecated',
342+
num_constraints=None, prior='identity',
373343
verbose=False, preprocessor=None, random_state=None):
374344
_BaseITML.__init__(self, gamma=gamma, max_iter=max_iter,
375345
convergence_threshold=convergence_threshold,
376-
A0=A0, prior=prior, verbose=verbose,
346+
prior=prior, verbose=verbose,
377347
preprocessor=preprocessor, random_state=random_state)
378-
self.num_labeled = num_labeled
379348
self.num_constraints = num_constraints
380-
self.bounds = bounds
381349

382-
def fit(self, X, y, random_state='deprecated', bounds=None):
350+
def fit(self, X, y, bounds=None):
383351
"""Create constraints from labels and learn the ITML model.
384352
385353
@@ -391,12 +359,6 @@ def fit(self, X, y, random_state='deprecated', bounds=None):
391359
y : (n) array-like
392360
Data labels.
393361
394-
random_state : Not used
395-
.. deprecated:: 0.5.0
396-
`random_state` in the `fit` function was deprecated in version 0.5.0
397-
and will be removed in 0.6.0. Set `random_state` at initialization
398-
instead (when instantiating a new `ITML_Supervised` object).
399-
400362
bounds : array-like of two numbers
401363
Bounds on similarity, aside slack variables, s.t.
402364
``d(a, b) < bounds_[0]`` for all given pairs of similar points ``a``
@@ -406,28 +368,6 @@ def fit(self, X, y, random_state='deprecated', bounds=None):
406368
set to the 5th and 95th percentile of the pairwise distances among all
407369
points in the training data `X`.
408370
"""
409-
# TODO: remove these in v0.6.0
410-
if self.num_labeled != 'deprecated':
411-
warnings.warn('"num_labeled" parameter is not used.'
412-
' It has been deprecated in version 0.5.0 and will be'
413-
' removed in 0.6.0', DeprecationWarning)
414-
if self.bounds != 'deprecated':
415-
warnings.warn('"bounds" parameter from initialization is not used.'
416-
' It has been deprecated in version 0.5.0 and will be'
417-
' removed in 0.6.0. Use the "bounds" parameter of this '
418-
'fit method instead.', DeprecationWarning)
419-
if random_state != 'deprecated':
420-
warnings.warn('"random_state" parameter in the `fit` function is '
421-
'deprecated. Set `random_state` at initialization '
422-
'instead (when instantiating a new `ITML_Supervised` '
423-
'object).', DeprecationWarning)
424-
else:
425-
warnings.warn('As of v0.5.0, `ITML_Supervised` now uses the '
426-
'`random_state` given at initialization to sample '
427-
'constraints, not the default `np.random` from the `fit` '
428-
'method, since this argument is now deprecated. '
429-
'This warning will disappear in v0.6.0.',
430-
ChangedBehaviorWarning)
431371
X, y = self._prepare_inputs(X, y, ensure_min_samples=2)
432372
num_constraints = self.num_constraints
433373
if num_constraints is None:

metric_learn/lfda.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class LFDA(MahalanobisMixin, TransformerMixin):
2727
n_components : int or None, optional (default=None)
2828
Dimensionality of reduced space (if None, defaults to dimension of X).
2929
30-
num_dims : Not used
31-
.. deprecated:: 0.5.0
32-
`num_dims` was deprecated in version 0.5.0 and will
33-
be removed in 0.6.0. Use `n_components` instead.
34-
3530
k : int, optional (default=None)
3631
Number of nearest neighbors used in local scaling method. If None,
3732
defaults to min(7, n_features - 1).
@@ -81,12 +76,11 @@ class LFDA(MahalanobisMixin, TransformerMixin):
8176
-discriminant-analysis-on-beer-style-clustering.html#>`_.
8277
'''
8378

84-
def __init__(self, n_components=None, num_dims='deprecated',
79+
def __init__(self, n_components=None,
8580
k=None, embedding_type='weighted', preprocessor=None):
8681
if embedding_type not in ('weighted', 'orthonormalized', 'plain'):
8782
raise ValueError('Invalid embedding_type: %r' % embedding_type)
8883
self.n_components = n_components
89-
self.num_dims = num_dims
9084
self.embedding_type = embedding_type
9185
self.k = k
9286
super(LFDA, self).__init__(preprocessor)
@@ -102,11 +96,6 @@ def fit(self, X, y):
10296
y : (n,) array-like
10397
Class labels, one per point of data.
10498
'''
105-
if self.num_dims != 'deprecated':
106-
warnings.warn('"num_dims" parameter is not used.'
107-
' It has been deprecated in version 0.5.0 and will be'
108-
' removed in 0.6.0. Use "n_components" instead',
109-
DeprecationWarning)
11099
X, y = self._prepare_inputs(X, y, ensure_min_samples=2)
111100
unique_classes, y = np.unique(y, return_inverse=True)
112101
n, d = X.shape

metric_learn/lmnn.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
Large Margin Nearest Neighbor Metric learning (LMNN)
33
"""
44
import numpy as np
5-
import warnings
65
from collections import Counter
7-
from sklearn.exceptions import ChangedBehaviorWarning
86
from sklearn.metrics import euclidean_distances
97
from sklearn.base import TransformerMixin
108

@@ -25,12 +23,10 @@ class LMNN(MahalanobisMixin, TransformerMixin):
2523
2624
Parameters
2725
----------
28-
init : None, string or numpy array, optional (default=None)
26+
init : string or numpy array, optional (default='auto')
2927
Initialization of the linear transformation. Possible options are
3028
'auto', 'pca', 'identity', 'random', and a numpy array of shape
31-
(n_features_a, n_features_b). If None, will be set automatically to
32-
'auto' (this option is to raise a warning if 'init' is not set, and
33-
stays to its default value None, in v0.5.0).
29+
(n_features_a, n_features_b).
3430
3531
'auto'
3632
Depending on ``n_components``, the most reasonable initialization
@@ -83,11 +79,6 @@ class LMNN(MahalanobisMixin, TransformerMixin):
8379
Tolerance of the optimization procedure. If the objective value varies
8480
less than `tol`, we consider the algorithm has converged and stop it.
8581
86-
use_pca : Not used
87-
.. deprecated:: 0.5.0
88-
`use_pca` was deprecated in version 0.5.0 and will
89-
be removed in 0.6.0.
90-
9182
verbose : bool, optional (default=False)
9283
Whether to print the progress of the optimization procedure.
9384
@@ -102,11 +93,6 @@ class LMNN(MahalanobisMixin, TransformerMixin):
10293
n_components : int or None, optional (default=None)
10394
Dimensionality of reduced space (if None, defaults to dimension of X).
10495
105-
num_dims : Not used
106-
.. deprecated:: 0.5.0
107-
`num_dims` was deprecated in version 0.5.0 and will
108-
be removed in 0.6.0. Use `n_components` instead.
109-
11096
random_state : int or numpy.RandomState or None, optional (default=None)
11197
A pseudo random number generator object or a seed for it if int. If
11298
``init='random'``, ``random_state`` is used to initialize the random
@@ -142,35 +128,23 @@ class LMNN(MahalanobisMixin, TransformerMixin):
142128
2005.
143129
"""
144130

145-
def __init__(self, init=None, k=3, min_iter=50, max_iter=1000,
131+
def __init__(self, init='auto', k=3, min_iter=50, max_iter=1000,
146132
learn_rate=1e-7, regularization=0.5, convergence_tol=0.001,
147-
use_pca='deprecated', verbose=False, preprocessor=None,
148-
n_components=None, num_dims='deprecated', random_state=None):
133+
verbose=False, preprocessor=None,
134+
n_components=None, random_state=None):
149135
self.init = init
150136
self.k = k
151137
self.min_iter = min_iter
152138
self.max_iter = max_iter
153139
self.learn_rate = learn_rate
154140
self.regularization = regularization
155141
self.convergence_tol = convergence_tol
156-
self.use_pca = use_pca
157142
self.verbose = verbose
158143
self.n_components = n_components
159-
self.num_dims = num_dims
160144
self.random_state = random_state
161145
super(LMNN, self).__init__(preprocessor)
162146

163147
def fit(self, X, y):
164-
if self.num_dims != 'deprecated':
165-
warnings.warn('"num_dims" parameter is not used.'
166-
' It has been deprecated in version 0.5.0 and will be'
167-
' removed in 0.6.0. Use "n_components" instead',
168-
DeprecationWarning)
169-
if self.use_pca != 'deprecated':
170-
warnings.warn('"use_pca" parameter is not used.'
171-
' It has been deprecated in version 0.5.0 and will be'
172-
' removed in 0.6.0.',
173-
DeprecationWarning)
174148
k = self.k
175149
reg = self.regularization
176150
learn_rate = self.learn_rate
@@ -184,20 +158,7 @@ def fit(self, X, y):
184158
raise ValueError('Must have one label per point.')
185159
self.labels_ = np.arange(len(unique_labels))
186160

187-
# if the init is the default (None), we raise a warning
188-
if self.init is None:
189-
# TODO: replace init=None by init='auto' in v0.6.0 and remove the warning
190-
msg = ("Warning, no init was set (`init=None`). As of version 0.5.0, "
191-
"the default init will now be set to 'auto', instead of the "
192-
"previous identity matrix. If you still want to use the identity "
193-
"matrix as before, set init='identity'. This warning "
194-
"will disappear in v0.6.0, and `init` parameter's default value "
195-
"will be set to 'auto'.")
196-
warnings.warn(msg, ChangedBehaviorWarning)
197-
init = 'auto'
198-
else:
199-
init = self.init
200-
self.components_ = _initialize_components(output_dim, X, y, init,
161+
self.components_ = _initialize_components(output_dim, X, y, self.init,
201162
self.verbose,
202163
random_state=self.random_state)
203164
required_k = np.bincount(label_inds).min()

0 commit comments

Comments
 (0)