0

I am working on image classification of breast cancer using DenseNet121. I used confusion_matrix and classification_report and accuracy_score but it didn't calculate the requirement metrics as I want to calculate ROC and sensitivity. I tried in many ways but it didn't work.

This is the code:

in_model = tf.keras.applications.DenseNet121(input_shape=(224,224,3),
                                               include_top=False,
                                               weights='imagenet',classes = 2)
in_model.trainable = False
inputs = tf.keras.Input(shape=(224,224,3))
x = in_model(inputs)
flat = Flatten()(x)
dense_1 = Dense(4096,activation = 'relu')(flat)
dense_2 = Dense(4096,activation = 'relu')(dense_1)
prediction = Dense(2,activation = 'softmax')(dense_2)
in_pred = Model(inputs = inputs,outputs = prediction)
in_pred.evaluate(test_data,test_labels)
test_ = in_pred.predict(test_text)
Y_pred= np.argmax(test_labels, axis=1)
vgg19 = np.argmax(test_, axis=1)

I used confusion_matrix and classification_report and accuracy_score using the below code but I don't know how to calculate ROC and Sensitivity.

Any help would be appreciated.

print(confusion_matrix(Y_pred,vgg19))
print(classification_report(Y_pred,vgg19))
print(accuracy_score(Y_pred,vgg19))
Eda
  • 565
  • 1
  • 7
  • 18
  • what is the error yoou are getting post the stacj trace – darth baba Mar 01 '23 at 18:17
  • Instead or repeating verbatim what you have already written in your post (including the unhelpful "*any help would be appreciated*") when asked for clarifications, it would be arguably better to clarify that you do *not* get any error, it's just that the posted code does not give you the result you want. Anyway, for specificity & sensitivity (starting from a confusion matrix) see own answer here: https://stackoverflow.com/questions/48100173/how-to-get-precision-recall-and-f-measure-from-confusion-matrix-in-python/48101802#48101802 – desertnaut Mar 02 '23 at 01:15
  • These terms are available as metrics in [tf.keras.metrics](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/AUC). You can [define these metrics](https://www.tensorflow.org/tutorials/structured_data/imbalanced_data#define_the_model_and_metrics) at model.compile() to calculate. –  Mar 24 '23 at 15:33

0 Answers0