8000 Nca temp by wdevazelhes · Pull Request #1 · wdevazelhes/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Nca temp #1

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

Open
wants to merge 10 commits into
base: nca
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove _make_masks and use OneHotEncoder instead
  • Loading branch information
William de Vazelhes committed Oct 31, 2017
commit 0cee29d78fecc0bf29b60f1008017f75c399a9d5
21 changes: 0 additions & 21 deletions sklearn/neighbors/nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,24 +529,3 @@ def _check_scalar(x, name, target_type, min_val=None, max_val=None):

if max_val is not None and x > max_val:
raise ValueError('`{}`= {}, must be <= {}.'.format(name, x, max_val))


def _make_masks(y):
"""Create one-hot encoding of vector ``y``.

Parameters
----------
y : array, shape (n_samples,)
Data samples labels.

Returns
-------
masks: array, shape (n_samples, n_classes)
One-hot encoding of ``y``.
"""
masks = OneHotEncoder(sparse=False, dtype=bool).fit_transform(y[:,
np.newaxis])
# n = y.shape[0]
# masks = np.zeros((n, y.max() + 1), dtype=bool)
# masks[np.arange(n), y] = [True]
return masks
6 changes: 4 additions & 2 deletions sklearn/neighbors/tests/test_nca.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import numpy as np
from numpy.testing import assert_array_equal
from sklearn.preprocessing import OneHotEncoder
from sklearn.utils import check_random_state
from sklearn.utils.testing import assert_raises, assert_equal
from sklearn.datasets import load_iris, make_classification
from sklearn.model_selection import train_test_split
from sklearn.neighbors.nca import NeighborhoodComponentsAnalysis, _make_masks
from sklearn.neighbors.nca import NeighborhoodComponentsAnalysis
from sklearn.metrics import pairwise_distances


Expand Down Expand Up @@ -59,7 +60,8 @@ def test_finite_differences():
nca = NeighborhoodComponentsAnalysis(None, init=point)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A quoi sert ce premier paramètre None ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah oui effectivement il ne devrait pas être là... Je crois qu'il est apparu en refactorant


X, y, init = nca._validate_params(X, y)
masks = _make_masks(y)
masks = OneHotEncoder(sparse=False,
dtype=bool).fit_transform(y[:, np.newaxis])
diffs = X[:, np.newaxis] - X[np.newaxis]
nca.n_iter_ = 0

Expand Down
0