Search code examples
pythoncompiler-errorsconfusion-matrix

confusion_matrix error 'DataFrame' "object is not callable"


What am I doing wrong? I set both vars to list. Also tried np.array.

y = list(y_test.values)
yhat = list(predictions)

print(y)
print(yhat)

confusion_matrix = pd.DataFrame(confusion_matrix(y, yhat), columns=["Predicted False", "Predicted True"], index=["Actual False", "Actual True"])
display(confusion_matrix)

Out:

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., 0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-159-e1640f0e3b13> in <module>()
     45 print(yhat)
     46 
---> 47 confusion_matrix = pd.DataFrame(confusion_matrix(y, yhat), columns=["Predicted False", "Predicted True"], index=["Actual False", "Actual True"])
     48 display(confusion_matrix)
     49 

TypeError: 'DataFrame' object is not callable

Not sure what's going on here...


Solution

  • Are you doing that in a notebook? If so, maybe the confusion_matrix method has been shadowed by the DataFrame when you called it the first time. Try to change the variable name and restart the kernel.