Skip to content

Commit

Permalink
add accuracy without draws
Browse files Browse the repository at this point in the history
  • Loading branch information
cthorrez committed Jun 7, 2024
1 parent 5499883 commit fd7cb2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "riix"
version = "0.0.2"
version = "0.0.3"
description = "vectorized implementations of online rating systems"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
8 changes: 8 additions & 0 deletions riix/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def binary_accuracy(probs: np.ndarray, outcomes: np.ndarray) -> float:
correct = outcomes[pos_mask].sum() + (1.0 - outcomes[neg_mask]).sum() + 0.5 * draw_mask.sum()
return correct / probs.shape[0]

def accuracy_without_draws(probs: np.ndarray, outcomes: np.ndarray) -> float:
"""compute binary accuracy after first filtering out rows where the label is a draw"""
draw_mask = outcomes == 0.5
probs = probs[~draw_mask]
outcomes = outcomes[~draw_mask]
return binary_accuracy(probs, outcomes)


def accuracy_with_draws(probs: np.ndarray, outcomes: np.ndarray, draw_margin=0.0) -> float:
"""computes accuracy while allowing for ties"""
Expand Down Expand Up @@ -39,6 +46,7 @@ def binary_metrics_suite(probs: np.ndarray, outcomes: np.ndarray):
"""a wrapper class for running a bunch of binary metrics"""
metrics = {
'accuracy': binary_accuracy(probs, outcomes),
'accuracy_without_draws' : accuracy_without_draws(probs, outcomes),
'log_loss': binary_log_loss(probs, outcomes),
'brier_score': brier_score(probs, outcomes),
}
Expand Down

0 comments on commit fd7cb2a

Please sign in to comment.