我是python的新手。我在python 3.7中绘制图形有困难。我有30个文本数据集,这些数据集将聚集成3个簇。然后,当我尝试绘制图形“ ValueError:形状(30,)的c不能接受为大小为1的x的颜色序列,大小为1的y的颜色序列”时显示。此代码有什么问题?
我尝试使用T.ravel和T.reshape(30)
with open("sentence.txt", "r") as path:
for line in path:
line = line.strip()
cleaned = clean(line)
cleaned = ' '.join(cleaned)
train_clean_sentences.append(cleaned)
vectorizer = TfidfVectorizer(stop_words='english')
X = vectorizer.fit_transform(train_clean_sentences)
# Creating true labels for 30 training sentences
y_train = np.zeros(30)
y_train[10:20] = 1
y_train[20:30] = 2
## Clustering the training 30 sentences with K-means technique
modelkmeans = KMeans(n_clusters=3, init='k-means++', max_iter=200, n_init=100)
modelkmeans.fit(X)
#plt.scatter(X[:, 0], X[:, 1], c=y_train, s=50, cmap='Spectral')
centers = modelkmeans.cluster_centers_
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.5);