首页 > 解决方案 > 当大小不同时,如何根据预测值绘制图形真实值?

问题描述

我是 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,)

我非常坚持这一点,请帮助!

标签: pythonmatplotlibxgboostlightgbmxgbregressor

解决方案


推荐阅读