Last active
April 21, 2019 16:23
-
-
Save Sangarshanan/d6c28bd799eb15af01f1aa4c537f134a to your computer and use it in GitHub Desktop.
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.text import TSNEVisualizer,UMAPVisualizer | |
from sklearn.feature_extraction.text import TfidfVectorizer,CountVectorizer | |
def visualize(dim_reduction,encoding,corpus_data,corpus_target,labels = True,alpha=0.7,metric=None): | |
if 'tfidf' in encoding.lower(): | |
encode = TfidfVectorizer() | |
if 'count' in encoding.lower(): | |
encode = CountVectorizer() | |
docs = encode.fit_transform(corpus_data) | |
if labels is True: | |
labels = corpus_target | |
else: | |
labels = None | |
if 'umap' in dim_reduction.lower(): | |
if metric is None: | |
viz = UMAPVisualizer() | |
else: | |
viz = UMAPVisualizer(metric=metric) | |
if 't-sne' in dim_reduction.lower(): | |
viz = TSNEVisualizer(alpha = alpha) | |
viz.fit(docs,labels) | |
return viz.poof() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment