Gist 15ec54668ea15cb0eada554bae7d6f13
✓ Published0🌍 Public
BBrideau
Last edited Dec 12, 2021
Created on Dec 12, 2021
This example demonstrates the concept of precision at k by generating a synthetic dataset of 1,000 “potential bad actors,” each labeled as fraudulent or not, and then computing precision for the top 40 ranked predictions based on a model’s probability scores. The code uses `faker` to create fake names and emails, `numpy.random` for random labeling, and `scipy.stats.truncnorm` to simulate skewed probabilities. It defines a custom `precision_at_k` function that sorts scores in descending order and calculates the fraction of true positives among the first *k* entries, while also comparing it to scikit-learn’s `average_precision_score` for context.
AI-generated description