python - 当大小不同时,如何根据预测值绘制图形真实值?
问题描述
我是 Python 新手,目前正在开发一个包含 16k 行数据的项目,以预测游戏的全球销量。所以我决定使用 LGB 和 XGB Regressor,并拆分我的训练和测试数据集。
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, p2], '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,)
我非常坚持这一点,请帮助!
解决方案
推荐阅读
- sql - Oracle 是否允许对分区进行求和,但仅当它遵守某些条件时才允许,否则使用滞后?
- c# - 如何使用 onclick 属性 c# webbrowser 单击按钮?
- python - Kivy 2 行标签文本
- byte-buddy - 如何使用 ByteBuddy 的 InvokeDynamic 类调用虚拟方法句柄?
- c# - 数据库似乎在执行期间更新,然后更改消失
- c - 使用函数交换两个变量的值时,为什么我应该以地址而不是实际变量名为目标?
- ansible - Ansible-playbook - 如何在字符串中添加大写
- java - Maven项目中的Logback
- discord - 试图制作一个机器人来计算语音频道中的成员
- python-3.x - 比较 2 个相同大小的元组列表:比较和交换