def view_dataset(X, color='blue', title=None, save=None):
n_components = 2
pca = PCA(n_components)
pca.fit(X)
x = pca.transform(X)
fig = pylab.figure()
ax = fig.add_subplot(1, 1, 1)
ax.scatter(x[:, 0], x[:, 1], c=color, s=5, lw=0.1)
ax.grid(True)
if title is None:
ax.set_title("Dataset ({} samples)".format(X.shape[0]))
else:
ax.set_title(title + " ({} samples)".format(X.shape[0]))
ax.set_xlabel("1st component")
ax.set_ylabel("2nd component")
if save is None:
pylab.show()
else:
pylab.savefig(save)
pylab.close(fig)
return
评论列表
文章目录