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
Addressing issue #589: Adding alpha params to PCA #811
Addressing issue #589: Adding alpha params to PCA #811
Conversation
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.
Great job on adding alpha. All my changes are very minor. I am unsure about the test you built and I will wait for a comment from @rebeccabilbro
yellowbrick/features/pca.py
Outdated
@@ -69,6 +69,10 @@ class PCADecomposition(MultiFeatureVisualizer): | |||
Optional string or matplotlib cmap to colorize lines. | |||
Use either color to colorize the lines on a per class basis or | |||
colormap to color them on a continuous scale. | |||
|
|||
alpha : float, default: 1 |
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.
alpha should be set to 0.75
yellowbrick/features/pca.py
Outdated
@@ -99,6 +103,7 @@ def __init__(self, | |||
proj_features=False, | |||
color=None, | |||
colormap=palettes.DEFAULT_SEQUENCE, | |||
alpha = 1, |
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.
set alpha to 0.75
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.
Tiny thing, but the spacing is off here. We shouldn't have spaces before and after the equals sign for keyword arguments.
yellowbrick/features/pca.py
Outdated
@@ -215,7 +221,7 @@ def finalize(self, **kwargs): | |||
|
|||
def pca_decomposition(X, y=None, ax=None, features=None, scale=True, | |||
proj_dim=2, proj_features=False, color=None, | |||
colormap=palettes.DEFAULT_SEQUENCE, | |||
colormap=palettes.DEFAULT_SEQUENCE, alpha=1, |
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.
set alpha = 0.75
tests/test_features/test_pca.py
Outdated
visualizer = PCADecomposition(**params).fit(self.dataset.X) | ||
pca_array = visualizer.transform(self.dataset.X) | ||
alpha=0.3 | ||
assert visualizer.alpha == alpha |
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.
0.3 doesn't need to be assigned to alpha. You should test directly assert visualizer.alpha == 0.3
@@ -188,3 +191,26 @@ def test_scale_true_3d_execption(self): | |||
with pytest.raises(ValueError, match=e): | |||
pca = PCADecomposition(**params) | |||
pca.fit(X) | |||
|
|||
@mock.patch('yellowbrick.features.pca.plt.sca', autospec=True) |
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.
I am unsure about this test, I will wait on a review from @rebeccabilbro
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.
Yes, the test looks good! Patching pyplot's set current axes method (sca
) ensures that when we make the mock on line 207 (which is used to called scatter
and retrieve the alpha
), matplotlib doesn't complain about it.
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.
Hey there @naresh-bachwani, good progress on this!
In addition to the feedback from @lwgray, I'm noticing that a few of the image comparison tests are failing due to your updates to this visualizer. This is fairly common, and the fix isn't too hard — essentially you'll need to (1) run the tests locally on your machine (2) copy the actual images generated by the tests (3) paste them into the baseline images and (4) commit the new baseline images to this same PR branch. You can find the instructions here. Let us know if you have questions!
yellowbrick/features/pca.py
Outdated
@@ -99,6 +103,7 @@ def __init__(self, | |||
proj_features=False, | |||
color=None, | |||
colormap=palettes.DEFAULT_SEQUENCE, | |||
alpha = 1, |
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.
Tiny thing, but the spacing is off here. We shouldn't have spaces before and after the equals sign for keyword arguments.
yellowbrick/features/pca.py
Outdated
@@ -118,7 +123,7 @@ def __init__(self, | |||
[('scale', StandardScaler(with_std=self.scale)), | |||
('pca', PCA(self.proj_dim, random_state=random_state))] | |||
) | |||
|
|||
self.alpha=alpha |
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.
Another spacing thing here (should be self.alpha = alpha
)
yellowbrick/features/pca.py
Outdated
@@ -280,7 +290,7 @@ def pca_decomposition(X, y=None, ax=None, features=None, scale=True, | |||
visualizer = PCADecomposition( | |||
ax=ax, features=features, scale=scale, proj_dim=proj_dim, | |||
proj_features=proj_features, color=color, colormap=colormap, | |||
random_state=random_state, **kwargs | |||
alpha=alpha, random_state=random_state,**kwargs |
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.
It looks like the spaces were modified here? We should reinsert the space after the last comma and before **kwargs
@@ -188,3 +191,26 @@ def test_scale_true_3d_execption(self): | |||
with pytest.raises(ValueError, match=e): | |||
pca = PCADecomposition(**params) | |||
pca.fit(X) | |||
|
|||
@mock.patch('yellowbrick.features.pca.plt.sca', autospec=True) |
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.
Yes, the test looks good! Patching pyplot's set current axes method (sca
) ensures that when we make the mock on line 207 (which is used to called scatter
and retrieve the alpha
), matplotlib doesn't complain about it.
I changed the baseline images. The test passes on my local computer but is failing here! |
Ok, thanks @naresh-bachwani — we may just need to tweak the comparison tolerances. We'll have a look this weekend and get back to you! |
Ok! Thanks! |
@naresh-bachwani i advise that you increase the tolerance for the tests that didn’t pass |
what OS are you using locally? |
Windows10 |
@naresh-bachwani That might be the reason for the difference . We have known that the test run differently in Windows than in Linux ( the environment our test run in). There isnt a way to know ahead of time if test will run successfully on Travis. The goal is to make them pass on Travis despite what is happening locally. |
Thanks for the help! |
@naresh-bachwani — yes, this unfortunately is one of the challenges of doing visual comparison tests. Different operating systems have slightly different versions of fonts, colors, etc, which can cause our tests to pass locally (since the images match on our local OSs) but fail mysteriously in the CI. Our CI solution is to use both Travis and AppVeyor, which allows us to see what will happen in both a linux and windows virtual machine. Generally my strategy is to run the tests locally, copy and commit any new baseline images, and then push to the PR branch to trigger the CI builds. If any builds fail, the first thing I check is if there are any If the |
Hello @rebeccabilbro, |
Great question @naresh-bachwani! The |
Ok so 9932 is just an arbitrary number? |
Yep! |
The following changes were made to PCA referenced #589 :
This PR was partially reviewed in #807
pca.py
to specify the opacity.test_pca.py
to add a test for alphaThe result is attached below: