Skip to content Skip to sidebar Skip to footer

Accuracy Of Multivariate Classification And Regression Models With Scikit-learn

I wrote one simple linear regression model and one decision tree model, they work good. My question is, how to calculate the accuracy of these two models. I mean, whats the differe

Solution 1:

Accuracy is a metric used for classification but not for regression. In the case of regression, you can use R squared, negative mean squared error, etc. Accuracy is defined as the number of data points classified correctly to the total number of data points and it not used in the case of continuous variables.

You can use the following metric for measuring the predictability of a regression model. https://scikit-learn.org/stable/modules/classes.html#regression-metrics For example, you can compute R squared using

metrics.r2_score(y_true, y_pred[, …])

Also, the following ones can be implemented for a classification model. https://scikit-learn.org/stable/modules/classes.html#classification-metrics Accuracy can be computed using

metrics.accuracy_score(y_true, y_pred[, …])

In your case, you can compute R squared for the regression model using:

y_pred_test = regression.predict(x_test)
metrics.score(y_true, y_pred_test)

And also the following gives you the accuracy of your decision tree.

y_pred_test = decision_tree.predict(x_test)
metrics.accuracy_score(y_true, y_pred_test)

Post a Comment for "Accuracy Of Multivariate Classification And Regression Models With Scikit-learn"