1
$\begingroup$

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()
misclassified
import seaborn as sn

# plt.figure()
sn.heatmap(cm, annot=True)
plt.xlabel("Predicted")
plt.ylabel("Actual")

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

$\endgroup$
2
  • $\begingroup$ Did you check the number of classes in y_test? $\endgroup$ May 23 '20 at 14:55
  • $\begingroup$ How can I check that? $\endgroup$ May 23 '20 at 15:14
1
$\begingroup$

Please check how many classes y_test has.

if Y is array-

np.unique(y_test)

If y is DataFrame column,

y_test.unique()

Looks like y_test has only 2 classes.

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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