[Python] How to predict list elements outside the bounds of a py dataframe?

Discussão em 'Python' iniciado por Stack, Janeiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I built a model based on LSTM and trained it to predict stock price changes during the day, where the unit of time is one second. The test data gives a result comparable to the real one, but I need to get a forecast for the future outside the existing range. What am I doing wrong?


    close = df['close']
    values = close.values
    values = values.reshape(-1, 1)

    training_scaler = MinMaxScaler(feature_range=(0, 1))

    testing_input = values
    testing_input = training_scaler.fit_transform(testing_input)
    testing = []
    for i in range(50, len(testing_input) + 50):
    testing.append(testing_input[i - 50:i][0])

    testing = np.array(testing)
    testing = np.reshape(testing, (testing.shape[0], testing.shape[1], 1))
    predict = model.predict(testing)
    predict = training_scaler.inverse_transform(predict)

    plt.plot(values, color='blue', label='Stock Price')
    plt.plot(predict, color='red', label='Predicted Stock Price')
    plt.title('Changes')
    plt.xlabel('Timeline')
    plt.ylabel('Stock Price')
    plt.legend()
    plt.show()


    My results

    It turns out that the model predicts data that I already know. How can I predict future data?

    Continue reading...

Compartilhe esta Página