5

I seem to be getting an error when calling confusion_matrix, please see below. How can I get this to work?

from sklearn.metrics import confusion_matrix
confusion_matrix = confusion_matrix(normalisedArr_y5,predicted5)
3
  • The DataTypes are as follows predicted5 Int64 (244,) array([1,1,1,...,2,2,2]) normalisedArr_y5 Int64 (244,) array([1,1,1,...,5,5,5]) Commented Mar 27, 2017 at 12:21
  • 3
    You should post the full stack trace Commented Mar 27, 2017 at 13:33
  • 4
    You are redefining confusion_matrix - use a different variable name. Commented Mar 27, 2017 at 17:37

3 Answers 3

2

1 Be sure that both values are np arrays or lists as specified by @Roelant
2 do not assign to your variable's name the same name as the function name

from sklearn.metrics import confusion_matrix
cfm = confusion_matrix(normalisedArr_y5,predicted5)
print(cfm)
Sign up to request clarification or add additional context in comments.

Comments

1

Both normalisedArr_y5 and predicted5 should be np.arrays or lists. Apparently one or both are not. You could try:

confusion_matrix = confusion_matrix(normalisedArr_y5.tolist(),predicted5.tolist())

Comments

0

In my case, I was defining

normalisedArr_x5 = df.iloc[:,:-1]

and

normalisedArr_y5 = data.iloc[:,-1:]

and this Error was coming.

So just check if both the dataframe variables are the same (here df) and perform the steps again @Garch2017

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.