特征的可视化-T-SNE

紧接上一个博客中将文件信息转化为.csv文件并用于观察特征的可视化,这里列举一个代码用于将特征进行可视化。这里是一个T-SNE方法,具体原理代码最后会给链接,自行学习。

mport matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.manifold import TSNE
import seaborn as sns

""" feature
"""
encoding_array = np.load("ext-CUB.npy", allow_pickle=True)
# print(encoding_array)
array = np.load("ext-CUB-proto.npy", allow_pickle=True)
# print(array)
array = np.concatenate((encoding_array, array), axis=0)
# print(array)

""" prediction
"""
df = pd.read_csv("CUB.csv")
marker_list = ["1", "o", "2", "s", "3", "p", "4", "*", "+", "X", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
class_list = np.unique(df["picture_names"])
n_class = len(class_list)
print(class_list)
# print(n_class)


trans = TSNE(n_components=2, n_iter=2000, random_state=3000)
X_trans_2d = trans.fit_transform(array)
print(X_trans_2d.shape)

show_feature = "picture_names"
plt.figure(figsize=(14, 14))
for idx, fruit in enumerate(class_list):

    marker = marker_list[idx % len(marker_list)]

    indices = np.where(df["picture_names"] == fruit)
    if idx % 2 == 0:
        s = 150
    else:
        s = 700
    if idx == 0:
        color = "red"
    if idx == 1:
        color = "red"
    if idx == 2:
        color = "blue"
    if idx == 3:
        color = "blue"
    if idx == 4:
        color = "y"
    if idx == 5:
        color = "y"
    if idx == 6:
        color = "m"
    if idx == 7:
        color = "m"
    if idx == 8:
        color = "c"
    if idx == 9:
        color = "c"
    plt.scatter(X_trans_2d[indices, 0], X_trans_2d[indices, 1], color=color, marker=marker, label=fruit, s=s)
plt.legend(fontsize=16, markerscale=1, bbox_to_anchor=(1, 1))
plt.xticks([])
plt.yticks([])
plt.savefig("ext-CUB.pdf", dpi=300)
# plt.show()
print("it is over !")

T-SNE算法解释.
不同点颜色的表示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值