首页 > 解决方案 > 如何在实际数据图的顶部绘制预测?

问题描述

当我只绘制实际值(原始数据集)时,它看起来很好,但是当我尝试将我的预测绘制到实际数据的图上时,事情变得很糟糕。

绘图功能:

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 )

和调用我的函数后的错误图: 不正确的价格图 不正确的体积图

那么,我在那里做错了什么?

标签: pythonmatplotlibmachine-learningdata-sciencerandom-forest

解决方案


推荐阅读