Last active
March 5, 2020 02:26
-
-
Save chidindu-ogbonna/7aec353158e6dcfa2be177e80d28f33c to your computer and use it in GitHub Desktop.
Data Science & Machine Learning Snippets - Useful snippets for simple things (All files start with "ds-" )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Second stuff comes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# Calculate TP, TN, FP, FN | |
test_labels = np.asarray([]) # Array contains true labels from the test dataset | |
test_preds = np.asarray([]) # Array contains predicted labels generated by the model | |
tp = np.logical_and(test_labels, test_preds).sum() | |
fp = np.logical_and(1-test_labels, test_preds).sum() | |
fn = np.logical_and(test_labels, 1-test_preds).sum() | |
tn = np.logical_and(1-test_labels, 1-test_preds).sum() | |
precision = tp / (fp + tp) | |
recall = tp / (fn + tp) | |
accuracy = (tp + tn) / (fp + fn + tp + tn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment