performance ¶
Utility module for computing various performance metrics for machine learning models.
Classes:
-
Performance
–Returns the value of a given metric.
Performance ¶
Returns the value of a given metric.
Parameters¶
labels (np.array) : labels predictions (np.array) : predictions metric (str) : the metric to compute
Returns:¶
value (float) : the value of the metric
TODO we can add more metrics here
TODO currently for classification metrics like precision, recall, f1score and mcc, we are using a threshold of 0.5 to convert the probabilities to binary predictions. However for models with imbalanced predictions, where the meaningful threshold is not located at 0.5, one can end up with full of 0s or 1s, and thus meaningless performance metrics.
Parameters:
-
labels
(Any
) –Ground truth labels
-
predictions
(Any
) –Model predictions
-
metric
(str
, default:'rocauc'
) –Type of metric to compute (default: "rocauc")
Methods:
-
data2array
–Convert input data to numpy array.
-
f1score
–Compute F1 score.
-
handle_multiclass
–Handle the case of multiclass classification.
-
mcc
–Compute Matthews Correlation Coefficient.
-
prauc
–Compute PR AUC score.
-
precision
–Compute precision score.
-
recall
–Compute recall score.
-
rocauc
–Compute ROC AUC score.
-
spearmanr
–Compute Spearman correlation coefficient.
Source code in src/stimulus/utils/performance.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
data2array ¶
data2array(data: Any) -> NDArray[float64]
Convert input data to numpy array.
Parameters:
-
data
(Any
) –Input data in various formats
Returns:
-
NDArray[float64]
–NDArray[np.float64]: Converted numpy array
Raises:
-
ValueError
–If input data type is not supported
Source code in src/stimulus/utils/performance.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
f1score ¶
f1score(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute F1 score.
Source code in src/stimulus/utils/performance.py
141 142 143 144 |
|
handle_multiclass ¶
handle_multiclass(
labels: NDArray[float64], predictions: NDArray[float64]
) -> tuple[NDArray[float64], NDArray[float64]]
Handle the case of multiclass classification.
Parameters:
-
labels
(NDArray[float64]
) –Labels array of shape (N,) or (N, 1)
-
predictions
(NDArray[float64]
) –Predictions array of shape (N,) or (N, C) where C is number of classes
Returns:
-
tuple[NDArray[float64], NDArray[float64]]
–tuple[NDArray[np.float64], NDArray[np.float64]]: Processed labels and predictions
Raises:
-
ValueError
–If input shapes are not compatible
Source code in src/stimulus/utils/performance.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
mcc ¶
mcc(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute Matthews Correlation Coefficient.
Source code in src/stimulus/utils/performance.py
136 137 138 139 |
|
prauc ¶
prauc(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute PR AUC score.
Source code in src/stimulus/utils/performance.py
132 133 134 |
|
precision ¶
precision(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute precision score.
Source code in src/stimulus/utils/performance.py
146 147 148 149 |
|
recall ¶
recall(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute recall score.
Source code in src/stimulus/utils/performance.py
151 152 153 154 |
|
rocauc ¶
rocauc(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute ROC AUC score.
Source code in src/stimulus/utils/performance.py
128 129 130 |
|
spearmanr ¶
spearmanr(
labels: NDArray[float64], predictions: NDArray[float64]
) -> float
Compute Spearman correlation coefficient.
Source code in src/stimulus/utils/performance.py
156 157 158 159 160 161 |
|