I am build a linear regression model and a decision tree model using sklearn. I want to compare the performance of these two models, I have calculated the r2_score for both the models. I have calculated the model.score for both the values. I am confused which is a better metric to compare the performance of these models. Also what does model.score gives?

from sklearn.metrics import r2_score
score_DT = r2_score(y_pred_DT,y_test)

dt_score = regressorDT.score(X_test,y_test)

1 Answer 1


Both functions are the same r2 metric and should produce the same results.

Your usage of the r2_score function is wrong. The first argument should be the ground truth values and not the predicted values, so in your case it should be:

score_DT = r2_score(y_test, y_pred_DT)

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.