绘制训练集和测试集的真实值和预测值图像 train_predict_plot = np.empty_like(data_scaled) train_predict_plot[:, :] = np.nan train_predict_plot[time_steps:len(train_predict) + time_steps, :] = train_predict test_predict_plot = np.empty_like(data_scaled) test_predict_plot[:, :] = np.nan test_predict_plot[len(train_predict) + time_steps * 2 + 1:len(data_scaled) - 1, :] = test_predict plt.figure(figsize=(10, 6)) plt.plot(scaler.inverse_transform(data_scaled)) plt.plot(train_predict_plot) plt.plot(test_predict_plot) plt.legend(['True', 'Train Predict', 'Test Predict']) plt.xlabel('Time/h') plt.ylabel('kwh') plt.show(改写以上代码,使得训练集部分和测试集部分分别绘制在两张图上
时间: 2024-01-26 12:02:49 浏览: 131
下面是改写后的代码,将训练集和测试集的真实值和预测值分别绘制在两张图上:
```
train_predict_plot = np.empty_like(data_scaled)
train_predict_plot[:, :] = np.nan
train_predict_plot[time_steps:len(train_predict) + time_steps, :] = train_predict
test_predict_plot = np.empty_like(data_scaled)
test_predict_plot[:, :] = np.nan
test_predict_plot[len(train_predict) + time_steps * 2 + 1:len(data_scaled) - 1, :] = test_predict
# 绘制训练集部分真实值和预测值图像
plt.figure(figsize=(10, 6))
plt.plot(scaler.inverse_transform(data_scaled[:len(train_predict)]))
plt.plot(train_predict_plot[:len(train_predict)])
plt.legend(['True', 'Train Predict'])
plt.xlabel('Time/h')
plt.ylabel('kwh')
plt.title('Training Set')
plt.show()
# 绘制测试集部分真实值和预测值图像
plt.figure(figsize=(10, 6))
plt.plot(scaler.inverse_transform(data_scaled[len(train_predict) + time_steps * 2 + 1:]))
plt.plot(test_predict_plot[len(train_predict) + time_steps * 2 + 1:])
plt.legend(['True', 'Test Predict'])
plt.xlabel('Time/h')
plt.ylabel('kwh')
plt.title('Test Set')
plt.show()
```
阅读全文