what is difference between metrics.r2_score and acccuracy_score
Asked Answered
P

1

5

what is difference between metrics.r2_score and acccuracy_score for calculating accuracy in a machine learning model.

When I try this:

    from sklearn import metrics
    from sklearn.metrics import accuracy_score 
    print("Accuracy = ", 1 - metrics.r2_score(y_test,y_pred))
    print("Accuracy1 = ", accuracy_score(y_test,y_pred))

I get this:

Accuracy =  0.9871059362722768
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)
<ipython-input-16-d19d2fd401dc> in <module>
      2 from sklearn.metrics import accuracy_score
      3 print("Accuracy = ", 1 - metrics.r2_score(y_test,y_pred))
----> 4 print("Accuracy1 = ", accuracy_score(y_test,y_pred))

~/anaconda3/lib/python3.7/site-packages/sklearn/metrics/classification.py in 
accuracy_score(y_true, y_pred, normalize, sample_weight)
    174 
    175     # Compute accuracy for each possible representation
--> 176     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    177     check_consistent_length(y_true, y_pred, sample_weight)
    178     if y_type.startswith('multilabel'):

~/anaconda3/lib/python3.7/site-packages/sklearn/metrics/classification.py in 
_check_targets(y_true, y_pred)
     86     # No metrics support "multiclass-multioutput" format
     87     if (y_type not in ["binary", "multiclass", "multilabel-indicator"]):
---> 88         raise ValueError("{0} is not supported".format(y_type))
     89 
     90     if y_type in ["binary", "multiclass"]:

ValueError: continuous is not supported
Papeete answered 30/9, 2019 at 7:7 Comment(1)
Welcome to SO: question has nothing to do with artificial-intelligence or floating-accuracy - kindly do not spam irrelevant tags (removed).Towards
F
7

Accuracy score is make for classification problems:

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html#sklearn.metrics.accuracy_score

This is way you get the error: continuous is not supported

The input is:

Parameters: 

y_true : 1d array-like, or label indicator array / sparse matrix

    Ground truth (correct) labels.
y_pred : 1d array-like, or label indicator array / sparse matrix

    Predicted labels, as returned by a classifier.

R2.score is made for continous variables, so for regression problems: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html

Fishback answered 30/9, 2019 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.