metrics.r2_score 和 acccuracy_score 有啥区别

Posted

技术标签:

【中文标题】metrics.r2_score 和 acccuracy_score 有啥区别【英文标题】:what is difference between metrics.r2_score and acccuracy_scoremetrics.r2_score 和 acccuracy_score 有什么区别 【发布时间】:2020-01-29 11:04:00 【问题描述】:

metrics.r2_score 和 acccuracy_score 在机器学习模型中计算准确度的区别是什么。

当我尝试这个时:

    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))

我明白了:

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

【问题讨论】:

欢迎来到 SO:问题与 artificial-intelligencefloating-accuracy 无关 - 请不要向无关标签发送垃圾邮件(已删除)。 【参考方案1】:

准确度分数用于分类问题:

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

这是你得到错误的方式:不支持连续

输入是:

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 用于连续变量,所以对于回归问题:https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html

【讨论】:

以上是关于metrics.r2_score 和 acccuracy_score 有啥区别的主要内容,如果未能解决你的问题,请参考以下文章

使用 numpy 和 sklearn 计算 R^2(确定系数)给出不同的结果

如何在 Tensorflow 中计算 R^2

& 和 && 区别和联系,| 和 || 区别和联系

第三十一节:扫盲并发和并行同步和异步进程和线程阻塞和非阻塞响应和吞吐等

shell中$()和 ` `${}${!}${#}$[] 和$(()),[ ] 和(( ))和 [[ ]]

Java基础8---面向对象代码块和继承和this和super和重写和重载和final