in Education by
I'm working on some Artificial Intelligence project and I want to predict the bitcoin trend but while using the model. predict function from Keras with my test_set, the prediction is always equal to 1 and the line in my diagram is therefore always straight. import csv import matplotlib.pyplot as plt import numpy as np import pandas as pd from cryptory import Cryptory from keras.models import Sequential, Model, InputLayer from keras.layers import LSTM, Dropout, Dense from sklearn.preprocessing import MinMaxScaler def format_to_3d(df_to_reshape): reshaped_df = np.array(df_to_reshape) return np.reshape(reshaped_df, (reshaped_df.shape[0], 1, reshaped_df.shape[1])) crypto_data = Cryptory(from_date = "2014-01-01") bitcoin_data = crypto_data.extract_coinmarketcap("bitcoin") sc = MinMaxScaler() for col in bitcoin_data.columns: if col != "open": del bitcoin_data[col] training_set = bitcoin_data; training_set = sc.fit_transform(training_set) # Split the data into train, validate and test train_data = training_set[365:] # Split the data into x and y x_train, y_train = train_data[:len(train_data)-1], train_data[1:] model = Sequential() model.add(LSTM(units=4, input_shape=(None, 1))) # 128 -- neurons**? # model.add(Dropout(0.2)) model.add(Dense(units=1, activation="softmax")) # activation function could be different model.compile(optimizer="adam", loss="mean_squared_error") # mse could be used for loss, look into optimiser model.fit(format_to_3d(x_train), y_train, batch_size=32, epochs=15) test_set = bitcoin_data test_set = sc.transform(test_set) test_data = test_set[:364] input = test_data input = sc.inverse_transform(input) input = np.reshape(input, (364, 1, 1)) predicted_result = model.predict(input) print(predicted_result) real_value = sc.inverse_transform(input) plt.plot(real_value, color='pink', label='Real Price') plt.plot(predicted_result, color='blue', label='Predicted Price') plt.title('Bitcoin Prediction') plt.xlabel('Time') plt.ylabel('Prices') plt.legend() plt.show() The training set performance looks like this: 1566/1566 [==============================] - 3s 2ms/step - loss: 0.8572 Epoch 2/15 1566/1566 [==============================] - 1s 406us/step - loss: 0.8572 Epoch 3/15 1566/1566 [==============================] - 1s 388us/step - loss: 0.8572 Epoch 4/15 1566/1566 [==============================] - 1s 388us/step - loss: 0.8572 Epoch 5/15 1566/1566 [==============================] - 1s 389us/step - loss: 0.8572 Epoch 6/15 1566/1566 [==============================] - 1s 392us/step - loss: 0.8572 Epoch 7/15 1566/1566 [==============================] - 1s 408us/step - loss: 0.8572 Epoch 8/15 1566/1566 [==============================] - 1s 459us/step - loss: 0.8572 Epoch 9/15 1566/1566 [==============================] - 1s 400us/step - loss: 0.8572 Epoch 10/15 1566/1566 [==============================] - 1s 410us/step - loss: 0.8572 Epoch 11/15 1566/1566 [==============================] - 1s 395us/step - loss: 0.8572 Epoch 12/15 1566/1566 [==============================] - 1s 386us/step - loss: 0.8572 Epoch 13/15 1566/1566 [==============================] - 1s 385us/step - loss: 0.8572 Epoch 14/15 1566/1566 [==============================] - 1s 393us/step - loss: 0.8572 Epoch 15/15 1566/1566 [==============================] - 1s 397us/step - loss: 0.8572 I'm supposed to print a plot with the Real Price and the Predicted Price, the Real Price is displayed properly but the Predicted price is only a straight line because of that model. predict that only contains the value 1. Thanks in advance! Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Actually, you are trying to predict a price value means that you're aiming at solving a regression problem and not a classification problem. However, in the previous layer of your network (model.add(Dense(units=1, activation=" softmax"))) you have a single neuron (which would be adequate for a regression problem), but you've chosen to use a softmax activation function. The softmax function is used in multi-class classification problems, to normalize the outputs into a probability distribution. If you have a single output neuron and you apply softmax, the final result will always 1.0, as it is the only parameter of the probability distribution. In short, for regression problems, you do not use an activation function, as the network is intended to already output the predicted value. If you wish to know more about Keras Model then visit this Artificial Intelligence Course.

Related questions

0 votes
    I am training on 970 samples and validating on 243 samples. How big should batch size and number of epochs be ... on data input size? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I don't understand which accuracy in the output to use to compare my 2 Keras models to see which one is better. ... - val_acc: 0.7531 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    How to load a model from an HDF5 file in Keras? What I tried: model = Sequential() model.add(Dense(64, ... list index out of range Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have a simple NN model for detecting hand-written digits from a 28x28px image written in python using Keras: ... that actually means? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I use a linear SVM to predict the sentiment of tweets. The LSVM classifies the tweets as neutral or positive ... predict('textoftweet') Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    If I want to use the BatchNormalization function in Keras, then do I need to call it once only at the ... much of a difference. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    When you run a Keras neural network model you might see something like this in the console: Epoch 1/3 6/1000 [. ... to a file. Thanks! Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I have trained a binary classification model with CNN, and here is my code model = Sequential() model.add(Convolution2D ... I do that? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have just built my first model using Keras and this is the output. It looks like the standard output you get ... - loss: 0.1928 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to read an image from electrocardiography and detect each one of the main waves in it (P wave, QRS ... some ideas? Thanks! Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    In the MNIST beginner tutorial, there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf ... (x,1)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I know the basics of feedforward neural networks, and how to train them using the backpropagation algorithm, but I'm ... , even better. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am looking for an open source neural network library. So far, I have looked at FANN, WEKA, and OpenNN. Are the ... , and ease of use. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm hoping to use either Haskell or OCaml on a new project because R is too slow. I need to be able to ... in either Haskell or OCaml? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...