Source code for immuneML.ml_metrics.ml_metrics

import numpy as np
from sklearn import metrics


[docs] def f1_score_weighted(true_y, predicted_y): return metrics.f1_score(true_y, predicted_y, average="weighted")
[docs] def f1_score_micro(true_y, predicted_y): return metrics.f1_score(true_y, predicted_y, average="micro")
[docs] def f1_score_macro(true_y, predicted_y): return metrics.f1_score(true_y, predicted_y, average="macro")
[docs] def roc_auc_score(true_y, predicted_y, labels=None): predictions = np.array(predicted_y) if not isinstance(predicted_y, np.ndarray) else predicted_y true_values = np.array(true_y) if not isinstance(true_y, np.ndarray) else true_y if predictions.shape == true_values.shape: return metrics.roc_auc_score(true_values, predictions, labels=labels) elif len(predictions.shape) == 2 and predictions.shape[1] == 2: return metrics.roc_auc_score(true_values, predictions[:, 1], labels=labels) else: return -1