Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created July 17, 2019 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/c850d4627bb09b16ec8a18a0a61e2b82 to your computer and use it in GitHub Desktop.
Save bbengfort/c850d4627bb09b16ec8a18a0a61e2b82 to your computer and use it in GitHub Desktop.
Example projection visualizer with Yellowbrick
from yellowbrick.features.projection import ProjectionVisualizer
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_regression
class Visualizer(ProjectionVisualizer):
def __init__(self, **kwargs):
super(Visualizer, self).__init__(**kwargs)
self.transformer = Pipeline([
('scale', StandardScaler()),
('pca', PCA(self.projection))
])
def fit(self, X, y=None):
super(ProjectionVisualizer, self).fit(X, y)
self.transformer.fit(X)
return self
def transform(self, X, y=None):
Xp = self.transformer.transform(X)
self.draw(Xp, y)
return Xp
if __name__ == "__main__":
X, y = make_regression(n_samples=500, n_features=22, n_informative=8)
oz = Visualizer()
oz.fit_transform(X, y)
oz.poof()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment