内联代码片
。
// A code block
import matplotlib.pyplot as plt
from sklearn.mainfold import TSNE
tsne = TSNE(n_components=2)
x = [[1,2,2],[2,2,2],[3,3,3]]
y = [1,0,2]#y是x对应的标签
x_tsne = tsne.fit_transform(x)
plt.scatter(x_tsne[:,0],x_tsne[:,1],c=y)
plt.show()
// An highlighted block
import matplotlib.pyplot as plt
from sklearn.mainfold import TSNE
tsne = TSNE(n_components=2)
x = [[1,2,2],[2,2,2],[3,3,3]]
y = [1,0,2]#y是x对应的标签
x_tsne = tsne.fit_transform(x)
plt.scatter(x_tsne[:,0],x_tsne[:,1],c=y)
plt.show()
下面是用seaborn
下面展示一些 内联代码片
。
// A code block
import matplotlib.pyplot as plt
from sklearn.mainfold import TSNE
import seaborn as sns
tsne = TSNE(n_components=2)
x = [[1,2,2],[2,2,2],[3,3,3]]
y = [1,0,2]#y是x对应的标签
x_tsne = tsne.fit_transform(x)
sns.scatterplot(x=x_tsne[:,0],y=x_tsne[:,1],hue=y)
plt.show()
// An highlighted block
import matplotlib.pyplot as plt
from sklearn.mainfold import TSNE
import seaborn as sns
tsne = TSNE(n_components=2)
x = [[1,2,2],[2,2,2],[3,3,3]]
y = [1,0,2]#y是x对应的标签
x_tsne = tsne.fit_transform(x)
sns.scatterplot(x=x_tsne[:,0],y=x_tsne[:,1],hue=y)
plt.show()
这样完成了t-sne的降维可视化,但是如果想要画的更好看些,可以看下matplotlib和seaborn的详细资料,因为matplotlib和seaborn的资料有些多,而且每个人喜欢的风格不同,这里就不详细叙述matplot和seaborn的资料了。