简体   繁体   English

在活动识别项目中绘制混淆矩阵时的值错误

[英]value error while plotting confusion matrix in activity recognition project

trying to plot confusion matrix on human activity recognition everything works fine accept the confusion matrix.试图 plot 混淆矩阵对人类活动识别一切正常接受混淆矩阵。 I am not able to print confusion matrix.我无法打印混淆矩阵。

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

result:结果:

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]

y_test.values and y_pred aren't the same length, one contains 2947 entries and the other 2937 y_test.valuesy_pred长度不同,一个包含 2947 个条目,另一个包含 2937 个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM