-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Fix TSNE init as NumPy array #7208
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
Changes from all commits
2a8e47c
395f016
403ac53
5cfd485
8adef49
e31b1c3
3761e65
e353e3e
033895d
41b6b8d
a8bbee0
a5d3d7c
a0ebbf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from sklearn.utils.testing import assert_less_equal | ||
from sklearn.utils.testing import assert_equal | ||
from sklearn.utils.testing import assert_almost_equal | ||
from sklearn.utils.testing import assert_array_equal | ||
from sklearn.utils.testing import assert_array_almost_equal | ||
from sklearn.utils.testing import assert_less | ||
from sklearn.utils.testing import assert_raises_regexp | ||
|
@@ -305,11 +306,25 @@ def test_non_square_precomputed_distances(): | |
|
||
|
||
def test_init_not_available(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just edit the comment instead of removing it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
# 'init' must be 'pca' or 'random'. | ||
m = "'init' must be 'pca', 'random' or a NumPy array" | ||
# 'init' must be 'pca', 'random', or numpy array. | ||
m = "'init' must be 'pca', 'random', or a numpy array" | ||
assert_raises_regexp(ValueError, m, TSNE, init="not available") | ||
|
||
|
||
def test_init_ndarray(): | ||
# Initialize TSNE with ndarray and test fit | ||
tsne = TSNE(init=np.zeros((100, 2))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also do a fit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if the test I put in the comment below looks good. If so, I'll push it in so you can merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please just add a tsne.fit here and assess at least the size of the fitted attributes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, do you think it's also worthwhile to check the case of init with ndarray and metric='precomputed'? (one change in this PR involves fixing a FutureWarning in this case) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a test for anything you fix
if you're done tell me I'll merge
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just added another test, should be good now. |
||
X_embedded = tsne.fit_transform(np.ones((100, 5))) | ||
assert_array_equal(np.zeros((100, 2)), X_embedded) | ||
|
||
|
||
def test_init_ndarray_precomputed(): | ||
# Initialize TSNE with ndarray and metric 'precomputed' | ||
# Make sure no FutureWarning is thrown from _fit | ||
tsne = TSNE(init=np.zeros((100, 2)), metric="precomputed") | ||
tsne.fit(np.zeros((100, 100))) | ||
|
||
|
||
def test_distance_not_available(): | ||
# 'metric' must be valid. | ||
tsne = TSNE(metric="not available") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw warnings if
self.init
is a numpy array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this as well. I also wrote a test that generated this warning. Would it make sense to push this test? I'm not sure how to assert that no FutureWarning is generated (I found 'assert_no_warnings' but I see that it's depreciating).
The two lines currently in the test are:
tsne = TSNE(init=np.zeros((2, 2)))
tsne.fit(np.array([[0, 0], [0, 0]]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's one more place that would throw a warning for the same reason in the event that metric='precomputed'. I'll fix this one as well using a type check first. Same question as above in terms of whether it's a good idea to write a test to check that a FutureError isn't thrown?