I am trying to plot a confusion matrix using the Logistic Regression for a multi-class dataset.

But the problem is when I plot the confusion matrix it only plot a confusion matrix for binary classification.

Here is where I am plotting it.

%matplotlib inline
import matplotlib.pyplot as plt 
import pandas as pd

dataframe = pd.read_csv("WA_Fn-UseC_-HR-Employee-Attrition.csv")
from sklearn.linear_model import LogisticRegression

LRModel = LogisticRegression(C=100, max_iter=5500)

LRModel.fit(X_train, y_train)
predicted_values_ = LRModel.predict(X_test)
from sklearn.metrics import confusion_matrix 

cm = confusion_matrix(y_test, predicted_values_)

misclassified = (y_test != predicted_values_).sum()
import seaborn as sn

# plt.figure()
sn.heatmap(cm, annot=True)

And I get this matrix as shown below.

enter image description here

Can someone tell me where I am doing wrong?

This is where I am using Logistic Regression for multi-class scenario

  • $\begingroup$ Did you check the number of classes in y_test? $\endgroup$ Commented May 23, 2020 at 14:55
  • $\begingroup$ How can I check that? $\endgroup$ Commented May 23, 2020 at 15:14

1 Answer 1


Please check how many classes y_test has.

if Y is array-


If y is DataFrame column,


Looks like y_test has only 2 classes.

As far as I know HR-Employee-Attrition.csv dataset has only 2 classes.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.