Your question is Precision and Recall on Imbalanced Data. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Vertafore may evaluate classification models used with products such as AMS360, where positive cases can be much less common than negative cases. Given actual and predicted binary labels, calculate precision and recall without using machine learning libraries.
Implement precision_recall(y_true, y_pred), where both inputs are non-empty lists of integers containing only 0 and 1, and have equal length. Label 1 is the positive class. Return a dictionary with two floating-point values:
precision = TP / (TP + FP), or 0.0 when the model predicts no positive cases.recall = TP / (TP + FN), or 0.0 when the input contains no actual positive cases.Count each label pair once. Do not round the results.
def precision_recall(y_true, y_pred):