title: RNNs - How to min-max scaling out-of-sample for test case
body: <p>I'm trying to predict Bitcoin price by RNNs with Tensorflow.</p>
  
  <p>My model is quite simple RNNs with LSTM : </p>
  
  <pre><code>cell = tf.contrib.rnn.BasicLSTMCell(num_units=num_hidden, state_is_tuple=True, activation=tf.tanh)
  outputs, _ = tf.nn.dynamic_rnn(cell, X, dtype=tf.float32)
  predict = tf.contrib.layers.fully_connected(outputs[:, -1], num_output,
                                              activation_fn=None)  # use last cell's output
  cost = tf.reduce_sum(tf.square(predict - Y))  # MSE
  optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)'
  </code></pre>
  
  <p>I have 35000 hourly Bitcoin price data.</p>
  
  <p>I split it to train dataset(older data) and test dataset(newer data).</p>
  
  <p>Before training I tried to Min-Max Scaling so as to all train data is scaled between 0 to 1.</p>
  
  <pre><code># to avoid divide by zero, add noise
  data = (data - np.min(np.abs(data), axis=0)) / (
              np.max(np.abs(data), axis=0) - np.min(np.abs(data), axis=0) + 1e-8)
  </code></pre>
  
  <p>However, since Bitcoin price increase dramatically last year(which is under test dataset), my model cannot predict at all for test dataset.</p>
  
  <p><a href="https://i.stack.imgur.com/sRSDf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sRSDf.png" alt="Sad prediction result. Image from here"></a></p>
  
  <p>(Image from <a href="https://lilianweng.github.io/lil-log/2017/07/08/predict-stock-prices-using-RNN-part-1.html" rel="nofollow noreferrer">here</a>)</p>
  
  <p>I tried another two ways :</p>
  
  <ol>
  <li><p>Just fix max price data
  I just fix maximum price such as 35,000$. </p>
  
  <pre><code># to avoid divide by zero, add noise
  data = (data - np.min(np.abs(data), axis=0)) / (
              35000 - np.min(np.abs(data), axis=0) + 1e-8)
  </code></pre>
  
  <p>It works well and prediction result is fine. However, I'm feeling this is 
  quite unsmart way - what if Bitcoin rise over 35,000$?</p></li>
  <li><p>Predict by increase/decrease rate</p>
  
  <pre><code>data = data[1:] / data[:len(data) - 1]
  </code></pre>
  
  <p>I modified whole data such as above so as to data will be like (price for 
  tomorrow) / (price for today). </p>
  
  <p>In this way, whole data is just between 0.8 ~ 1.2 so it doesn't need any 
  min-max scaling.</p>
  
  <p>However, this way fails since it is not trained well. </p></li>
  </ol>
  
  <p>Is there any better way for this problem?</p>