Getting InvalidIndexError: (slice(115770, None, None), slice



试图用过去50天的股价来预测一家公司(苹果公司)的收盘价。

get: pandas.errors.InvalidIndexError: (slice(115770, None, None), slice(None, None, None))

#Import the librarires
import math
import pandas_datareader as web
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
#Get the stock quote
df =web.DataReader ('AAPL', data_source='yahoo', start='2017-01-01', end='2022-05-31')
.....
#Create the data sets x_test and y_test
x_test = []
y_test = dataset[training_data_len:, :]
for i in range(50, len(test_data)):
x_test.append(test_data[i-50:i, 0])
#Convert Data to a numpy array
x_test = np.array(x_test)
#Reshape the data
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1 ))
#Get the models predicte price values
predictions = model.predict(x_test)
#inverse transform the prediction 
# basically unscaling the values and have the prediction contain the same values as the y_testdataset, given the x_dataset
predictions = scaler.inverse_transform(predictions)

dataset[training_data_len:, :]定位多索引列,您可能希望loc定位行和列

dataset.loc[training_data_len:, :]

相关内容

  • 没有找到相关文章

最新更新