Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 混淆矩阵:递归错误_Python 3.x_Pandas_Scikit Learn - Fatal编程技术网

Python 3.x 混淆矩阵:递归错误

Python 3.x 混淆矩阵:递归错误,python-3.x,pandas,scikit-learn,Python 3.x,Pandas,Scikit Learn,我一直在尝试复制一个绘制混淆矩阵的在线教程,但出现递归错误,尝试重置递归限制,但错误仍然存在。代码如下所示: log = LogisticRegression() log.fit(x_train,y_train) pred_log = log.predict(x_train) confusion_matrix(y_train,pred_log) 我得到的错误是: ------------------------------------------------------------------

我一直在尝试复制一个绘制混淆矩阵的在线教程,但出现递归错误,尝试重置递归限制,但错误仍然存在。代码如下所示:

log = LogisticRegression()
log.fit(x_train,y_train)
pred_log = log.predict(x_train)
confusion_matrix(y_train,pred_log)
我得到的错误是:

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-57-4b8fbe47e72d> in <module>
----> 1 (confusion_matrix(y_train,pred_log))

<ipython-input-48-92d5242f8580> in confusion_matrix(test_data, pred_data)
      1 def confusion_matrix(test_data,pred_data):
----> 2     c_mat = confusion_matrix(test_data,pred_data)
      3     return pd.DataFrame(c_mat)

... last 1 frames repeated, from the frame below ...

<ipython-input-48-92d5242f8580> in confusion_matrix(test_data, pred_data)
      1 def confusion_matrix(test_data,pred_data):
----> 2     c_mat = confusion_matrix(test_data,pred_data)
      3     return pd.DataFrame(c_mat)

RecursionError: maximum recursion depth exceeded
试用:
sys.setrecursionlimit(1500)


但仍然没有解决方案

看起来您正在递归调用同一个函数。尝试更改外部函数名

def混淆矩阵pd转换器(测试数据、预测数据):
c_mat=混淆矩阵(测试数据、预测数据)
返回局部放电数据帧(c_-mat)
log=LogisticRegression()
对数拟合(x_列,y_列)
预测日志=日志预测(x列车)
混淆矩阵pd转换器(y列、预测日志)

看起来您正在递归调用同一个函数。尝试更改外部函数名

def混淆矩阵pd转换器(测试数据、预测数据):
c_mat=混淆矩阵(测试数据、预测数据)
返回局部放电数据帧(c_-mat)
log=LogisticRegression()
对数拟合(x_列,y_列)
预测日志=日志预测(x列车)
混淆矩阵pd转换器(y列、预测日志)

我认为应该是
pred\u log=log.predict(x\u test)
combusion\u matrix(y\u test,pred\u log)
已经尝试了您建议的解决方案,但在这种情况下错误仍然相同。您看到了吗?我认为应该是
pred\u log=log.predict(x\u test)
combusion\u matrix(y\u test,pred\u log)
已经尝试了您建议的解决方案,但在这种情况下错误仍然相同。您看到了吗?
x_train.shape,y_train.shape,x_test.shape,y_test.shape 
# ((712, 7), (712,), (179, 7), (179,))
      1 def confusion_matrix(test_data,pred_data):
----> 2     c_mat = confusion_matrix(test_data,pred_data)
      3     return pd.DataFrame(c_mat)