Skip to content
Open
Changes from 3 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
14 changes: 7 additions & 7 deletions sklearn/neighbors/nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NeighborhoodComponentAnalysis(BaseEstimator, TransformerMixin):

Parameters
----------
n_features_out: int, optional (default=None)
n_features_out : int, optional (default=None)
Preferred dimensionality of the embedding.

init : string or numpy array, optional (default='pca')
Expand Down Expand Up @@ -87,10 +87,10 @@ class NeighborhoodComponentAnalysis(BaseEstimator, TransformerMixin):
Attributes
----------
transformation_ : array, shape (n_features_out, n_features)
The linear transformation learned during fitting.
The linear transformation learned during fitting.

n_iter_ : int
Counts the number of iterations performed by the optimizer.
Counts the number of iterations performed by the optimizer.

opt_result_ : scipy.optimize.OptimizeResult (optional)
A dictionary of information representing the optimization result.
Expand Down Expand Up @@ -121,9 +121,9 @@ class NeighborhoodComponentAnalysis(BaseEstimator, TransformerMixin):
Notes
-----
Neighborhood Component Analysis (NCA) is a machine learning algorithm for
metric learning. It learns a linear transformation of the space in a
supervised fashion to improve the classification accuracy of a
stochastic nearest neighbors rule in this new space.
metric learning. It learns a linear transformation in a supervised fashion
to improve the classification accuracy of a stochastic nearest neighbors
rule in the new space.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transformed space

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


.. warning::

Expand Down Expand Up @@ -445,7 +445,7 @@ def _loss_grad_lbfgs(self, transformation, X, y, diffs,
ci = masks[:, y[i]]
p_i_j = soft[ci]
not_ci = np.logical_not(ci)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just use ~ci and avoid defining this variable?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right, I changed it

diff_ci = diffs[i, ci, :] # n_samples * n_features
diff_ci = diffs[i, ci, :]
diff_not_ci = diffs[i, not_ci, :]
sum_ci = diff_ci.T.dot(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, sum_ci and sum_not_ci are distances

(p_i_j[:, np.newaxis] * diff_embedded[ci, :]))
Expand Down