【问题标题】:value error while plotting confusion matrix in activity recognition project在活动识别项目中绘制混淆矩阵时的值错误
【发布时间】:2020-12-02 07:15:25
【问题描述】:

尝试在人类活动识别上绘制混淆矩阵,一切正常,接受混淆矩阵。我无法打印混淆矩阵。

cm = confusion_matrix(y_test.values,y_pred)
plot_confusion_matrix(cm, np.unique(y_pred))

结果:

ValueError                                Traceback (most recent call last)
<ipython-input-29-7fc4511c54b7> in <module>
----> 1 cm = confusion_matrix(y_test.values,y_pred)
      2 plot_confusion_matrix(cm, np.unique(y_pred))  # plotting confusion matrix

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
     71                           FutureWarning)
     72         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 73         return f(**kwargs)
     74     return inner_f
     75 

~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight, normalize)
    274 
    275     """
--> 276     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    277     if y_type not in ("binary", "multiclass"):
    278         raise ValueError("%s is not supported" % y_type)

~\anaconda3\lib\site-packages\sklearn\metrics\_classification.py in _check_targets(y_true, y_pred)
     79     y_pred : array or indicator matrix
     80     """
---> 81     check_consistent_length(y_true, y_pred)
     82     type_true = type_of_target(y_true)
     83     type_pred = type_of_target(y_pred)

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
    254     uniques = np.unique(lengths)
    255     if len(uniques) > 1:
--> 256         raise ValueError("Found input variables with inconsistent numbers of"
    257                          " samples: %r" % [int(l) for l in lengths])
    258 

ValueError: Found input variables with inconsistent numbers of samples: [2947, 2937]

【问题讨论】:

    标签: python machine-learning scikit-learn logistic-regression confusion-matrix


    【解决方案1】:

    y_test.valuesy_pred 长度不同,一个包含 2947 个条目,另一个包含 2937 个

    【讨论】:

      猜你喜欢
      • 2016-01-31
      • 2021-03-13
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 2021-07-21
      • 2016-06-04
      相关资源
      最近更新 更多