Evaluation
Evaluation (payn.Evaluation.Evaluator)
This class provides specialized metrics to assess the quality of the reliable negative identification process. This is possible due to the use of fully labelled HTE datasets as a ground truth. Since the primary goal of the framework is to construct a balanced training set, standard classification accuracy is insufficient. This module implements negative specific metrics and confusion matrices.
- Negative-Specific Metrics: Isolates the subset of data that the model has labeled as reliable negatives and computes negative Precision and negative Recall.
- Negative Precision measures the purity of the negative set (i.e., How many of the identified negatives are actually negative?). High negative precision is crucial to prevent the introduction of noise through latent positives.
- Negative Recall measures the coverage (i.e., What fraction of all true negatives did we successfully find?).
- Undecisive Analysis: The module tracks the volume of undecisive data points—those discarded because their probabilities fell into the zone between the reliable negatives and the known positives.
- Safety Checks: The evaluator automatically flags discrepancies, such as "Missed Negatives" (true negatives that were lost during processing) or index mismatches between the input and output dataframes.
Evaluator computes dual evaluation metrics for the Spy pipeline.
It assesses performance from multiple perspectives: 1. Overall Evaluation: Standard classification metrics based on the union of all subsets. 2. Negative-Specific Evaluation: Performance of the reliable negative extraction. 3. Undecisive Analysis: Quantification of discarded data. 4. Missed Negatives: Analysis of ground-truth negatives lost during filtering.
Attributes:
| Name | Type | Description |
|---|---|---|
meta_columns |
Dict[str, str]
|
Mapping of internal column names to dataset columns. |
logger |
Optional[Logger]
|
Logger instance for tracking results. |
fold_index |
Optional[int]
|
Current cross-validation fold index. |
training_mode |
bool
|
Flag indicating if the evaluator is running during training. |
Source code in payn\Evaluation\evaluator.py
10 11 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 | |
__init__(meta_columns, logger=None, fold_index=None, training_mode=True)
Initialize the Evaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta_columns
|
Dict[str, str]
|
Dictionary mapping meta keys to dataframe columns. |
required |
logger
|
Logger
|
Logger instance. |
None
|
fold_index
|
int
|
Index of the current fold. |
None
|
training_mode
|
bool
|
Whether evaluation is performed during training. |
True
|
Source code in payn\Evaluation\evaluator.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
compute_classification_metrics(y_true, y_pred)
Compute standard classification metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
True labels. |
required |
y_pred
|
ndarray
|
Predicted labels. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict[str, float]: Dictionary containing accuracy, precision, recall, and f1. |
Source code in payn\Evaluation\evaluator.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
compute_confusion_matrix(y_true, y_pred)
Compute the confusion matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
True labels. |
required |
y_pred
|
ndarray
|
Predicted labels. |
required |
Returns:
| Type | Description |
|---|---|
List[List[int]]
|
List[List[int]]: Confusion matrix as a nested list (JSON serializable). |
Source code in payn\Evaluation\evaluator.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
compute_missed_negatives(true_data, predicted_union)
Compute the ratio of missed negatives (true negatives not captured in the final set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
true_data
|
DataFrame
|
Ground truth data. |
required |
predicted_union
|
DataFrame
|
Union of all processed data subsets. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict[str, float]: Dictionary containing the missed negative ratio. |
Source code in payn\Evaluation\evaluator.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
compute_missing_indices(true_data, predicted_union)
Identify indices present in true data but missing from predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
true_data
|
DataFrame
|
Ground truth data. |
required |
predicted_union
|
DataFrame
|
Union of all processed data subsets. |
required |
Returns:
| Type | Description |
|---|---|
List[Any]
|
List[Any]: List of missing indices. |
Source code in payn\Evaluation\evaluator.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
compute_negative_specific_metrics(negatives_df, true_data)
Compute metrics specifically for the subset predicted as negatives.
Calculates
- Negative Precision (NPV): Fraction of predicted negatives that are truly negative.
- Negative Recall (True Negative Rate): Fraction of true negatives captured.
- Negative F1: Harmonic mean of negative precision and recall.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
negatives_df
|
DataFrame
|
Dataframe of predicted reliable negatives. |
required |
true_data
|
DataFrame
|
Original dataframe with ground truth. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict[str, float]: Dictionary of negative-specific metrics. |
Source code in payn\Evaluation\evaluator.py
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 | |
evaluate(true_data, augmen_negatives, known_positives, undecisives)
Perform comprehensive dual evaluation of the PU pipeline.
- Overall Evaluation: Merges all subsets and compares against ground truth.
- Negative-Specific Evaluation: Focuses on the purity of the 'reliable negative' set.
- Undecisive Analysis: Tracks data loss.
- Missed Negatives: Tracks recall loss relative to ground truth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
true_data
|
DataFrame
|
Full training data with ground-truth labels. |
required |
augmen_negatives
|
DataFrame
|
Datapoints predicted as reliable negatives. |
required |
known_positives
|
DataFrame
|
Datapoints forced to be known positives. |
required |
undecisives
|
DataFrame
|
Datapoints labeled as "undecisive". |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing all computed metrics. |
Source code in payn\Evaluation\evaluator.py
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 | |
from_config(config, logger=None, fold_index=1, training_mode=True)
classmethod
Alternative constructor that extracts parameters from a config object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
logger
|
Logger
|
Logger instance. |
None
|
fold_index
|
int
|
Current fold index. |
1
|
training_mode
|
bool
|
Training mode flag. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Evaluator |
Evaluator
|
An initialized Evaluator instance. |
Source code in payn\Evaluation\evaluator.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
log_evaluation_summary(results)
Log the evaluation summary as a JSON artifact in MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Dict[str, Any]
|
The evaluation results dictionary. |
required |
Source code in payn\Evaluation\evaluator.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
log_metric_individual(metrics, prefix='')
Log individual metrics using mlflow.log_metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
Dict[str, float]
|
Dictionary of metrics. |
required |
prefix
|
str
|
Prefix for the metric name in MLflow. |
''
|
Source code in payn\Evaluation\evaluator.py
194 195 196 197 198 199 200 201 202 203 204 | |