Skip to content

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
@dataclass
class BinaryClassificationStats:
    """
    A data class representing counts of different categories in binary classification.

    Attributes:
        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.
    """

    true_positives: int = 0
    true_negatives: int = 0
    false_positives: int = 0
    false_negatives: int = 0
    labels: List = field(default_factory=list)
    scores: List = field(default_factory=list)

    @staticmethod
    def remove_relevant_ranks(
        pheval_results: Union[
            List[RankedPhEvalGeneResult],
            List[RankedPhEvalVariantResult],
            List[RankedPhEvalDiseaseResult],
        ],
        relevant_ranks: List[int],
    ) -> List[int]:
        """
        Remove the relevant entity ranks from all result ranks
        Args:
            pheval_results:
                (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]):
                    The list of all pheval results.
            relevant_ranks (List[int]): A list of the ranks associated with the known entities.

        Returns:
            List[int]: A list of the ranks with the relevant entity ranks removed.

        """
        all_result_ranks = [pheval_result.rank for pheval_result in pheval_results]
        for rank in relevant_ranks:
            if rank in all_result_ranks:
                all_result_ranks.remove(rank)
                continue
        return all_result_ranks

    def add_classification_for_known_entities(self, relevant_ranks: List[int]) -> None:
        """
        Update binary classification metrics for known entities based on their ranking.

        Args:
            relevant_ranks (List[int]): A list of the ranks associated with the known entities.
        """
        for rank in relevant_ranks:
            if rank == 1:
                self.true_positives += 1
            elif rank != 1:
                self.false_negatives += 1

    def add_classification_for_other_entities(self, ranks: List[int]) -> None:
        """
        Update binary classification metrics for other entities based on their ranking.

        Args:
            ranks (List[int]): A list of the ranks for all other entities.
        """
        for rank in ranks:
            if rank == 1:
                self.false_positives += 1
            elif rank != 1:
                self.true_negatives += 1

    def add_labels_and_scores(
        self,
        pheval_results: Union[
            List[RankedPhEvalGeneResult],
            List[RankedPhEvalVariantResult],
            List[RankedPhEvalDiseaseResult],
        ],
        relevant_ranks: List[int],
    ):
        """
        Adds scores and labels from the PhEval results.

        Args:
            pheval_results (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult],
                                  List[RankedPhEvalDiseaseResult]]):
                List of all PhEval results
            relevant_ranks (List[int]): A list of the ranks associated with the known entities.
        """
        relevant_ranks_copy = relevant_ranks.copy()
        for result in pheval_results:
            self.scores.append(result.score)
            label = 1 if result.rank in relevant_ranks_copy else 0
            self.labels.append(label)
            relevant_ranks_copy.remove(result.rank) if label == 1 else None

    def add_classification(
        self,
        pheval_results: Union[
            List[RankedPhEvalGeneResult],
            List[RankedPhEvalVariantResult],
            List[RankedPhEvalDiseaseResult],
        ],
        relevant_ranks: List[int],
    ) -> None:
        """
        Update binary classification metrics for known and unknown entities based on their ranks.
        Args:
            pheval_results:
                (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]):
                    The list of all pheval results.
            relevant_ranks (List[int]): A list of the ranks associated with the known entities.
        """
        self.add_classification_for_known_entities(relevant_ranks)
        self.add_classification_for_other_entities(
            self.remove_relevant_ranks(pheval_results, relevant_ranks)
        )
        self.add_labels_and_scores(pheval_results, relevant_ranks)

    def sensitivity(self) -> float:
        """
        Calculate sensitivity.

        Sensitivity measures the proportion of actual positive instances correctly identified by the model.

        Returns:
            float: The sensitivity of the model, calculated as true positives divided by the sum of true positives
            and false negatives. Returns 0 if both true positives and false negatives are zero.
        """
        return (
            self.true_positives / (self.true_positives + self.false_negatives)
            if (self.true_positives + self.false_negatives) > 0
            else 0.0
        )

    def specificity(self) -> float:
        """
        Calculate specificity.

        Specificity measures the proportion of actual negative instances correctly identified by the model.

        Returns:
            float: The specificity of the model, calculated as true negatives divided by the sum of true negatives
            and false positives. Returns 0.0 if both true negatives and false positives are zero.
        """
        return (
            self.true_negatives / (self.true_negatives + self.false_positives)
            if (self.true_negatives + self.false_positives) > 0
            else 0.0
        )

    def precision(self) -> float:
        """
        Calculate precision.

        Precision measures the proportion of correctly predicted positive instances out of all instances
        predicted as positive.

        Returns:
            float: The precision of the model, calculated as true positives divided by the sum of true positives
            and false positives. Returns 0.0 if both true positives and false positives are zero.
        """
        return (
            self.true_positives / (self.true_positives + self.false_positives)
            if (self.true_positives + self.false_positives) > 0
            else 0.0
        )

    def negative_predictive_value(self) -> float:
        """
        Calculate Negative Predictive Value (NPV).

        NPV measures the proportion of correctly predicted negative instances out of all instances predicted negative.

        Returns:
            float: The Negative Predictive Value of the model, calculated as true negatives divided by the sum of
            true negatives and false negatives. Returns 0.0 if both true negatives and false negatives are zero.
        """
        return (
            self.true_negatives / (self.true_negatives + self.false_negatives)
            if (self.true_negatives + self.false_negatives) > 0
            else 0.0
        )

    def false_positive_rate(self) -> float:
        """
        Calculate False Positive Rate (FPR).

        FPR measures the proportion of instances predicted as positive that are actually negative.

        Returns:
            float: The False Positive Rate of the model, calculated as false positives divided by the sum of
            false positives and true negatives. Returns 0.0 if both false positives and true negatives are zero.
        """
        return (
            self.false_positives / (self.false_positives + self.true_negatives)
            if (self.false_positives + self.true_negatives) > 0
            else 0.0
        )

    def false_discovery_rate(self) -> float:
        """
        Calculate False Discovery Rate (FDR).

        FDR measures the proportion of instances predicted as positive that are actually negative.

        Returns:
            float: The False Discovery Rate of the model, calculated as false positives divided by the sum of
            false positives and true positives. Returns 0.0 if both false positives and true positives are zero.
        """
        return (
            self.false_positives / (self.false_positives + self.true_positives)
            if (self.false_positives + self.true_positives) > 0
            else 0.0
        )

    def false_negative_rate(self) -> float:
        """
        Calculate False Negative Rate (FNR).

        FNR measures the proportion of instances that are actually positive but predicted as negative.

        Returns:
            float: The False Negative Rate of the model, calculated as false negatives divided by the sum of
            false negatives and true positives. Returns 0.0 if both false negatives and true positives are zero.
        """
        return (
            self.false_negatives / (self.false_negatives + self.true_positives)
            if (self.false_negatives + self.true_positives) > 0
            else 0.0
        )

    def accuracy(self) -> float:
        """
        Calculate Accuracy.

        Accuracy measures the proportion of correctly predicted instances out of all instances.

        Returns:
            float: The Accuracy of the model, calculated as the sum of true positives and true negatives divided by
            the sum of true positives, false positives, true negatives, and false negatives.
            Returns 0.0 if the total sum of counts is zero.
        """
        return (
            (self.true_positives + self.true_negatives)
            / (
                self.true_positives
                + self.false_positives
                + self.true_negatives
                + self.false_negatives
            )
            if (
                self.true_positives
                + self.false_negatives
                + self.true_negatives
                + self.false_negatives
            )
            > 0
            else 0.0
        )

    def f1_score(self) -> float:
        """
        Calculate F1 Score.

        F1 Score is the harmonic mean of precision and recall, providing a balance between false positives
        and false negatives.

        Returns:
            float: The F1 Score of the model, calculated as 2 * TP / (2 * TP + FP + FN).
            Returns 0.0 if the denominator is zero.
        """
        return (
            (2 * self.true_positives)
            / ((2 * self.true_positives) + self.false_positives + self.false_negatives)
            if (self.true_positives + self.false_positives + self.false_negatives) > 0
            else 0.0
        )

    def matthews_correlation_coefficient(self) -> float:
        """
        Calculate Matthews Correlation Coefficient (MCC).

        MCC is a measure of the quality of binary classifications, accounting for imbalances in the data.

        Returns:
            float: The Matthews Correlation Coefficient of the model, calculated as
            ((TP * TN) - (FP * FN)) / sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)).
            Returns 0.0 if the denominator is zero.
        """
        return (
            (
                (self.true_positives * self.true_negatives)
                - (self.false_positives * self.false_negatives)
            )
            / (
                sqrt(
                    (self.true_positives + self.false_positives)
                    * (self.true_positives + self.false_negatives)
                    * (self.true_negatives + self.false_positives)
                    * (self.true_negatives + self.false_negatives)
                )
            )
            if (
                self.true_positives
                + self.false_negatives
                + self.true_negatives
                + self.false_negatives
            )
            > 0
            else 0.0
        )

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
def accuracy(self) -> float:
    """
    Calculate Accuracy.

    Accuracy measures the proportion of correctly predicted instances out of all instances.

    Returns:
        float: The Accuracy of the model, calculated as the sum of true positives and true negatives divided by
        the sum of true positives, false positives, true negatives, and false negatives.
        Returns 0.0 if the total sum of counts is zero.
    """
    return (
        (self.true_positives + self.true_negatives)
        / (
            self.true_positives
            + self.false_positives
            + self.true_negatives
            + self.false_negatives
        )
        if (
            self.true_positives
            + self.false_negatives
            + self.true_negatives
            + self.false_negatives
        )
        > 0
        else 0.0
    )

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
def add_classification(
    self,
    pheval_results: Union[
        List[RankedPhEvalGeneResult],
        List[RankedPhEvalVariantResult],
        List[RankedPhEvalDiseaseResult],
    ],
    relevant_ranks: List[int],
) -> None:
    """
    Update binary classification metrics for known and unknown entities based on their ranks.
    Args:
        pheval_results:
            (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]):
                The list of all pheval results.
        relevant_ranks (List[int]): A list of the ranks associated with the known entities.
    """
    self.add_classification_for_known_entities(relevant_ranks)
    self.add_classification_for_other_entities(
        self.remove_relevant_ranks(pheval_results, relevant_ranks)
    )
    self.add_labels_and_scores(pheval_results, relevant_ranks)

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
def add_classification_for_known_entities(self, relevant_ranks: List[int]) -> None:
    """
    Update binary classification metrics for known entities based on their ranking.

    Args:
        relevant_ranks (List[int]): A list of the ranks associated with the known entities.
    """
    for rank in relevant_ranks:
        if rank == 1:
            self.true_positives += 1
        elif rank != 1:
            self.false_negatives += 1

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
def add_classification_for_other_entities(self, ranks: List[int]) -> None:
    """
    Update binary classification metrics for other entities based on their ranking.

    Args:
        ranks (List[int]): A list of the ranks for all other entities.
    """
    for rank in ranks:
        if rank == 1:
            self.false_positives += 1
        elif rank != 1:
            self.true_negatives += 1

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
def add_labels_and_scores(
    self,
    pheval_results: Union[
        List[RankedPhEvalGeneResult],
        List[RankedPhEvalVariantResult],
        List[RankedPhEvalDiseaseResult],
    ],
    relevant_ranks: List[int],
):
    """
    Adds scores and labels from the PhEval results.

    Args:
        pheval_results (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult],
                              List[RankedPhEvalDiseaseResult]]):
            List of all PhEval results
        relevant_ranks (List[int]): A list of the ranks associated with the known entities.
    """
    relevant_ranks_copy = relevant_ranks.copy()
    for result in pheval_results:
        self.scores.append(result.score)
        label = 1 if result.rank in relevant_ranks_copy else 0
        self.labels.append(label)
        relevant_ranks_copy.remove(result.rank) if label == 1 else None

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
def f1_score(self) -> float:
    """
    Calculate F1 Score.

    F1 Score is the harmonic mean of precision and recall, providing a balance between false positives
    and false negatives.

    Returns:
        float: The F1 Score of the model, calculated as 2 * TP / (2 * TP + FP + FN).
        Returns 0.0 if the denominator is zero.
    """
    return (
        (2 * self.true_positives)
        / ((2 * self.true_positives) + self.false_positives + self.false_negatives)
        if (self.true_positives + self.false_positives + self.false_negatives) > 0
        else 0.0
    )

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
def false_discovery_rate(self) -> float:
    """
    Calculate False Discovery Rate (FDR).

    FDR measures the proportion of instances predicted as positive that are actually negative.

    Returns:
        float: The False Discovery Rate of the model, calculated as false positives divided by the sum of
        false positives and true positives. Returns 0.0 if both false positives and true positives are zero.
    """
    return (
        self.false_positives / (self.false_positives + self.true_positives)
        if (self.false_positives + self.true_positives) > 0
        else 0.0
    )

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
def false_negative_rate(self) -> float:
    """
    Calculate False Negative Rate (FNR).

    FNR measures the proportion of instances that are actually positive but predicted as negative.

    Returns:
        float: The False Negative Rate of the model, calculated as false negatives divided by the sum of
        false negatives and true positives. Returns 0.0 if both false negatives and true positives are zero.
    """
    return (
        self.false_negatives / (self.false_negatives + self.true_positives)
        if (self.false_negatives + self.true_positives) > 0
        else 0.0
    )

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
def false_positive_rate(self) -> float:
    """
    Calculate False Positive Rate (FPR).

    FPR measures the proportion of instances predicted as positive that are actually negative.

    Returns:
        float: The False Positive Rate of the model, calculated as false positives divided by the sum of
        false positives and true negatives. Returns 0.0 if both false positives and true negatives are zero.
    """
    return (
        self.false_positives / (self.false_positives + self.true_negatives)
        if (self.false_positives + self.true_negatives) > 0
        else 0.0
    )

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
def matthews_correlation_coefficient(self) -> float:
    """
    Calculate Matthews Correlation Coefficient (MCC).

    MCC is a measure of the quality of binary classifications, accounting for imbalances in the data.

    Returns:
        float: The Matthews Correlation Coefficient of the model, calculated as
        ((TP * TN) - (FP * FN)) / sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)).
        Returns 0.0 if the denominator is zero.
    """
    return (
        (
            (self.true_positives * self.true_negatives)
            - (self.false_positives * self.false_negatives)
        )
        / (
            sqrt(
                (self.true_positives + self.false_positives)
                * (self.true_positives + self.false_negatives)
                * (self.true_negatives + self.false_positives)
                * (self.true_negatives + self.false_negatives)
            )
        )
        if (
            self.true_positives
            + self.false_negatives
            + self.true_negatives
            + self.false_negatives
        )
        > 0
        else 0.0
    )

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
def negative_predictive_value(self) -> float:
    """
    Calculate Negative Predictive Value (NPV).

    NPV measures the proportion of correctly predicted negative instances out of all instances predicted negative.

    Returns:
        float: The Negative Predictive Value of the model, calculated as true negatives divided by the sum of
        true negatives and false negatives. Returns 0.0 if both true negatives and false negatives are zero.
    """
    return (
        self.true_negatives / (self.true_negatives + self.false_negatives)
        if (self.true_negatives + self.false_negatives) > 0
        else 0.0
    )

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
def precision(self) -> float:
    """
    Calculate precision.

    Precision measures the proportion of correctly predicted positive instances out of all instances
    predicted as positive.

    Returns:
        float: The precision of the model, calculated as true positives divided by the sum of true positives
        and false positives. Returns 0.0 if both true positives and false positives are zero.
    """
    return (
        self.true_positives / (self.true_positives + self.false_positives)
        if (self.true_positives + self.false_positives) > 0
        else 0.0
    )

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
@staticmethod
def remove_relevant_ranks(
    pheval_results: Union[
        List[RankedPhEvalGeneResult],
        List[RankedPhEvalVariantResult],
        List[RankedPhEvalDiseaseResult],
    ],
    relevant_ranks: List[int],
) -> List[int]:
    """
    Remove the relevant entity ranks from all result ranks
    Args:
        pheval_results:
            (Union[List[RankedPhEvalGeneResult], List[RankedPhEvalVariantResult], List[RankedPhEvalDiseaseResult]]):
                The list of all pheval results.
        relevant_ranks (List[int]): A list of the ranks associated with the known entities.

    Returns:
        List[int]: A list of the ranks with the relevant entity ranks removed.

    """
    all_result_ranks = [pheval_result.rank for pheval_result in pheval_results]
    for rank in relevant_ranks:
        if rank in all_result_ranks:
            all_result_ranks.remove(rank)
            continue
    return all_result_ranks

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
def sensitivity(self) -> float:
    """
    Calculate sensitivity.

    Sensitivity measures the proportion of actual positive instances correctly identified by the model.

    Returns:
        float: The sensitivity of the model, calculated as true positives divided by the sum of true positives
        and false negatives. Returns 0 if both true positives and false negatives are zero.
    """
    return (
        self.true_positives / (self.true_positives + self.false_negatives)
        if (self.true_positives + self.false_negatives) > 0
        else 0.0
    )

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
def specificity(self) -> float:
    """
    Calculate specificity.

    Specificity measures the proportion of actual negative instances correctly identified by the model.

    Returns:
        float: The specificity of the model, calculated as true negatives divided by the sum of true negatives
        and false positives. Returns 0.0 if both true negatives and false positives are zero.
    """
    return (
        self.true_negatives / (self.true_negatives + self.false_positives)
        if (self.true_negatives + self.false_positives) > 0
        else 0.0
    )