2017-04-26 58 views
0

如果我想將序列(特徵)A,B和C投影到帶有張量LSTM的目標序列,我怎麼能知道每個特徵對目標影響的重要性?主成分分析有幫助嗎?如果pca可以幫助,該怎麼辦?數據的RNN中的主成分分析

的結構(列)設定如下面:

A sequence 
    B sequence 
    C sequence 
    Target sequence 

回答

0

什麼將這個序列的主成分是?你可以做的是採取的序列,B序列和C序列的PCA和可視化... 這裏是與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 !

+0

非常感謝。這項工作的主要目的是使用A,B和C預測RNN的目標序列,並定量分析(PCA)A,B,C變量對目標序列的影響。 –