To install metrify, simply run pip install metrify
.
The purpose of metrify is to add a few simple functionalities to scikit-learn. In particular, the informedness, markedness and
The main issue with precision, recall and F-score is that none of them makes use of True Negatives (TNs) to assess the model performance. Whilst we are usually interested in the positive class, ensuring to get the negative class right is a sort of sanity check for our model. For example, if we had a highly imbalanced dataset (towards the negative class) we definitely want the negative class to be predicted with high confidence. Our job should be, in theory, to ensure that the model performs well on the minority, i.e. the positive, class.
In practice, suppose we have a model whose predictions yield, in terms of False Positives, False Negatives and True Positives
To make sure our metrics do take into consideration this case, we need an alternative to precision and recall. One option is to use markedness
Currently metrify only works for a binary classification problem. A sample usage is the following
from metrify import informedness, markedness, phi_beta
# Define a random numpy array of 100 true values
t = np.random.randint(0, 2, 100)
# Define a random numpy array of 100 predicted values
p = np.random.randint(0, 2, 100)
# Compute the metrics
i = informedness(t, p)
m = markedness(t, p)
phi_2 = phi_beta(t, p, beta=2)
Given a set of binary ground truths and predictions as probabilities, find the best
from metrify import find_best_fbeta
# Define a random numpy array of 100 true values
t = np.random.randint(0, 2, 100)
# Define a random numpy array of 100 predicted probabilities
p = np.random.rand(100)
# Get the best F0.5 and the corresponding threshold
f_beta, threshold = find_best_fbeta(t, p, beta=0.5)
To create and deploy a new version, the recipe is:
- Modify the code as suited;
- Update the version and possibly the dependencies in
pyproject.toml
; - Build the package
python -m build
; - Upload the package
python -m twine upload dist/metrify-<VERSION>*