用python 画出sklearn生成的不同类的数据的二维图像
生成数据
import matplotlib.pyplot as pltimport numpy as np
%matplotlib inline
from sklearn.datasets.samples_generator import make_blobs
center = [[1, 1],[-1, -1],[1, -1]]
cluster_std = 0.3
X, labels = make_blobs(n_samples=100, centers=center, n_features=2, \
cluster_std=cluster_std, random_state=0)
画出数据集
unique_lab = set(labels)colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_lab)))
for k, col in zip(unique_lab, colors):
x_k = X[labels == k]
plt.plot(x_k[:, 0], x_k[:, 1], 'o', markerfacecolor=colors, markeredgecolor='k',\
markersize=14)
plt.title('dataset by make_blob')
plt.show()
报错:
回答:
更换了另一种方法,就好了
plt.scatter(X[:,0],X[:,1],'o',c=lables)
以上是 用python 画出sklearn生成的不同类的数据的二维图像 的全部内容, 来源链接: utcz.com/a/163000.html