Binary classification stats
BinaryClassificationStats
dataclass
A data class representing counts of different categories in binary classification.
Attributes:
Name | Type | Description |
---|---|---|
true_positives |
int
|
The count of true positive instances - i.e., the number of known entities ranked 1 in the results. |
true_negatives |
int
|
The count of true negative instances - i.e., the number of non-relevant entities ranked at a position other than 1 in the results. |
false_positives |
int
|
The count of false positive instances - i.e., the number of non-relevant entities ranked at position 1 in the results. |
false_negatives |
int
|
The count of false negative instances - i.e., the number of known entities ranked at a position other than 1 in the results. |
Source code in src/pheval/analyse/binary_classification_stats.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
accuracy()
Calculate Accuracy.
Accuracy measures the proportion of correctly predicted instances out of all instances.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The Accuracy of the model, calculated as the sum of true positives and true negatives divided by |
float
|
the sum of true positives, false positives, true negatives, and false negatives. |
|
float
|
Returns 0.0 if the total sum of counts is zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
add_classification(pheval_results, relevant_ranks)
Update binary classification metrics for known and unknown entities based on their ranks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pheval_results |
Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]
|
(Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]): The list of all pheval results. |
required |
relevant_ranks |
List[int]
|
A list of the ranks associated with the known entities. |
required |
Source code in src/pheval/analyse/binary_classification_stats.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
add_classification_for_known_entities(relevant_ranks)
Update binary classification metrics for known entities based on their ranking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relevant_ranks |
List[int]
|
A list of the ranks associated with the known entities. |
required |
Source code in src/pheval/analyse/binary_classification_stats.py
63 64 65 66 67 68 69 70 71 72 73 74 |
|
add_classification_for_other_entities(ranks)
Update binary classification metrics for other entities based on their ranking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ranks |
List[int]
|
A list of the ranks for all other entities. |
required |
Source code in src/pheval/analyse/binary_classification_stats.py
76 77 78 79 80 81 82 83 84 85 86 87 |
|
add_labels_and_scores(pheval_results, relevant_ranks)
Adds scores and labels from the PhEval results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relevant_ranks |
List[int]
|
A list of the ranks associated with the known entities. |
required |
Source code in src/pheval/analyse/binary_classification_stats.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 |
|
f1_score()
Calculate F1 Score.
F1 Score is the harmonic mean of precision and recall, providing a balance between false positives and false negatives.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The F1 Score of the model, calculated as 2 * TP / (2 * TP + FP + FN). |
float
|
Returns 0.0 if the denominator is zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
false_discovery_rate()
Calculate False Discovery Rate (FDR).
FDR measures the proportion of instances predicted as positive that are actually negative.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The False Discovery Rate of the model, calculated as false positives divided by the sum of |
float
|
false positives and true positives. Returns 0.0 if both false positives and true positives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
false_negative_rate()
Calculate False Negative Rate (FNR).
FNR measures the proportion of instances that are actually positive but predicted as negative.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The False Negative Rate of the model, calculated as false negatives divided by the sum of |
float
|
false negatives and true positives. Returns 0.0 if both false negatives and true positives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
false_positive_rate()
Calculate False Positive Rate (FPR).
FPR measures the proportion of instances predicted as positive that are actually negative.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The False Positive Rate of the model, calculated as false positives divided by the sum of |
float
|
false positives and true negatives. Returns 0.0 if both false positives and true negatives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
matthews_correlation_coefficient()
Calculate Matthews Correlation Coefficient (MCC).
MCC is a measure of the quality of binary classifications, accounting for imbalances in the data.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The Matthews Correlation Coefficient of the model, calculated as |
float
|
((TP * TN) - (FP * FN)) / sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)). |
|
float
|
Returns 0.0 if the denominator is zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
negative_predictive_value()
Calculate Negative Predictive Value (NPV).
NPV measures the proportion of correctly predicted negative instances out of all instances predicted negative.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The Negative Predictive Value of the model, calculated as true negatives divided by the sum of |
float
|
true negatives and false negatives. Returns 0.0 if both true negatives and false negatives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
precision()
Calculate precision.
Precision measures the proportion of correctly predicted positive instances out of all instances predicted as positive.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The precision of the model, calculated as true positives divided by the sum of true positives |
float
|
and false positives. Returns 0.0 if both true positives and false positives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
remove_relevant_ranks(pheval_results, relevant_ranks)
staticmethod
Remove the relevant entity ranks from all result ranks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pheval_results |
Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]
|
(Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]): The list of all pheval results. |
required |
relevant_ranks |
List[int]
|
A list of the ranks associated with the known entities. |
required |
Returns:
Type | Description |
---|---|
List[int]
|
List[int]: A list of the ranks with the relevant entity ranks removed. |
Source code in src/pheval/analyse/binary_classification_stats.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
sensitivity()
Calculate sensitivity.
Sensitivity measures the proportion of actual positive instances correctly identified by the model.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The sensitivity of the model, calculated as true positives divided by the sum of true positives |
float
|
and false negatives. Returns 0 if both true positives and false negatives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
specificity()
Calculate specificity.
Specificity measures the proportion of actual negative instances correctly identified by the model.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The specificity of the model, calculated as true negatives divided by the sum of true negatives |
float
|
and false positives. Returns 0.0 if both true negatives and false positives are zero. |
Source code in src/pheval/analyse/binary_classification_stats.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|