I want to find the accuracy of prediction using python.
List1=[('positive rapid hiv test', 'PRESENT'),
('liver function tests', 'PRESENT'),
('low albumin', 'PRESENT'),
('chest x - ray', 'POSSIBLE'),
('diffuse nodular opacities bilaterally', 'PRESENT'),
('an electrocardiogram', 'PRESENT'),
('sinus rhythm', 'PRESENT'),
('hiv', 'PRESENT')]
List2=[('positive rapid hiv test', 'PRESENT'),
('liver function tests', 'PRESENT'),
('low albumin', 'PRESENT'),
('chest x - ray', 'PRESENT'),
('diffuse nodular opacities bilaterally', 'PRESENT'),
('an electrocardiogram', 'PRESENT'),
('sinus rhythm', 'POSSIBLE'),
('hiv', 'ABSENT')]
Number of tuples may vary, in both list1 and list2
CodePudding user response:
If you assume PRESENT
as 1
and ABSENT
as 0
, you can create a list of predicted and true values with 0 and 1 and use classification_report
from sklearn
library.
from sklearn.metrics import classification_report
list1 = [1,1,1,1,1,1,1,1]
lsit2 = [1,1,1,1,1,1,1,0]
print(classification_report(y_true=lsit2, y_pred=list1))