Validation Toolkit
check_binary_values(pred_col, label1=0, label2=1)
¶
Check that values are binary (default: 0 or 1).
Example Use Case
Predictions can only be 0 (no disease present) or 1 (disease present).
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the values to validate.
TYPE:
|
label1
|
First acceptable binary value.
TYPE:
|
label2
|
Second acceptable binary value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
check_duplicate_keys(pred_col, verbose=False)
¶
Check for duplicate keys.
Example Use Case
There is exactly one prediction for a patient / sample / etc.
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the keys to validate
TYPE:
|
verbose
|
Include list of affected keys in error message
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
check_missing_keys(gold_col, pred_col, verbose=False)
¶
Check for missing keys.
Example Use Case
There is at least one prediction for every patient / sample / etc.
| PARAMETER | DESCRIPTION |
|---|---|
gold_col
|
Dataframe column containing the true keys
TYPE:
|
pred_col
|
Dataframe column containing the keys to validate
TYPE:
|
verbose
|
Include list of affected keys in error message
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
check_nan_values(pred_col, include_inf=False)
¶
Check for NaN values, and optionally infinite values.
Example Use Case
Predictions must not be null or None. Set include_inf=True if
infinite values should also be treated as invalid.
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the values to validate
TYPE:
|
include_inf
|
If True, infinite values are also flagged as invalid. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
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 | |
check_not_constant(pred_col)
¶
Check that a column is not constant (all values identical).
Example Use Case
A submission where every prediction is the same value (e.g. all zeros) often indicates a trivial or broken model.
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the values to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
check_unknown_keys(gold_col, pred_col, verbose=False)
¶
Check for unknown keys.
Example Use Case
There are no predictions without a corresponding groundtruth value.
| PARAMETER | DESCRIPTION |
|---|---|
gold_col
|
Dataframe column containing the true keys
TYPE:
|
pred_col
|
Dataframe column containing the keys to validate
TYPE:
|
verbose
|
Include list of affected keys in error message
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
check_valid_values(pred_col, valid_values)
¶
Check that all values belong to an allowed set.
Example Use Case
Predictions must be one of a fixed set of category labels,
e.g. {"low", "medium", "high"}.
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the values to validate
TYPE:
|
valid_values
|
Set of acceptable values
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
check_values_range(pred_col, min_val=0, max_val=1)
¶
Check that values are between min and max values, inclusive.
Example Use Case
Predictions must be a probability from 0 (disease not likely) to 1 (disease likely).
| PARAMETER | DESCRIPTION |
|---|---|
pred_col
|
Dataframe column containing the values to validate
TYPE:
|
min_val
|
Lower limit of range
TYPE:
|
max_val
|
Upper limit of range
TYPE:
|
Note
NaN values are ignored. Use :func:check_nan_values to catch them
separately if needed.
| RETURNS | DESCRIPTION |
|---|---|
str
|
An error message, if any (default is an empty string) |
Source code in cnb_tools/validation_toolkit.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |