plt.plot(range(len(meiguo_Num["confirmNum"])-7,len(meiguo_Num["confirmNum"])),arima314.forecast(7)[0],color="red",label="预测值")
时间: 2023-11-21 12:44:50 浏览: 17
这段代码是用来绘制ARIMA模型预测出的未来7天的确诊人数数据的折线图,其中:
- `range(len(meiguo_Num["confirmNum"])-7,len(meiguo_Num["confirmNum"]))` 表示横坐标,即要绘制的数据在原始数据中的索引范围,这里是从原始数据中最后7天开始到最后一天(即未来7天)的范围。
- `arima314.forecast(7)[0]` 表示纵坐标,即ARIMA模型预测出的未来7天的确诊人数数据。
- `color="red"` 表示折线的颜色为红色。
- `label="预测值"` 表示该折线的标签为“预测值”,用于在图例中显示该线段代表的含义。
相关问题
temp = range(len(meiguo_Num["confirmNum"].values)) plt.plot(temp,meiguo_Num["confirmNum"].values)
这段代码使用了Python的matplotlib库,通过plt.plot函数绘制了美国新冠病例的累计确诊数曲线。其中,meiguo_Num["confirmNum"].values表示美国新冠病例的累计确诊数数据,而range(len(meiguo_Num["confirmNum"].values))则是用来生成x轴坐标的序列,表示该数据的第0个到第(len(meiguo_Num["confirmNum"].values)-1)个数据对应的x轴坐标。
绘制训练集和测试集的真实值和预测值图像 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(改写以上代码,使得训练集部分和测试集部分分别绘制在两张图上
下面是改写后的代码,将训练集和测试集的真实值和预测值分别绘制在两张图上:
```
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()
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)