def test_threshold_found_3(mocker): global y_true, y_pred [entry, _] = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), customer_target_precision=0.875, target_recall=0) assert abs(entry['Contents']['threshold'] - 0.8) < 10 ** -2
def test_threshold_found_2(mocker): global y_true, y_pred entry = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), target_precision=0.6, target_recall=0) assert abs(entry['Contents']['threshold'] - 0) < 10 ** -2
def test_predictions_are_correct_and_all_equals_one_prob(mocker): y_true = ['class1'] * 7 + ['class2'] * 7 y_pred = [{'class1': 0.95}] * 7 + [{'class2': 0.95}] * 7 [entry, _] = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), customer_target_precision=0.6, target_recall=0) assert abs(entry['Contents']['threshold'] - 0.95) < 10 ** -2
def test_all_wrong_predictions_2(mocker): y_true = ['class1'] * 7 + ['class2'] * 7 y_pred = [{'class2': 0.5}] * 7 + [{'class1': 0.5}] * 7 [entry, _] = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), customer_target_precision=0, target_recall=0) assert entry['Contents']['threshold'] >= 0.5
def test_plabook_test_simulation(mocker): y_pred = [{"spam": 0.9987042546272278}, {"ham": 0.9987037777900696}] y_true = ["spam", "ham"] [entry, _] = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), customer_target_precision=0.7, target_recall=0) assert abs(entry['Contents']['threshold'] - 0.9987037777900696) < 10 ** -2
def test_no_existing_threshold(mocker): [entry, _] = find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), customer_target_precision=0.9, target_recall=0) assert abs(entry['Contents']['threshold'] - 0.8) < 10 ** -2
def test_no_existing_threshold(mocker): with pytest.raises(SystemExit): find_threshold(y_pred_str=json.dumps(y_pred), y_true_str=json.dumps(y_true), target_precision=1, target_recall=0)