Skip to content

Revert changes in #270 due to revert decision in sklearn #273

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

Merged
merged 1 commit into from
Jan 13, 2020
Merged
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
37 changes: 6 additions & 31 deletions metric_learn/base_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import six
from ._util import ArrayIndexer, check_input, validate_vector
import warnings
import sys


class BaseMetricLearner(six.with_metaclass(ABCMeta, BaseEstimator)):
Expand Down Expand Up @@ -241,22 +240,14 @@ def transform(self, X):
X_embedded : `numpy.ndarray`, shape=(n_samples, n_components)
The embedded data points.
"""
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, ['preprocessor_', 'components_'])
else:
check_is_fitted(self)
check_is_fitted(self, ['preprocessor_', 'components_'])
X_checked = check_input(X, type_of_inputs='classic', estimator=self,
preprocessor=self.preprocessor_,
accept_sparse=True)
return X_checked.dot(self.components_.T)

def get_metric(self):
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, 'components_')
else:
check_is_fitted(self)
check_is_fitted(self, 'components_')
components_T = self.components_.T.copy()

def metric_fun(u, v, squared=False):
Expand Down Expand Up @@ -309,11 +300,7 @@ def get_mahalanobis_matrix(self):
M : `numpy.ndarray`, shape=(n_features, n_features)
The copy of the learned Mahalanobis matrix.
"""
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, 'components_')
else:
check_is_fitted(self)
check_is_fitted(self, 'components_')
return self.components_.T.dot(self.components_)


Expand Down Expand Up @@ -376,11 +363,7 @@ def decision_function(self, pairs):
y_predicted : `numpy.ndarray` of floats, shape=(n_constraints,)
The predicted decision function value for each pair.
"""
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, 'preprocessor_')
else:
check_is_fitted(self)
check_is_fitted(self, 'preprocessor_')
pairs = check_input(pairs, type_of_inputs='tuples',
preprocessor=self.preprocessor_,
estimator=self, tuple_size=self._tuple_size)
Expand Down Expand Up @@ -623,11 +606,7 @@ def predict(self, quadruplets):
prediction : `numpy.ndarray` of floats, shape=(n_constraints,)
Predictions of the ordering of pairs, for each quadruplet.
"""
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, 'preprocessor_')
else:
check_is_fitted(self)
check_is_fitted(self, 'preprocessor_')
quadruplets = check_input(quadruplets, type_of_inputs='tuples',
preprocessor=self.preprocessor_,
estimator=self, tuple_size=self._tuple_size)
Expand Down Expand Up @@ -656,11 +635,7 @@ def decision_function(self, quadruplets):
decision_function : `numpy.ndarray` of floats, shape=(n_constraints,)
Metric differences.
"""
# TODO: remove when we stop supporting Python < 3.5
if sys.version_info.major < 3 or sys.version_info.minor < 5:
check_is_fitted(self, 'preprocessor_')
else:
check_is_fitted(self)
check_is_fitted(self, 'preprocessor_')
quadruplets = check_input(quadruplets, type_of_inputs='tuples',
preprocessor=self.preprocessor_,
estimator=self, tuple_size=self._tuple_size)
Expand Down