Computer Science, asked by harshithanaick393, 1 year ago

How to find true positive and true negative sensitivity in python?

Answers

Answered by Tigresses
0

Answer:

You can obtain True Positive (TP), True Negative (TN), False Positive (FP) and False Negative (FN) by implementing confusion matrix in Scikit-learn.

Confusion Matrix:

It is a performance measurement for machine learning classification problem where output can be two or more classes. It is a table with 4 different combinations of predicted and actual values.

True Positive:

Interpretation: You predicted positive and it’s true.

True Negative:

Interpretation: You predicted negative and it’s true.

False Positive: (Type 1 Error)

Interpretation: You predicted positive and it’s false.

False Negative: (Type 2 Error)

Interpretation: You predicted negative and it’s false.

For example:

> from sklearn.metrics import confusion_matrix

> y_true = [2, 0, 2, 2, 0, 1]

> y_pred = [0, 0, 2, 2, 0, 2]

> confusion_matrix(y_true, y_pred)

array([[2, 0, 0],

[0, 0, 1],

[1, 0, 2]])

> tn, fp, fn, tp = confusion_matrix([0, 1, 0, 1], [1, 1, 1, 0]).ravel()

> (tn, fp, fn, tp)

(0, 2, 1, 1)

Similar questions