[英]Confusion Matrix : RecursionError
I had been trying to replicated an online tutorial for plotting confusion matrix but got recursion error, tried resetting the recursion limit but still the error persists. 我一直在尝试复制用于绘制混淆矩阵的在线教程,但遇到了递归错误,尝试重置递归限制,但错误仍然存在。 The code is a below: 代码如下:
log = LogisticRegression()
log.fit(x_train,y_train)
pred_log = log.predict(x_train)
confusion_matrix(y_train,pred_log)
The error I got is : 我得到的错误是:
---------------------------------------------------------------------------
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
The shape of the train and test data is as below 火车的形状和测试数据如下
x_train.shape,y_train.shape,x_test.shape,y_test.shape
# ((712, 7), (712,), (179, 7), (179,))
Tried with: sys.setrecursionlimit(1500)
尝试过: sys.setrecursionlimit(1500)
But still no resolution. 但是仍然没有解决方案。
Looks like you are recursively calling the same function. 看起来您正在递归调用相同的函数。 Try changing the outer function name. 尝试更改外部函数名称。
1 def confusion_matrix(test_data,pred_data): ----> 2 c_mat = confusion_matrix(test_data,pred_data) 3 return pd.DataFrame(c_mat)
To 至
def confusion_matrix_pd_convertor(test_data,pred_data):
c_mat = confusion_matrix(test_data,pred_data)
return pd.DataFrame(c_mat)
log = LogisticRegression()
log.fit(x_train,y_train)
pred_log = log.predict(x_train)
confusion_matrix_pd_convertor(y_train,pred_log)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.