Skip to content

Instantly share code, notes, and snippets.

@chidindu-ogbonna
Last active March 5, 2020 02:26
Show Gist options
  • Save chidindu-ogbonna/7aec353158e6dcfa2be177e80d28f33c to your computer and use it in GitHub Desktop.
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-" )
# Second stuff comes here
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