Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2, normalize=False)
assert isequal(metric_dict, {"accuracy@2": 6})
"""Unit test of accuracy_scorer."""
caplog.set_level(logging.INFO)
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2, normalize=False)
def test_accuracy(caplog):
"""Unit test of accuracy_scorer."""
caplog.set_level(logging.INFO)
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2, normalize=False)
assert isequal(metric_dict, {"accuracy@2": 6})
def test_accuracy(caplog):
"""Unit test of accuracy_scorer."""
caplog.set_level(logging.INFO)
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2, normalize=False)
assert isequal(metric_dict, {"accuracy@2": 6})
def test_accuracy(caplog):
"""Unit test of accuracy_scorer."""
caplog.set_level(logging.INFO)
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, PROBS, None)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(GOLDS, None, PREDS, normalize=False)
assert isequal(metric_dict, {"accuracy": 4})
metric_dict = accuracy_scorer(GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, None, PREDS)
assert isequal(metric_dict, {"accuracy": 0.6666666666666666})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2)
assert isequal(metric_dict, {"accuracy@2": 1.0})
metric_dict = accuracy_scorer(PROB_GOLDS, PROBS, PREDS, topk=2, normalize=False)
assert isequal(metric_dict, {"accuracy@2": 6})
pos_label: int = 1,
) -> Dict[str, float]:
"""Average of accuracy and f1 score.
Args:
golds: Ground truth values.
probs: Predicted probabilities.
preds: Predicted values.
uids: Unique ids, defaults to None.
pos_label: The positive class label, defaults to 1.
Returns:
Average of accuracy and f1.
"""
metrics = dict()
accuracy = accuracy_scorer(golds, probs, preds, uids)
f1 = f1_scorer(golds, probs, preds, uids, pos_label=pos_label)
metrics["accuracy_f1"] = np.mean([accuracy["accuracy"], f1["f1"]])
return metrics
from emmental.metrics.accuracy import accuracy_scorer
from emmental.metrics.accuracy_f1 import accuracy_f1_scorer
from emmental.metrics.fbeta import f1_scorer, fbeta_scorer
from emmental.metrics.matthews_correlation import (
matthews_correlation_coefficient_scorer,
)
from emmental.metrics.mean_squared_error import mean_squared_error_scorer
from emmental.metrics.pearson_correlation import pearson_correlation_scorer
from emmental.metrics.pearson_spearman import pearson_spearman_scorer
from emmental.metrics.precision import precision_scorer
from emmental.metrics.recall import recall_scorer
from emmental.metrics.roc_auc import roc_auc_scorer
from emmental.metrics.spearman_correlation import spearman_correlation_scorer
METRICS = {
"accuracy": accuracy_scorer,
"accuracy_f1": accuracy_f1_scorer,
"precision": precision_scorer,
"recall": recall_scorer,
"f1": f1_scorer,
"fbeta": fbeta_scorer,
"matthews_correlation": matthews_correlation_coefficient_scorer,
"mean_squared_error": mean_squared_error_scorer,
"pearson_correlation": pearson_correlation_scorer,
"pearson_spearman": pearson_spearman_scorer,
"spearman_correlation": spearman_correlation_scorer,
"roc_auc": roc_auc_scorer,
}
__all__ = [
"accuracy_scorer",
"accuracy_f1_scorer",