|
11 | 11 | import six
|
12 | 12 | from ._util import ArrayIndexer, check_input, validate_vector
|
13 | 13 | import warnings
|
| 14 | +import sys |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class BaseMetricLearner(six.with_metaclass(ABCMeta, BaseEstimator)):
|
@@ -240,14 +241,22 @@ def transform(self, X):
|
240 | 241 | X_embedded : `numpy.ndarray`, shape=(n_samples, n_components)
|
241 | 242 | The embedded data points.
|
242 | 243 | """
|
243 |
| - check_is_fitted(self, ['preprocessor_', 'components_']) |
| 244 | + # TODO: remove when we stop supporting Python < 3.5 |
| 245 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 246 | + check_is_fitted(self, ['preprocessor_', 'components_']) |
| 247 | + else: |
| 248 | + check_is_fitted(self) |
244 | 249 | X_checked = check_input(X, type_of_inputs='classic', estimator=self,
|
245 | 250 | preprocessor=self.preprocessor_,
|
246 | 251 | accept_sparse=True)
|
247 | 252 | return X_checked.dot(self.components_.T)
|
248 | 253 |
|
249 | 254 | def get_metric(self):
|
250 |
| - check_is_fitted(self, 'components_') |
| 255 | + # TODO: remove when we stop supporting Python < 3.5 |
| 256 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 257 | + check_is_fitted(self, 'components_') |
| 258 | + else: |
| 259 | + check_is_fitted(self) |
251 | 260 | components_T = self.components_.T.copy()
|
252 | 261 |
|
253 | 262 | def metric_fun(u, v, squared=False):
|
@@ -300,7 +309,11 @@ def get_mahalanobis_matrix(self):
|
300 | 309 | M : `numpy.ndarray`, shape=(n_features, n_features)
|
301 | 310 | The copy of the learned Mahalanobis matrix.
|
302 | 311 | """
|
303 |
| - check_is_fitted(self, 'components_') |
| 312 | + # TODO: remove when we stop supporting Python < 3.5 |
| 313 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 314 | + check_is_fitted(self, 'components_') |
| 315 | + else: |
| 316 | + check_is_fitted(self) |
304 | 317 | return self.components_.T.dot(self.components_)
|
305 | 318 |
|
306 | 319 |
|
@@ -363,7 +376,11 @@ def decision_function(self, pairs):
|
363 | 376 | y_predicted : `numpy.ndarray` of floats, shape=(n_constraints,)
|
364 | 377 | The predicted decision function value for each pair.
|
365 | 378 | """
|
366 |
| - check_is_fitted(self, 'preprocessor_') |
| 379 | + # TODO: remove when we stop supporting Python < 3.5 |
| 380 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 381 | + check_is_fitted(self, 'preprocessor_') |
| 382 | + else: |
| 383 | + check_is_fitted(self) |
367 | 384 | pairs = check_input(pairs, type_of_inputs='tuples',
|
368 | 385 | preprocessor=self.preprocessor_,
|
369 | 386 | estimator=self, tuple_size=self._tuple_size)
|
@@ -606,7 +623,11 @@ def predict(self, quadruplets):
|
606 | 623 | prediction : `numpy.ndarray` of floats, shape=(n_constraints,)
|
607 | 624 | Predictions of the ordering of pairs, for each quadruplet.
|
608 | 625 | """
|
609 |
| - check_is_fitted(self, 'preprocessor_') |
| 626 | + # TODO: remove when we stop supporting Python < 3.5 |
| 627 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 628 | + check_is_fitted(self, 'preprocessor_') |
| 629 | + else: |
| 630 | + check_is_fitted(self) |
610 | 631 | quadruplets = check_input(quadruplets, type_of_inputs='tuples',
|
611 | 632 | preprocessor=self.preprocessor_,
|
612 | 633 | estimator=self, tuple_size=self._tuple_size)
|
@@ -635,7 +656,11 @@ def decision_function(self, quadruplets):
|
635 | 656 | decision_function : `numpy.ndarray` of floats, shape=(n_constraints,)
|
636 | 657 | Metric differences.
|
637 | 658 | """
|
638 |
| - check_is_fitted(self, 'preprocessor_') |
| 659 | + # TODO: remove when we stop supporting Python < 3.5 |
| 660 | + if sys.version_info.major < 3 or sys.version_info.minor < 5: |
| 661 | + check_is_fitted(self, 'preprocessor_') |
| 662 | + else: |
| 663 | + check_is_fitted(self) |
639 | 664 | quadruplets = check_input(quadruplets, type_of_inputs='tuples',
|
640 | 665 | preprocessor=self.preprocessor_,
|
641 | 666 | estimator=self, tuple_size=self._tuple_size)
|
|
0 commit comments