Created
July 17, 2019 13:07
-
-
Save bbengfort/c850d4627bb09b16ec8a18a0a61e2b82 to your computer and use it in GitHub Desktop.
Example projection visualizer with Yellowbrick
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
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