TSNE画图
2D图
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import numpy as np# 10条数据,每条数据6维
h = np.random.randn(10, 6) # 使用PCA降维到2维
tsne = TSNE(n_components=2, init='pca', random_state=0)
result_2D = tsne.fit_transform(h)
# 10条数据中前5条为一类,后五条为一类
s1, s2 = result_2D[:5, :], result_2D[5:, :]
fig = plt.figure()
t1 = plt.scatter(s1[:, 0], s1[:, 1], marker='x', c='r', s=20) # marker:点符号 c:点颜色 s:点大小
t2 = plt.scatter(s2[:, 0], s2[:, 1], marker='o', c='b', s=20)
plt.xlabel('X')
plt.ylabel('Y')
plt.legend((t1, t2), ('pos', 'neg'))
plt.show()