python - 机器学习: Getting error in Confusion Matrix

标签 python machine-learning regression random-forest confusion-matrix

在运行随机森林回归模型时,我在运行混淆矩阵时遇到错误。该模型能够预测 y_pred,但我无法检查准确性,因为我无法运行准确性矩阵。

数据类型:

type(y_test)
Out[124]: numpy.ndarray

type(y_pred)
Out[125]: numpy.ndarray

下面是我的混淆矩阵代码:

from sklearn.metrics import confusion_matrix
matrix = confusion_matrix(y_test, y_pred)

print(matrix)

from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)

错误:

confusion_matrix(y_test, y_pred)

Traceback (most recent call last):

File "<ipython-input-121-7a3dbcfd18a0>", line 1, in <module>
confusion_matrix(y_test, y_pred)

File "/Users/srikantswamy/anaconda3/lib/python3.6/site-packages/sklearn  /metrics/classification.py", line 253, in confusion_matrix
y_type, y_true, y_pred = _check_targets(y_true, y_pred)

File "/Users/srikantswamy/anaconda3/lib/python3.6/site-packages/sklearn /metrics/classification.py", line 88, in _check_targets
raise ValueError("{0} is not supported".format(y_type))

ValueError: continuous is not supported

最佳答案

给出一个简单的答案:混淆矩阵是一个通常用于描述分类模型(或“分类器”)性能的表格。在您的情况下,您正在尝试找到连续变量的混淆矩阵。对于回归,使用均方误差。 看看这个讲座pdf:http://www.it.uu.se/edu/course/homepage/sml/lectures/lecture3_handout.pdf

关于python - 机器学习: Getting error in Confusion Matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53095290/

相关文章:

python - django python manage.py runserver RuntimeError : Settings already configured

python - 了解 PyTorch CNN channel

python - 与 Scikit-Learn 的 Logistic 回归相比,Tensorflow 的性能要差得多

machine-learning - 许多机器学习模型 - 保存和加载

r - R 中随机森林回归模型中的 corr.bias 参数

Python for 循环使用列表

python - 为什么套接字行为依赖于打印语句?

R 中数据帧的回归循环

python - 代码在 IDE 中有效,但在终端控制台中无效

apache-spark - Spark AFTSurvivalRegression 参数