如何解决当大小不同时,如何根据预测值绘制图形真实值?
我是 Python 新手,目前我正在从事一个项目,该项目有 16,000 行数据,以预测游戏的全球销量。所以我决定使用 LGB 和 XGB 回归器,并拆分我的训练和测试数据集。
predictor_columns = [c for c in df3.columns if c != 'Global_Sales']
X = pd.DataFrame(df3,columns = predictor_columns)
y = df3['Global_Sales']
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state= 42)
model2 = LGBMRegressor(random_state=42)
model2.fit(X_train,y_train)
因此,当我尝试根据真实值绘制预测值时:
plt.figure(figsize=(10,10))
plt.scatter(y_test,y_pred2,c='crimson')
plt.yscale('log')
plt.xscale('log')
p1 = max(max(y_pred2),max(y_test))
p2 = min(min(y_pred2),min(y_test))
plt.plot([p1,p2],[p1,'b-')
plt.xlabel('True Values',fontsize=15)
plt.ylabel('Predictions',fontsize=15)
plt.axis('equal')
plt.show()
出现以下错误:
x and y must be the same size
所以我检查了我的真实和预测 y 的形状,我发现:
y_pred2.shape
(3156,)
y_test.shape
(789,)
我很纠结,请帮忙!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。