简体   繁体   中英

How to output a value of a CNN for Stock Prediction

I built an LSTM based Neural Network to predict the price of BTC. Its training is decent I'd say, but I'm not sure about how to make it predict tomorrow's price for example.

I tried Keras' method predict for my trained model with today's price as argument and then tensorflow's "tf.argmax" to pick the highest certainty in the array outputed. Now I know that it refers to the class predicted in the case of computer vision but I really have no clue about what those probabilities refer to in that case.

Model built:


  model = Sequential()
  model.add(LSTM(neurons, return_sequences=True, input_shape=(inputs.shape[1], inputs.shape[2]), activation=activ_func))
  model.add(Dropout(dropout))
  model.add(LSTM(neurons, return_sequences=True, activation=activ_func))
  model.add(Dropout(dropout))
  model.add(LSTM(neurons, activation=activ_func))
  model.add(Dropout(dropout))
  model.add(Dense(units=output_size))
  model.add(Activation(activ_func))
  model.compile(loss=loss, optimizer=optimizer, metrics=['mae'])
  model.summary()
  plot_keras_model(model, show_shapes=True, show_layer_names=False)

Training and prediction:


prediction_data = get_today_price4prediction('bitcoin', tag="BTC")
X_prediction = create_inputs(prediction_data)
X_prediction = to_array(X_prediction)
btc_history = btc_model.fit(X_train, Y_train_btc, epochs=epochs, batch_size=batch_size, verbose=1, validation_data=(X_test, Y_test_btc), shuffle=False)
predictions = btc_model.predict(X_prediction, verbose=1, steps=None)
plot_results(btc_history, btc_model, Y_train_btc, coin='BTC')
predictions = tf.math.argmax(predictions)
print(predictions)

The expected output is a 7D numpy array with values from 1 to 1e-7 . But I dont know what those values refers to. Any suggestion?

Sounds like you are trying to get results without knowing your data. Don't ever do that, you are likely to end up with useless results.

I don't know where you got the data from, but that place should describe what the target is. In this case it is probably a categorical target because of the multi-dimensional output (it is if you're using categorical crossentropy loss for example but it is also not stated in the code). If that is the case and the output you expect is a real number, the categories are probably ranges of this number, and each value in the output array would be the probability that this number belongs to each of these ranges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM