Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing True False confusion

Tags:

python

I have some confusion over testing values that are assigned False, True

To check for True value, we can simply just

a = True
if (a):

how about False?

a=False
if (a) <--- or should it be if (a==False), or if not a ?
like image 614
dorothy Avatar asked Sep 11 '13 15:09

dorothy


People also ask

What is a confusion matrix in machine learning?

A confusion matrix, in predictive analytics, shows the rate of false positives, false negatives, true positives and true negatives for a test or predictor. In machine learning, a confusion matrix can be used to show how well a classification model performs on a set of test data. Correctly assigned values appear in their relative diagonal box:

What is the percentage of accuracy of the confusion matrix?

The confusion matrix is as follows. Figure 7: Confusion matrix for healthy vs unhealthy people classification task. Accuracy in this case will be (90 + 0)/ (100) = 0.9 and in percentage the accuracy is 90 %. Is there anything fishy?

How to compare true and false values in Python?

python - Comparing True False confusion - Stack Overflow I have some confusion over testing values that are assigned False, True To check for True value, we can simply just a = True if (a): how about False? a=False if (a) &lt;--- or should it be if (a==

What is the difference between true positive and false negative?

Figure 1: True Positive. 2. A person who is actually not pregnant (negative) and classified as not pregnant (negative). This is called TRUE NEGATIVE (TN). Figure 2: True Negative. 3. A person who is actually not pregnant (negative) and classified as pregnant (positive). This is called FALSE POSITIVE (FP). Figure 3: False Positive. 4.


3 Answers

From the Python Style Guide:

For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

Yes: if not seq:
     if seq:

No: if len(seq)
    if not len(seq)

[..]

Don't compare boolean values to True or False using ==.

Yes: if greeting:
No: if greeting == True:
Worse: if greeting is True:
like image 130
Burhan Khalid Avatar answered Oct 08 '22 17:10

Burhan Khalid


use not:

if not a:
    ....
    # If a is the empty value like '', [], (), {}, or 0, 0.0, ..., False
    # control flow also reach here.

or is False:

if a is False:
    ....
like image 39
falsetru Avatar answered Oct 08 '22 18:10

falsetru


To check for if a value is true:

if a:
    pass

To check if a value is not true:

if not a:
    pass

However, not a: is True (and true) for values other than False, eg. None, 0, and empty containers.

If you want to check if a value is True or False (although you generally don't) try:

if a is True:
    pass

or

if a is False:
    pass

Edit: for checking if a value is True or False it seems you should use if isinstance(a, bool) and a, and if isinstance(a, bool) and not a

like image 1
rlms Avatar answered Oct 08 '22 16:10

rlms