python - 如何在实际数据图的顶部绘制预测?
问题描述
当我只绘制实际值(原始数据集)时,它看起来很好,但是当我尝试将我的预测绘制到实际数据的图上时,事情变得很糟糕。
绘图功能:
def plotData(df , predicted ) :
fig1= plt.figure(figsize= (15 ,5));
plt.subplot(1 ,2 ,1);
df.plot(x = 'Date' , y = ['Close'] )
plt.plot(df['Date'] , predicted)
plt.title('BitcoinPrice - Date')
plt.xlabel('Date')
plt.ylabel('Prices')
plt.close(fig1)
fig2 = plt.figure(figsize=(15,5));
plt.subplot(1,2,2);
df.plot(x='Date' , y = 'Volume')
plt.title('BitcoinVolume-Date')
plt.xlabel('Date')
plt.ylabel('Volume')
plt.legend(loc ='best')
plt.close(fig2)
我将实际数据帧和预测值发送为 "predicted" 。例如,当我创建一个没有“预测”值参数的函数时,函数会正确绘制这些图。
正确的情节: 正确的价格情节
我的模型:
plotData(bitcoinDatrain , x_test, y_train , y_test = train_test_split(date , price , test_size = 0.25, random_state = 0)
forest_model = RandomForestRegressor(random_state = 1 )
forest_model.fit(date , price.ravel())
forest_predictions = forest_model.predict(date)
MAEForest = mean_squared_error(forest_predictions , price)
plotData(bitcoinDataFrame , forest_predictions )
那么,我在那里做错了什么?
解决方案
推荐阅读
- php - Laravel 多实例干扰
- java - 使用 RestClient 部署 Quarkus 微服务
- vue.js - (Vue.js) 电容器移动应用程序后台处理/服务工作者(接收消息)
- json - 我想使用 JOLT 转换将 A json 转换为另一个 Json
- json - 处理包含多维 JSON 的列表,而不使用任何嵌套的 for 循环
- javascript - AR.js 中挤压的 SVG 图像引发未定义错误的 getUniforms
- javascript - 反应滑块和文本框 - 两者都可编辑但两个值始终保持相同
- excel - 根据另一个动态字段过滤 Excel 中的注释
- pointers - HexRays(IDAPro6.8) 指向结构“中心”的指针,如何反编译正确?
- matlab - Simulink - 从初始化回调更新结构参数