Created
December 11, 2016 23:12
-
-
Save Baschdl/e965ba3499bb6e905f92befa7f77bbf2 to your computer and use it in GitHub Desktop.
Visualize data with tensorflow (tensorboard) embedding projector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#how-to: https://www.tensorflow.org/versions/r0.12/how_tos/embedding_viz/index.html | |
#run "tensorboard --log-path ../path/to/log" and open in browser | |
import tensorflow as tf | |
import os | |
import numpy as np | |
LOG_DIR='log' | |
def visualize_data(df): | |
#Replace NaN with empty string | |
df.fillna("", inplace=True) | |
#Get labels from dataframe | |
training_labels = df["label"].values | |
df = df.drop("label",1) | |
training_data = df.values | |
#float input data | |
input_var_data = tf.Variable(initial_value=training_data, dtype=np.dtype(float)) | |
#string input labels | |
input_var_labels = tf.Variable(initial_value=training_labels) | |
init_op = tf.global_variables_initializer() | |
saver = tf.train.Saver() | |
#create log dir | |
if not os.path.exists(LOG_DIR): | |
os.makedirs(LOG_DIR) | |
#dummy session to save data as checkpoint | |
with tf.Session() as sess: | |
sess.run(init_op) | |
for n in range(1): | |
saver.save(sess, os.path.join(LOG_DIR, "model.ckpt"), n) | |
if __name__ == '__main__': | |
#get dataframe | |
visualize_data(dataframe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment