I am trying to understand how to make a confusion matrix and ROC curve for my multilabel classification problem. I am building a neural network. Here are my classes:
mlb = MultiLabelBinarizer()
ohe = mlb.fit_transform(as_list)
# loop over each of the possible class labels and show them
for (i, label) in enumerate(mlb.classes_):
print("{}. {}".format(i + 1, label))
[INFO] class labels:
1. class1
2. class2
3. class3
4. class4
5. class5
6. class6
My labels are transformed:
ohe
array([[0, 1, 0, 0, 1, 1],
[0, 1, 1, 1, 1, 0],
[1, 1, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1],...]]
Training data:
array([[[[ 1.93965047e+04, 8.49532852e-01],
[ 1.93965047e+04, 8.49463479e-01],
[ 1.93965047e+04, 8.49474722e-01],
...,
Model:
model.compile(loss="binary_crossentropy", optimizer=opt,metrics=["accuracy"])
H = model.fit(trainX, trainY, batch_size=BS,
validation_data=(testX, testY),
epochs=EPOCHS, verbose=1)
I am able to get precentages but I am a bit clueless in how to calculate confusion matrix or ROC curve, or get classification report.. here are the precentages:
proba = model.predict(testX)
idxs = np.argsort(proba)[::-1][:2]
for i in proba:
print ('\n')
for (label, p) in zip(mlb.classes_, i):
print("{}: {:.2f}%".format(label, p * 100))
class1: 69.41%
class2: 76.41%
class3: 58.02%
class4: 63.97%
class5: 48.91%
class6: 58.28%
class1: 69.37%
class2: 76.42%
class3: 58.01%
class4: 63.92%
class5: 48.88%
class6: 58.26%
If anyone has some tips on how to do it or an example I would really appreciate it! Thank you in advance!