An implementation of Precision@k compatible with Scikit-learn.
✓ Published0🌍 Public
BBrideau
Last edited Dec 12, 2021
Created on Dec 12, 2021
This example demonstrates a custom implementation of the Precision@k metric that integrates directly with Scikit-learn's array utilities. It shows how to compute precision for the top *k* predictions, assuming a binary classification task. The function uses `column_or_1d` to flatten input arrays and `type_of_target` to validate the binary format. It sorts the true labels by descending prediction scores using `np.argsort`, then calculates the proportion of true positives among the top *k* entries. The code relies on NumPy for sorting and summing, and it returns a scalar float representing the precision value.
AI-generated description