How to plot a graph true value against predicted value when the size is different?

431 Views Asked by At

I am new to Python and I am currently working on a project with 16k rows of data to predict the game global sales. So I have decided to use LGB and XGB Regressor, and split my train and test dataset.

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)

So when I try to plot the predicted value against the true value:

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()

The following error occurred:

x and y must be the same size

So I checked the shape of my true and predicted y and I found that:

y_pred2.shape
(3156,)

y_test.shape
(789,)

I am terribly stuck on this, please help !

0

There are 0 best solutions below