10000 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 useless None
  • Loading branch information
William de Vazelhes committed Oct 31, 2017
commit 4c0494d3ab8c66a8ea47d89de36a185709a97d2b
2 changes: 1 addition & 1 deletion sklearn/neighbors/nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class NeighborhoodComponentsAnalysis(BaseEstimator, TransformerMixin):
>>> X, y = load_iris(return_X_y=True)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y,
... stratify=y, test_size=0.7, random_state=42)
>>> nca = NeighborhoodComponentsAnalysis(None,random_state=42)
>>> nca = NeighborhoodComponentsAnalysis(random_state=42)
>>> nca.fit(X_train, y_train) # doctest: +ELLIPSIS
NeighborhoodComponentsAnalysis(...)
>>> knn = KNeighborsClassifier(n_neighbors=3)
Expand Down
28 changes: 14 additions & 14 deletions sklearn/neighbors/tests/test_nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_transformation_dimensions():
# Fail if transformation input dimension does not match inputs dimensions
transformation = np.array([[1, 2], [3, 4]])
assert_raises(ValueError,
NeighborhoodComponentsAnalysis(None,
NeighborhoodComponentsAnalysis(
init=transformation).fit,
X, y)

Expand All @@ -144,13 +144,13 @@ def test_transformation_dimensions():
transformation = np.array([[1, 2], [3, 4], [5, 6]])
# len(transformation) > len(transformation[0])
assert_raises(ValueError,
NeighborhoodComponentsAnalysis(None,
NeighborhoodComponentsAnalysis(
init=transformation).fit,
X, y)

# Pass otherwise
transformation = np.arange(9).reshape(3, 3)
NeighborhoodComponentsAnalysis(None, init=transformation).fit(X, y)
NeighborhoodComponentsAnalysis(init=transformation).fit(X, y)


def test_n_features_out():
Expand Down Expand Up @@ -178,29 +178,29 @@ def test_init_transformation():
X_train, X_test, y_train, y_test = train_test_split(X, y)

# Start learning from scratch
nca = NeighborhoodComponentsAnalysis(None, init='identity')
nca = NeighborhoodComponentsAnalysis(init='identity')
nca.fit(X_train, y_train)

# Initialize with random
nca_random = NeighborhoodComponentsAnalysis(None, init='random')
nca_random = NeighborhoodComponentsAnalysis(init='random')
nca_random.fit(X_train, y_train)

# Initialize with PCA
nca_pca = NeighborhoodComponentsAnalysis(None, init='pca')
nca_pca = NeighborhoodComponentsAnalysis(init='pca')
nca_pca.fit(X_train, y_train)

init = np.random.rand(X.shape[1], X.shape[1])
nca = NeighborhoodComponentsAnalysis(None, init=init)
nca = NeighborhoodComponentsAnalysis(init=init)
nca.fit(X_train, y_train)

# init.shape[1] must match X.shape[1]
init = np.random.rand(X.shape[1], X.shape[1] + 1)
nca = NeighborhoodComponentsAnalysis(None, init=init)
nca = NeighborhoodComponentsAnalysis(init=init)
assert_raises(ValueError, nca.fit, X_train, y_train)

# init.shape[0] must be <= init.shape[1]
init = np.random.rand(X.shape[1] + 1, X.shape[1])
nca = NeighborhoodComponentsAnalysis(None, init=init)
nca = NeighborhoodComponentsAnalysis(init=init)
assert_raises(ValueError, nca.fit, X_train, y_train)

# init.shape[0] must match n_features_out
Expand All @@ -211,7 +211,7 @@ def test_init_transformation():


def test_verbose():
nca = NeighborhoodComponentsAnalysis(None, verbose=1)
nca = NeighborhoodComponentsAnalysis(verbose=1)
nca.fit(iris_data, iris_target)


Expand Down Expand Up @@ -271,7 +271,7 @@ def test_callable():
y = iris_target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

nca = NeighborhoodComponentsAnalysis(None, callback='my_cb')
nca = NeighborhoodComponentsAnalysis(callback='my_cb')
assert_raises(ValueError, nca.fit, X_train, y_train)

max_iter = 10
Expand All @@ -280,7 +280,7 @@ def my_cb(transformation, n_iter):
rem_iter = max_iter - n_iter
print('{} iterations remaining...'.format(rem_iter))

nca = NeighborhoodComponentsAnalysis(None, max_iter=max_iter,
nca = NeighborhoodComponentsAnalysis(max_iter=max_iter,
callback=my_cb, verbose=1)
nca.fit(X_train, y_train)

Expand All @@ -290,7 +290,7 @@ def test_terminate_early():
y = iris_target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

nca = NeighborhoodComponentsAnalysis(None, max_iter=5)
nca = NeighborhoodComponentsAnalysis(max_iter=5)
nca.fit(X_train, y_train)


Expand All @@ -299,7 +299,7 @@ def test_store_opt_result():
y = iris_target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

nca = NeighborhoodComponentsAnalysis(None, max_iter=5,
nca = NeighborhoodComponentsAnalysis(max_iter=5,
store_opt_result=True)
nca.fit(X_train, y_train)
transformation = nca.opt_result_.x
Expand Down
0