python - 元组索引超出范围,试图重塑
问题描述
我正在尝试按照下面链接中的 youtube 教程进行操作,但出现错误:“元组索引超出范围”我已将我的代码与视频进行了比较,它似乎匹配。这是返回错误的最后一行代码。我确实创建并编译了模型,必须删除该代码才能发布。关于如何纠正这个问题的任何想法?
#https://www.youtube.com/watch?v=PuZY9q-aKLw
#Load data
company = 'FB'
start = dt.datetime(2012,1,1)
end = dt.datetime(2020,1,1)
data = web.DataReader(company, 'yahoo', start, end)
#Prepare Data
scaler = MinMaxScaler(feature_range=(0,1))
scaled_data = scaler.fit_transform(data['Close'].values.reshape(-1,1))
prediction_days=60
x_train = []
y_train = []
for x in range(prediction_days, len(scaled_data)):
x_train.append(scaled_data[x-prediction_days:x, 0])
y_train.append(scaled_data[x, 0])
x_train, y_train = np.array(x_train), np.array(y_train)
x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
#Test the model accuracy
test_start = dt.date(2020,1,1)
test_end = dt.datetime.now()
test_data = web.DataReader(company, 'yahoo', test_start, test_end)
actual_prices = test_data['Close'].values
total_dataset = pd.concat((data['Close'], test_data['Close']), axis=0)
model_inputs = total_dataset[len(total_dataset)- len(test_data) - prediction_days:].values
model_inputs = model_inputs.reshape(-1, 1)
model_inputs = scaler.transform(model_inputs)
#Make predictions on test data
x_test = []
for x in range(prediction_days, len(model.inputs)):
x_test.append(model_inputs[x-prediction_days:x, 0])
x_test = np.array(x_test)
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))
解决方案
推荐阅读
- python - 在 ESXi 中使用 Ansible 和 Python
- c# - System.Data.SqlClient.SqlException:'UPDATE 语句与 FOREIGN KEY 约束“FK_Subject_Professor”冲突
- python - 用tensorflow计算一个量子算子的时间依赖期望值
- c# - 如何随时间启动协程?
- java - 如何在 JPQL 中正确执行 LIKE 和 CASE 子句
- sql - 如何将动态 json 键展平为 BigQuery 中的列?
- python - 你如何在 Python 中更改 PNG 的内容?
- android - Android 上的深色主题不适用于 IONIC 5
- git - 如何查看与我在 git 中的远程 master 相比,我的本地 master 前后有多少提交
- r - 隐藏 gt 包中的汇总行标签