title: How Do I Save Tensorflow Predictions To A File? (CSV Preferred)
body: <pre><code>import pandas as pd
  import manipulate_data as md
  from math import sqrt
  from numpy import concatenate
  from matplotlib import pyplot
  from sklearn.preprocessing import MinMaxScaler
  from sklearn.preprocessing import LabelEncoder
  from sklearn.metrics import mean_squared_error
  from keras.models import Sequential
  from keras.layers import Dense
  from keras.layers import LSTM
  import datetime as dt
  import tensorflow as tf
  import matplotlib.pyplot as plt
  
  df = pd.read_csv('중계동_dummies.csv')
  
  # train Parameters
  seq_length = 365
  data_dim = 8
  hidden_dim = 10
  output_dim = 1
  learning_rate = 0.032
  iterations = 500
  
  trainX, trainY, testX, testY = md.preprocess_data(df,seq_length)
  
  X = tf.placeholder(tf.float32, [None, seq_length, data_dim])
  Y = tf.placeholder(tf.float32, [None, 1])
  
  # build a LSTM network
  cell = tf.contrib.rnn.BasicLSTMCell(
      num_units=hidden_dim, state_is_tuple=True, activation=tf.nn.relu)
  outputs, _states = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)
  Y_pred = tf.contrib.layers.fully_connected(
      outputs[:, -1], output_dim, activation_fn=None)  # We use the last cell's output
  
  # cost/loss
  loss = tf.reduce_sum(tf.square(Y_pred - Y))  # sum of the squares
  # optimizer
  optimizer = tf.train.AdamOptimizer(learning_rate)
  train = optimizer.minimize(loss)
  
  # RMSE
  targets = tf.placeholder(tf.float32, [None, 1])
  predictions = tf.placeholder(tf.float32, [None, 1])
  rmse = tf.sqrt(tf.reduce_mean(tf.square(targets - predictions)))
  mape = tf.reduce_mean(tf.abs(tf.divide(tf.subtract(predictions,targets),(targets + 1e-10))))
  
  
  with tf.Session() as sess:
      init = tf.global_variables_initializer()
      sess.run(init)
  
      saver = tf.train.Saver()
      # Training step
      for i in range(iterations):
          _, step_loss = sess.run([train, loss], feed_dict={
              X: trainX,
              Y: trainY
              })
          print("[step: {}] loss: {}".format(i, step_loss))
  
      saver.save(sess, 'my_test_model')
  
      # Test step
      test_predict = sess.run(Y_pred, feed_dict={X: testX})
      test_predict = np.asarray(test_predict)
      np.savetxt("prediction.csv", test_predict, delimiter=",")
      rmse_val = sess.run(rmse, feed_dict={
                      targets: testY, predictions: test_predict})
      mape_val = sess.run(mape, feed_dict={
                      targets: testY, predictions: test_predict})
      print("RMSE: {}, MAPE: {}".format(rmse_val, mape_val))
  
      # Plot predictions
      plt.plot(testY)
      plt.plot(test_predict)
      plt.xlabel("Time Period")
      plt.ylabel("Apartment Price")
      plt.show()
  </code></pre>
  
  <p>This is my code. I have trained a model on housing price data from 2011-2018 and have attempted to predict housing prices for 2019. I want to save my prediction results to a .csv file.
  My goal is to create a simple webpage and display the predictions using Google Maps API, so I would need each individual result. However, not much resources exist for saving prediction results to a .csv file.</p>
  
  <p>How can I do so?
  Or 
  What are some better ways to achieve my goal?</p>