3
$\begingroup$

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)
$\endgroup$

1 Answer 1

4
$\begingroup$

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)
$\endgroup$

Your Answer

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

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