Python: count TP, FP, FN Ð¸ TN
<p>I have dataframe with true class and class, that were predicted by some algorithm.</p>

<pre><code>     true  pred
0       1     0
1       1     1
2       1     1
3       0     0
4       1     1
</code></pre>

<p>I try to use</p>

<pre><code>def classification(y_actual, y_hat):
    TP = 0
    FP = 0
    TN = 0
    FN = 0

    for i in range(len(y_hat)): 
        if y_actual[i] == y_hat[i] == 1:
           TP += 1
    for i in range(len(y_hat)): 
        if y_actual[i] == 1 and y_actual != y_hat[i]:
           FP += 1
    for i in range(len(y_hat)): 
        if y_actual[i] == y_hat[i] == 0:
           TN += 1
    for i in range(len(y_hat)): 
        if y_actual[i] == 0 and y_actual != y_hat[i]:
           FN += 1

    return(TP, FP, TN, FN)
</code></pre>

<p>but it return me</p>

<blockquote>
  <p>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  How can I fix that or maybe there are the better decision?</p>
</blockquote>

<p>I use <code>confusion_matrix</code> from <code>sklearn.metrics</code> and it return me need matrix.</p>

python machine-learning scikit-learn