主成分分析在循环神经网络中的应用

2024-04-26 05:01:42 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我想用tensorflow LSTM将序列(特征)A、B和C投影到目标序列,如何知道每个特征对目标序列的影响?主成分分析有帮助吗?如果pca能帮上忙,怎么办?在

数据集的结构(列)如下:

   A sequence
   B sequence
   C sequence
   Target sequence

Tags: 数据target目标tensorflow序列特征结构投影
1条回答
网友
1楼 · 发布于 2024-04-26 05:01:42

这个序列的主要成分是什么?你可以做的是对A序列,B序列和C序列进行主成分分析,然后可视化。。。 下面是一个关于用Tensorboard可视化PCA的简单教程:http://www.pinchofintelligence.com/simple-introduction-to-tensorboard-embedding-visualisation/

%matplotlib inline
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import os

from tensorflow.contrib.tensorboard.plugins import projector
from tensorflow.examples.tutorials.mnist import input_data

LOG_DIR = 'minimalsample'
NAME_TO_VISUALISE_VARIABLE = "mnistembedding"
TO_EMBED_COUNT = 500


path_for_mnist_sprites =  os.path.join(LOG_DIR,'mnistdigits.png')
path_for_mnist_metadata =  os.path.join(LOG_DIR,'metadata.tsv')
mnist = input_data.read_data_sets("MNIST_data/", one_hot=False)
batch_xs, batch_ys = mnist.train.next_batch(TO_EMBED_COUNT)
embedding_var = tf.Variable(batch_xs, name=NAME_TO_VISUALISE_VARIABLE)
summary_writer = tf.summary.FileWriter(LOG_DIR)
config = projector.ProjectorConfig()
embedding = config.embeddings.add()
embedding.tensor_name = embedding_var.name

# Specify where you find the metadata
embedding.metadata_path = path_for_mnist_metadata #'metadata.tsv'

# Specify where you find the sprite (we will create this later)
embedding.sprite.image_path = path_for_mnist_sprites #'mnistdigits.png'
embedding.sprite.single_image_dim.extend([28,28])

# Say that you want to visualise the embeddings
projector.visualize_embeddings(summary_writer, config)
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.save(sess, os.path.join(LOG_DIR, "model.ckpt"), 1)
with open(path_for_mnist_metadata,'w') as f:
    f.write("Index\tLabel\n")
    for index,label in enumerate(batch_ys):
        f.write("%d\t%d\n" % (index,label))

希望这能帮助你思考PCA!在

相关问题 更多 >