0
$\begingroup$

I was working on a project and I got a 0.98 R^2 score on both the training and test data sets and 0.91 training mse and 1.02 test mse, But my Actual values vs Predicted values looks like this, I was wondering that if this is considered accepteable and if my model is preforming well. I have also added the residuals plot.Thanks in advance.

model = xgb.XGBRegressor()
model.fit(X_train, y_train)

train_r2 = model.score(X_train, y_train)
y_train_pred = model.predict(X_train)
train_mse = mean_squared_error(y_train, y_train_pred)
test_r2 = model.score(X_test, y_test)
y_test_pred = model.predict(X_test)
test_mse = mean_squared_error(y_test, y_test_pred)
print(f'Test R^2 score: {test_r2}, Test MSE : {test_mse}')
print(f'Training R^2 score: {train_r2}, Training MSE : {train_mse}')

predicted_values = model.predict(X_test)
plt.scatter(y_test, predicted_values, color='green', alpha=0.4)
plt.xlabel("Actual Values")
plt.ylabel("Predicted Values")
plt.title("Actual vs. Predicted Values")
plt.show()

residuals = y_test - predicted_values

plt.scatter(y_test, residuals, alpha=0.5)
plt.xlabel("Actual Values")
plt.ylabel("Residuals")
plt.axhline(y=0, color='r', linestyle='-')
plt.title("Residual Plot")
plt.show()

enter image description here

enter image description here

$\endgroup$
9
  • $\begingroup$ I’m with you on your skepticism! How do you compute those $R^2$ scores? How do you plot your data? $\endgroup$
    – Dave
    Nov 5 at 23:08
  • $\begingroup$ model = xgb.XGBRegressor() model.fit(X_train, y_train) r2 = model.score(X_train, y_train) y_train_pred = model.predict(X_train) mse = mean_squared_error(y_train, y_train_pred) test_r2 = model.score(X_test, y_test) print(f'Training R^2 score: {r2}, Training MSE : {mse}') $\endgroup$
    – Ario Alavi
    Nov 5 at 23:38
  • $\begingroup$ predicted_values = model.predict(X_test) plt.scatter(y_test, predicted_values, color='green', alpha=0.4) plt.xlabel("Actual Values") plt.ylabel("Predicted Values") plt.title("Actual vs. Predicted Values") plt.show() thanks for taking the time to help. $\endgroup$
    – Ario Alavi
    Nov 5 at 23:39
  • $\begingroup$ Could you please edit that into your original question as a code block with comments? Thanks! $\endgroup$
    – Dave
    Nov 5 at 23:48
  • $\begingroup$ Sure, and thank you $\endgroup$
    – Ario Alavi
    Nov 6 at 0:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.