How can I calculate the accuracy of each predicted value one by one in Python?

Viewed 399

I am currently working on a disease prediction machine learning model using Random Forest Classifier. I enter the symptoms, and then the program should predict the disease. There is no problem with prediction, but I want to calculate the accuracy of each predicted value "one by one". For example, the program predicted "Tuberculosis" as a disease. Then, I want to calculate the accuracy rate of this prediction. (Only the accuracy of the predicted value Tuberculosis.) How can I calculate the accuracy of each predicted value one by one?

1 Answers

In case of Random Forest this might be difficult. Random Forest classifier divides the feature space into regions and then assigns the value based on where a point is located. Obviously, the point being of 0-size can't be 60% in one area and 40% in the other area, therefore, the predicted label in case of a disease can only be "tuberculosis" or "no tuberculosis".

enter image description here

On the other hand, other methods allow for more options in this regard. For example, binary neural network classifier will have two output neurons (one for each class) and for each of the predictions the label will come from neuron that has a higher weight associated with it. But you can actually report weights of output neurons and the confidence of the prediction based on those. In this image there are 3 output classes but you get the idea - here you can say that there's a 60% chance that the record belongs to second class, 30% that is belongs to the third class and 10% that it belongs to the first class:

enter image description here

Finally, one other method is logistic regression where the prediction is the value of a logit, which essentially is the probability of the point belonging to the positive class which in your case will be the probability of a person having tuberculosis.

Related