赞
踩
- from sklearn.manifold import TSNE
- import matplotlib.pyplot as plt
- import pandas as pd
- import numpy as np
- from sklearn import manifold
- import xlrd
-
- #将csv格式文件的内容转换为矩阵,不保留第一行(标签)
- def load_csv(path):
- data_read = pd.read_csv(path)
- list = data_read.values.tolist()
- data = np.array(list)
- print(data.shape)
- # print(data)
- return data
-
- #载入我的csv格式的数据集
- data = load_csv(r"C:\\Users\\Cai\\Desktop\\test\\hcvdat0.csv")
-
- #提取分组信息(最后一列),并将字符串转为数字
- target = data[:,12]
- target_T = np.array(target)
- target_T = [int(x) for x in target_T]
-
- tsne = TSNE(n_components=2,learning_rate=100).fit_transform(data[:,1:11])
-
- plt.figure(figsize=(12, 6))
- plt.subplot(121)
- plt.scatter(tsne[:, 0], tsne[:, 1], s=10, c= target_T)
- plt.colorbar()
- plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。