-1

I trained Random Forest Classifier in sklearn to predict multi-class classification problem.

My dataset has four class labels. But my code create 2x2 confusion matrix

y_predict = rf.predict(X_test)
conf_mat = sklearn.metrics.confusion_matrix(y_test, y_predict)
print(conf_mat)

Output:

[[0,   0]

 [394, 39]]

How can I get 4x4 confusion matrix to analyze TP, TN, FP, FN.

franiis
  • 1,378
  • 1
  • 18
  • 33
ZEESHAN
  • 191
  • 2
  • 15

1 Answers1

0

From the documentation at
http://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html

y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])

Result :

array([[2, 0, 0], 
       [0, 0, 1], 
       [1, 0, 2]])