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$
8
  • $\begingroup$ I’m with you on your skepticism! How do you compute those $R^2$ scores? How do you plot your data? $\endgroup$
    – Dave
    Commented Nov 5, 2023 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
    Commented Nov 5, 2023 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
    Commented Nov 5, 2023 at 23:39
  • $\begingroup$ Could you please edit that into your original question as a code block with comments? Thanks! $\endgroup$
    – Dave
    Commented Nov 5, 2023 at 23:48
  • $\begingroup$ Does this give you a score of $0.98$ or a score of $98?$ $\endgroup$
    – Dave
    Commented Nov 6, 2023 at 0:40

0

Your Answer

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