22Information Theoretic Metric Learning (ITML)
33"""
44
5- import warnings
65import numpy as np
7- from sklearn .exceptions import ChangedBehaviorWarning
86from sklearn .metrics import pairwise_distances
97from sklearn .utils .validation import check_array
108from 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 :
0 commit comments