Skip to content
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

[WIP] Explained Variance #1037

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
54 changes: 54 additions & 0 deletions docs/api/features/explained_variance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.. -*- mode: rst -*-

Explained Variance
==================

================= =================
Visualizer :class:`~yellowbrick.features.explained_variance.ExplainedVariance`
Quick Method :func:`~yellowbrick.features.explained_variance.explained_variance`
Models Decomposition
Workflow Feature Engineering
================= =================

.. plot::
:context: close-figs
:alt: Explained variance quick method on the credit dataset

from yellowbrick.datasets import load_credit
from yellowbrick.features import ExplainedVariance

# Specify the features of interest and the target
X, _ = load_credit()

# Instantiate the visualizer, fit and transform the data
oz = ExplainedVariance()
oz.fit_transform(X)
oz.show()


Quick Method
------------

The same functionality above can be achieved with the associated quick method ``explained_variance``. This method will build the ``ExplainedVariance`` visualizer with the associated arguments, fit it, then (optionally) immediately show it.

.. plot::
:context: close-figs
:alt: Explained variance quick method on the concrete dataset

from yellowbrick.datasets import load_concrete
from yellowbrick.features import explained_variance

# Specify the features of interest and the target
X, _ = load_concrete()

# Determine the optimal number of components
oz = explained_variance(X)


API Reference
-------------

.. automodule:: yellowbrick.features.explained_variance
:members: ExplainedVariance, explained_variance
:undoc-members:
:show-inheritance:
3 changes: 2 additions & 1 deletion docs/api/features/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ finalizes and displays the image.
radviz
rankd
pcoords
pca
manifold
pca
explained_variance
jointplot
13 changes: 12 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
Changelog
=========

Under Development
-----------------

Major Changes:
- New ``ExplainedVariance`` visualizer that assists in the selection of the number of
components for principal component analysis. The visualizer plots both cumulative
and discrete explained variance against the number of components and shades in
percentiles of total explained variance for visual selection of the best fit.



Version 1.1
-----------

* Tag: v1.1_
* Deployed Wednesday, February 12, 2020
* Contributors: Benjamin Bengfort, Rebecca Bilbro, Kristen McIntyre, Larry Gray, Prema Roman, Adam Morris, Shivendra Sharma, Michael Chestnut, Michael Garod, Naresh Bachwani, Piyush Gautam, Daniel Navarrete, Molly Morrison, Emma Kwiecinska, Sarthak Jain, Tony Ojeda, Edwin Schmier, Nathan Danielsen
* Contributors: Benjamin Bengfort, Rebecca Bilbro, Kristen McIntyre, Larry Gray, Prema Roman, Adam Morris, Shivendra Sharma, Michael Chestnut, Michael Garod, Naresh Bachwani, Piyush Gautam, Daniel Navarrete, Molly Morrison, Emma Kwiecinska, Sarthak Jain, Tony Ojeda, Edwin Schmierer, Nathan Danielsen

Major Changes:
- Quick methods (aka Oneliners), which return a fully fitted finalized visualizer object in only a single line, are now implemented for all Yellowbrick Visualizers. Test coverage has been added for all quick methods. The documentation has been updated to document and demonstrate the usage of the quick methods.
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ Feature Visualization
- :doc:`api/features/rankd`: pairwise ranking of features to detect relationships
- :doc:`api/features/pcoords`: horizontal visualization of instances
- :doc:`Radial Visualization <api/features/radviz>`: separation of instances around a circular plot
- :doc:`api/features/pca`: projection of instances based on principal components
- :doc:`api/features/manifold`: high dimensional visualization with manifold learning
- :doc:`api/features/pca`: projection of instances based on principal components
- :doc:`api/features/explained_variance`: select number of components for PCA
- :doc:`Joint Plots <api/features/jointplot>`: direct data visualization with feature selection

Classification Visualization
Expand Down
43 changes: 43 additions & 0 deletions tests/test_features/test_explained_variance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# tests.test_features.test_explained_variance
# Tests for the PCA explained variance visualizer
#
# Author: Benjamin Bengfort
# Created: Mon Feb 10 19:11:46 2020 -0500
#
# Copyright (C) 2019 The scikit-yb developers
# For license information, see LICENSE.txt
#
# ID: test_explained_variance.py [] [email protected] $

"""
Tests for the PCA explained variance visualizer
"""

##########################################################################
## Imports
##########################################################################

from tests.base import VisualTestCase

from yellowbrick.datasets import load_credit
from yellowbrick.features.explained_variance import *


##########################################################################
## ExplainedVariance Tests
##########################################################################

class TextExplainedVariance(VisualTestCase):
"""
Test the explained variance visualizer
"""

def test_quick_method(self):
"""
Test the explained variance quick method
"""
X, _ = load_credit()
oz = explained_variance(X)

assert isinstance(oz, ExplainedVariance)
self.assert_images_similar(oz)
1 change: 1 addition & 0 deletions yellowbrick/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .jointplot import JointPlot, JointPlotVisualizer, joint_plot
from .pca import PCA, PCADecomposition, pca_decomposition
from .manifold import Manifold, manifold_embedding
from .explained_variance import ExplainedVariance, explained_variance

# Alias the TargetType defined in yellowbrick.utils.target
from yellowbrick.utils.target import TargetType
Expand Down
174 changes: 0 additions & 174 deletions yellowbrick/features/decomposition.py

This file was deleted.

Loading