绘制训练集真实值和预测值 trainPredictPlot = np.empty_like(data.values) trainPredictPlot[:, :] = np.nan trainPredictPlot[look_back:len(trainPredict)+look_back, :] = trainPredict plt.figure(figsize=(10,5)) plt.plot(data.values, label='True Data') plt.plot(trainPredictPlot, label='Predicted Data') plt.title('Training Set') plt.xlabel('Time/h') plt.ylabel('kwh') plt.legend() plt.show() # 绘制测试集真实值和预测值 testPredictPlot = np.empty_like(data.values) testPredictPlot[:, :] = np.nan testPredictPlot[len(trainPredict)+(look_back*2)+1:len(data)-1, :] = testPredict plt.figure(figsize=(10,5)) plt.plot(data.values, label='True Data') plt.plot(testPredictPlot, label='Predicted Data') plt.title('Testing Set') plt.xlabel('Time/h') plt.ylabel('kwh') plt.legend() plt.show()改写这段代码,使得训练集和测试集的曲线分别绘制在两张图上
时间: 2024-02-29 12:51:05 浏览: 185
修改后的代码如下:
```
# 绘制训练集真实值和预测值
trainPredictPlot = np.empty_like(data.values)
trainPredictPlot[:, :] = np.nan
trainPredictPlot[look_back:len(trainPredict)+look_back, :] = trainPredict
plt.figure(figsize=(10,5))
plt.plot(data.values, label='True Data')
plt.plot(trainPredictPlot, label='Predicted Data')
plt.title('Training Set')
plt.xlabel('Time/h')
plt.ylabel('kwh')
plt.legend()
plt.show()
# 绘制测试集真实值和预测值
testPredictPlot = np.empty_like(data.values)
testPredictPlot[:, :] = np.nan
testPredictPlot[len(trainPredict)+(look_back*2)+1:len(data)-1, :] = testPredict
plt.figure(figsize=(10,5))
plt.plot(data.values, label='True Data')
plt.plot(testPredictPlot, label='Predicted Data')
plt.title('Testing Set')
plt.xlabel('Time/h')
plt.ylabel('kwh')
plt.legend()
plt.show()
```
这样修改后,训练集和测试集的真实值和预测值将分别绘制在两张图上。
阅读全文
相关推荐
















