plot.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def plot_tsne(data, analyse = True, n_components = 2, precomputed = False):
  """Perform t-SNE and plot overview of the results"""
  if precomputed:
    metric = 'precomputed';
  else:
    metric = None;

  if analyse:
    tsne = sl.TSNE(n_components=n_components, init = 'pca', random_state = 0, metric = metric)
    Y = tsne.fit_transform(data)
  else:
    Y = data;

  if n_components == 1:
    plt.plot(Y);
  elif n_components == 2:
    plt.scatter(Y[:,0], Y[:,1], c = range(len(Y[:,0])), cmap = plt.cm.Spectral);
  else:
    ax = plt.gcf().add_subplot(1, 1, 1, projection = '3d');
    ax.scatter(Y[:, 0], Y[:, 1], Y[:,2], c = range(len(Y[:,0])), cmap=plt.cm.Spectral)
  plt.title("t-SNE")
  plt.tight_layout();
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号