lda

from sklearn import decomposition
from sklearn.preprocessing import StandardScaler
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis 
from sklearn.manifold import LocallyLinearEmbedding
import matplotlib.pyplot as plt
import numpy as np
# import seaborn  #可视化
from mpl_toolkits.mplot3d import Axes3D
# %matplotlib notebook

data = np.loadtxt('feature_result.txt')
data_x = data[:,0:15]
data_y = data[:,15]
# data_y = [np.argmax(one_hot) for one_hot in data_y] #转成一类
std = StandardScaler()
data_x_std = std.fit_transform(data_x)  #均值化
# lda = LinearDiscriminantAnalysis(n_components=3)
lle = LocallyLinearEmbedding(n_neighbors = 10, n_components = 3)
# pca = decomposition.PCA(n_components=3)
PCA_X = lle.fit_transform(data_x, data_y)
# np.savetxt('pca_x.txt', PCA_X)
# print(PCA_X)

x_1, y_1, z_1 = [],[],[]
x_2, y_2, z_2 = [],[],[]
x_3, y_3, z_3 = [],[],[]
x_4, y_4, z_4 = [],[],[]
# x_5, y_5, z_5 = [],[],[]
# x_6, y_6, z_6 = [],[],[]
for i in range(len(PCA_X)):
	if data_y[i] == 0:
		x_1.append(PCA_X[i][0])
		y_1.append(PCA_X[i][1])
		z_1.append(PCA_X[i][2])
	elif data_y[i] ==1:
		x_2.append(PCA_X[i][0])
		y_2.append(PCA_X[i][1])
		z_2.append(PCA_X[i][2])
	elif data_y[i] ==2:
		x_3.append(PCA_X[i][0])
		y_3.append(PCA_X[i][1])
		z_3.append(PCA_X[i][2])
	elif data_y[i] ==3:
		x_4.append(PCA_X[i][0])
		y_4.append(PCA_X[i][1])
		z_4.append(PCA_X[i][2])
	# elif data_y[i] ==5:
	# 	x_5.append(PCA_X[i][0])
	# 	y_5.append(PCA_X[i][1])
	# 	z_5.append(PCA_X[i][2])
	# else:
	# 	x_6.append(PCA_X[i][0])
	# 	y_6.append(PCA_X[i][1])
	# 	z_6.append(PCA_X[i][2])

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(x_1, y_1, z_1, c='orange', label = '0', marker = '*')
ax.scatter(x_2, y_2, z_2, c='firebrick', label = '1', marker = 'p')
ax.scatter(x_3, y_3, z_3, c='slateblue', label = '2', marker = 's')
ax.scatter(x_4, y_4, z_4, c='lightseagreen', label = '3', marker = 'o')
# ax.scatter(x_5, y_5, z_5, c='slateblue', label = '$C_3H_6O$', marker = '^')
# ax.scatter(x_6, y_6, z_6, c='firebrick', label = '$NH_3b$', marker = 'd')
# #alt+f3全选所有变量
ax.set_xlabel('pc1', fontsize = 10)
ax.set_ylabel('pc2', fontsize = 10)
ax.set_zlabel('pc3', fontsize = 10)
plt.savefig('lda.jpg')
ax.legend(loc='upper left')
plt.show()
# print(lle.explained_variance_ratio_)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值