Home > Enterprise >  Unable to plot line of best fit for regression
Unable to plot line of best fit for regression

Time:11-04

I already referred these posts enter image description here

My code to plot the best fit line looks like below

plt.scatter(X_test.values, Y_test.values, color="black") # throws error in this line
plt.plot(Y_test, y_pred, color="blue", linewidth=3)

plt.xticks(())
plt.yticks(())

plt.show()

ValueError: x and y must be the same size

CodePudding user response:

Did you mean to scatter y_pred and Y_test, instead of X_test and Y_test ?

X_test.values would be an array of arrays containing n_rows * n_cols values

CodePudding user response:

As of now, you are trying to plot 63 variables (from X_test) which is not possible. The best solution is to pick one variable from your dataset and look at it. This is best if you have one particular variable you want to evaluate.

But, it seems like you want to understand your model's performance. Sklearn has a nice page on different metrics you could use to evaluate your regression model.

  • Related