-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
Final Tweaks #946
Merged
bbengfort
merged 12 commits into
DistrictDataLabs:develop
from
naresh-bachwani:minor-changes
Aug 15, 2019
Merged
Final Tweaks #946
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8c9f1a8
Final Tweaks
naresh-bachwani 2367368
Baseline changes
naresh-bachwani 29d5ea3
minor changes
naresh-bachwani f38e2dc
Baselinee imahes
naresh-bachwani abf16fb
Changes default colors
naresh-bachwani 54301cf
regenerate baseline images on mac and remove warnings
bbengfort 9771636
removed import
naresh-bachwani e922976
Added conftest
naresh-bachwani 3932498
Merge branch 'develop' into minor-changes
naresh-bachwani 30a4fdb
regenerate images
bbengfort d39f46a
add windows tol, headers, update api reference
bbengfort 8b82917
change xfailif to xfail
bbengfort File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-422 Bytes
(99%)
tests/baseline_images/test_features/test_manifold/test_manifold_classification.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+854 Bytes
(100%)
...baseline_images/test_features/test_manifold/test_manifold_classification_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+133 KB
(340%)
tests/baseline_images/test_features/test_manifold/test_manifold_pandas.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+22.1 KB
(130%)
tests/baseline_images/test_features/test_manifold/test_manifold_regression.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.17 KB
(98%)
tests/baseline_images/test_features/test_manifold/test_manifold_regression_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+673 Bytes
(100%)
tests/baseline_images/test_features/test_pca/test_biplot_2d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.41 KB
(97%)
tests/baseline_images/test_features/test_pca/test_biplot_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.63 KB
(100%)
tests/baseline_images/test_features/test_pca/test_colorbar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+20.4 KB
(140%)
tests/baseline_images/test_features/test_pca/test_colorbar_heatmap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.16 KB
(100%)
tests/baseline_images/test_features/test_pca/test_continuous.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1012 Bytes
(99%)
tests/baseline_images/test_features/test_pca/test_discrete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+18 KB
(130%)
tests/baseline_images/test_features/test_pca/test_heatmap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.81 KB
(98%)
.../baseline_images/test_features/test_pca/test_pca_decomposition_quick_method.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.25 KB
(100%)
tests/baseline_images/test_features/test_pca/test_scale_false_2d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+10.8 KB
(110%)
tests/baseline_images/test_features/test_pca/test_scale_false_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.03 KB
(93%)
tests/baseline_images/test_features/test_pca/test_scale_true_2d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-300 Bytes
(100%)
tests/baseline_images/test_features/test_pca/test_scale_true_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+261 Bytes
(100%)
...e_images/test_features/test_projection/test_continuous_when_target_discrete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.3 KB
(110%)
tests/baseline_images/test_features/test_projection/test_discrete_3d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+405 Bytes
(100%)
tests/baseline_images/test_features/test_projection/test_discrete_plot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.73 KB
(100%)
tests/baseline_images/test_features/test_projection/test_single_plot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Provides fixtures for the feature tests module. | ||
""" | ||
|
||
########################################################################## | ||
## Imports | ||
########################################################################## | ||
import pytest | ||
from sklearn.datasets import make_classification, make_regression, make_s_curve | ||
|
||
from tests.fixtures import Dataset | ||
|
||
########################################################################## | ||
## Fixtures | ||
########################################################################## | ||
|
||
@pytest.fixture(scope="class") | ||
def discrete(request): | ||
""" | ||
Creates a fixture of train and test splits for the sklearn digits dataset | ||
For ease of use returns a Dataset named tuple composed of two Split tuples. | ||
""" | ||
X, y = make_classification( | ||
n_samples=400, | ||
n_features=12, | ||
n_informative=8, | ||
n_redundant=0, | ||
n_classes=5, | ||
n_clusters_per_class=1, | ||
class_sep=1.8, | ||
random_state=854, | ||
scale=[14.2, 2.1, 0.32, 0.001, 32.3, 44.1, 102.3, 2.3, 2.4, 38.2, 0.05, 1.0], | ||
) | ||
|
||
# Set a class attribute for discrete data. | ||
request.cls.discrete = Dataset(X, y) | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def continuous(request): | ||
""" | ||
Creates a random regressor fixture. | ||
""" | ||
X, y = make_regression( | ||
n_samples=500, n_features=22, n_informative=8, random_state=2019 | ||
) | ||
|
||
# Set a class attribute for continuous data | ||
request.cls.continuous = Dataset(X, y) | ||
|
||
@pytest.fixture(scope="class") | ||
def s_curves(request): | ||
""" | ||
Creates a random regressor fixture. | ||
""" | ||
X, y = make_s_curve(1000, random_state=888) | ||
# Set a class attribute for continuous data | ||
request.cls.s_curves = Dataset(X, y) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ | |
from sklearn.pipeline import Pipeline | ||
from sklearn.decomposition import PCA | ||
from sklearn.manifold import LocallyLinearEmbedding | ||
from sklearn.datasets.samples_generator import make_s_curve | ||
from sklearn.datasets import make_classification, make_regression, make_blobs | ||
from sklearn.datasets import make_s_curve | ||
from sklearn.datasets import make_blobs | ||
|
||
from unittest.mock import patch | ||
from tests.base import VisualTestCase | ||
|
@@ -40,7 +40,7 @@ | |
## Manifold Visualizer Tests | ||
########################################################################## | ||
|
||
|
||
@pytest.mark.usefixtures("s_curves", "discrete", "continuous") | ||
class TestManifold(VisualTestCase): | ||
""" | ||
Test Manifold visualizer | ||
|
@@ -112,41 +112,37 @@ def test_manifold_instance_construction(self): | |
|
||
@pytest.mark.filterwarnings("ignore:Conversion of the second argument") | ||
@pytest.mark.parametrize( | ||
"algorithm", | ||
["lle", "ltsa", "hessian", "modified", "isomap"], | ||
"algorithm", ["lle", "ltsa", "hessian", "modified", "isomap"] | ||
) | ||
def test_manifold_algorithm_transform_fit(self, algorithm): | ||
""" | ||
Test manifold fit with algorithms having transform implemented | ||
""" | ||
X, y = make_s_curve(1000, random_state=94) | ||
manifold = Manifold(manifold=algorithm, target="auto") | ||
with pytest.warns(YellowbrickWarning): | ||
manifold = Manifold(manifold=algorithm, target="auto") | ||
|
||
assert manifold.fit(X, y) is manifold, "fit did not return self" | ||
|
||
@pytest.mark.filterwarnings("ignore:Conversion of the second argument") | ||
@pytest.mark.parametrize( | ||
"algorithm", | ||
["mds", "spectral", "tsne"], | ||
) | ||
@pytest.mark.parametrize("algorithm", ["mds", "spectral", "tsne"]) | ||
def test_manifold_algorithm_no_transform_fit(self, algorithm): | ||
""" | ||
Test manifold fit with algorithms not having transform implemented | ||
""" | ||
X, y = make_s_curve(200, random_state=888) | ||
X, y = self.s_curves | ||
msg = "requires data to be simultaneously fit and transformed" | ||
oz = Manifold(manifold=algorithm, n_neighbors=10, random_state=223) | ||
with pytest.raises(ModelError, match=msg): | ||
oz.fit(X) | ||
|
||
|
||
@patch("yellowbrick.features.manifold.Manifold.draw", spec=True) | ||
@pytest.mark.parametrize("projection", [2, 3]) | ||
def test_manifold_fit_transform(self, mock_draw, projection): | ||
""" | ||
Test manifold fit_transform method | ||
""" | ||
X, y = make_s_curve(1000, random_state=888) | ||
X, y = self.s_curves | ||
manifold = Manifold(target="auto", projection=projection) | ||
|
||
assert not hasattr(manifold, "fit_time_") | ||
|
@@ -157,29 +153,31 @@ def test_manifold_fit_transform(self, mock_draw, projection): | |
mock_draw.assert_called_once() | ||
assert hasattr(manifold, "fit_time_") | ||
assert manifold._target_color_type == TargetType.CONTINUOUS | ||
|
||
@patch("yellowbrick.features.manifold.Manifold.fit_transform", spec=True) | ||
@patch("yellowbrick.features.manifold.Manifold.draw", spec=True) | ||
@pytest.mark.parametrize("projection", [2, 3]) | ||
def test_manifold_transform(self, mock_draw, mock_fit_transform, projection): | ||
""" | ||
Test manifold transform method | ||
""" | ||
X, y = make_s_curve(1000, random_state=888) | ||
manifold = Manifold(manifold="lle", target="auto", projection=projection) | ||
X, y = self.s_curves | ||
manifold = Manifold( | ||
manifold="lle", target="auto", n_neighbors=5, projection=projection | ||
) | ||
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. removed n_neighbors warning |
||
|
||
manifold.fit(X, y) | ||
Xp = manifold.transform(X, y) | ||
assert Xp.shape == (X.shape[0], projection) | ||
|
||
mock_draw.assert_called_once() | ||
|
||
def test_manifold_no_transform(self): | ||
""" | ||
Test the exception when manifold doesn't implement transform. | ||
""" | ||
X, _ = make_s_curve(1000, random_state=888) | ||
manifold = Manifold(manifold="lle", target="auto") | ||
X, _ = self.s_curves | ||
manifold = Manifold(manifold="lle", n_neighbors=5, target="auto") | ||
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. removed n_neighbors warning |
||
|
||
msg = "instance is not fitted yet, please call fit" | ||
with pytest.raises(NotFitted, match=msg): | ||
|
@@ -191,27 +189,19 @@ def test_manifold_assert_no_transform(self, mock_fit, manifolds): | |
""" | ||
Assert that transform raises error when MDS, TSNE or Spectral Embedding algorithms are used. | ||
""" | ||
X, _ = make_s_curve(1000, random_state=888) | ||
X, _ = self.s_curves | ||
manifold = Manifold(manifold=manifolds, target="auto", n_neighbors=10) | ||
mock_fit(X) | ||
msg = "requires data to be simultaneously fit and transformed" | ||
with pytest.raises(ModelError, match=msg): | ||
manifold.transform(X) | ||
manifold.transform(X) | ||
|
||
@pytest.mark.filterwarnings("ignore:Conversion of the second argument") | ||
def test_manifold_classification(self): | ||
""" | ||
Image similarity test for classification dataset (discrete y) | ||
""" | ||
X, y = make_classification( | ||
n_samples=300, | ||
n_features=7, | ||
n_informative=4, | ||
n_redundant=2, | ||
n_classes=4, | ||
n_clusters_per_class=2, | ||
random_state=78, | ||
) | ||
X, y = self.discrete | ||
|
||
oz = Manifold( | ||
manifold="spectral", target="discrete", n_neighbors=5, random_state=108 | ||
|
@@ -228,15 +218,7 @@ def test_manifold_classification_3d(self): | |
""" | ||
Image similarity test for classification dataset (discrete y) | ||
""" | ||
X, y = make_classification( | ||
n_samples=300, | ||
n_features=7, | ||
n_informative=4, | ||
n_redundant=2, | ||
n_classes=4, | ||
n_clusters_per_class=2, | ||
random_state=78, | ||
) | ||
X, y = self.discrete | ||
|
||
oz = Manifold( | ||
manifold="spectral", | ||
|
@@ -258,9 +240,7 @@ def test_manifold_regression(self): | |
""" | ||
Image similarity test for regression dataset (continuous y) | ||
""" | ||
X, y = make_regression( | ||
n_samples=300, n_features=7, n_informative=4, random_state=87 | ||
) | ||
X, y = self.continuous | ||
|
||
oz = Manifold(manifold="tsne", target="continuous", random_state=1) | ||
assert not hasattr(oz, "range_") | ||
|
@@ -275,9 +255,7 @@ def test_manifold_regression_3d(self): | |
""" | ||
Image similarity test for regression dataset (continuous y) | ||
""" | ||
X, y = make_regression( | ||
n_samples=300, n_features=7, n_informative=4, random_state=87 | ||
) | ||
X, y = self.continuous | ||
|
||
oz = Manifold( | ||
manifold="tsne", target="continuous", random_state=1, projection=3 | ||
|
@@ -318,18 +296,17 @@ def test_manifold_pandas(self): | |
""" | ||
Test manifold on a dataset made up of a pandas DataFrame and Series | ||
""" | ||
X, y = make_s_curve(200, random_state=888) | ||
X, y = self.s_curves | ||
|
||
oz = Manifold( | ||
manifold="ltsa", | ||
colormap="nipy_spectral", | ||
n_neighbors=10, | ||
target="continuous", | ||
random_state=223, | ||
) | ||
oz.fit_transform(X, y) | ||
oz.fit_transform(X, y) | ||
oz.finalize() | ||
oz.cbar.set_ticks([]) | ||
# TODO: find a way to decrease this tolerance | ||
self.assert_images_similar(oz, tol=40) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
removed n_neighbors warning