matlab17b的tsne程序,TSNE三维图形

将数据ncoll和wcoll想象为4000位随机数。在

我想通过TSNE运行它们,然后创建一个三维图。在

如果我把它画出来,我最终得到的基本上是一个二维图形,所以有些地方出了问题,但我不完全确定是什么。在

最后,我想在同一个3D图形上绘制前半部分为红色,第二部分为蓝色。在print(__doc__)

from time import time

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from matplotlib.ticker import NullFormatter

from sklearn import manifold

from sklearn.utils import check_random_state

c = 1000

# Open File

ncoll_fn = "C:/Users/xxlassi/Downloads/trajectory_demo/trajectory_270252769939974_run__uid_-1808183947_tag_collision_0.0.txt"

wcoll_fn = "C:/Users/xxlassi/Downloads/trajectory_demo/trajectory_271551342150600_run__uid_-918721219_tag_collision_0.01.txt"

ncoll = []

wcoll = []

with open( ncoll_fn ) as f:

ncoll = [ np.array([ float(el) for el in line.strip().split(',') ]) for line in f.readlines() ]

ncoll = np.array( ncoll )

with open( wcoll_fn ) as f:

wcoll = [ np.array([ float(el) for el in line.strip().split(',') ]) for line in f.readlines() ]

wcoll = np.array( wcoll )

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

arr = np.concatenate((wcoll, ncoll), axis=0)

mid = int(len(arr)/2)

print (mid)

tsne = manifold.TSNE(n_components=3, init='pca',random_state=0, perplexity= 30, n_iter=5000)

trans_data = tsne.fit_transform(arr)

ax.scatter(arr[:,0][0:mid], arr[:,1][0:mid], c= 'r')

ax.scatter(arr[:,0][mid:], arr[:,1][mid:], c= 'b')

ax.set_xlabel('X Label')

ax.set_ylabel('Y Label')

ax.set_zlabel('Z Label')

plt.title("t-SNE")

plt.axis('tight')

plt.show()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值