0

I have tried code from this link plot a document tfidf 2D graph

from sklearn.feature_extraction.text import CountVectorizer, 
TfidfTransformer
from sklearn.decomposition import PCA
from sklearn.pipeline import Pipeline
import matplotlib.pyplot as plt

pipeline = Pipeline([
('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
])        
X = pipeline.fit_transform(x_test).todense()

pca = PCA(n_components=2).fit(X)
data2D = pca.transform(X)
plt.scatter(data2D[:,0], data2D[:,1],c=x_test)
plt.show() 

That's code is worked if I delete c=x_test in the last line, but the color is same just one color, if I add c=x_test its say error ValueError: c of shape (444L,) not acceptable as a color sequence for x with size 444, y with size 444

How to fix the code so that the color should be 6 classes or categories?

sophros
  • 14,672
  • 11
  • 46
  • 75
yyywd
  • 21
  • 5

0 Answers0