Logging
Logging (payn.Logging.Logger)
Serves as the centralized logging of the pipeline, interfacing directly with MLflow and Optuna to ensure full experiment reproducibility and transparency. It abstracts the complexity of artifact serialization (DataFrames to CSV buffers) and hyperparameter tracking.
- Parameter Logging: The
log_model_hyperparametersfunction differentiates between user-defined overrides and model defaults, logging both (defaults prefixed withconfig_) to clarify exactly which parameters drove the model's behavior. - Artifact Serialization: Utilizes
StringIObuffers to log pandas DataFrames directly to MLflow without creating intermediate temporary files on disk, reducing I/O overhead and filesystem clutter. - Reproducibility: Logs the exact state of the Optuna study (trials, best parameters, durations) and the resulting model attributes (feature importances, best iteration), allowing for the reconstruction of the optimization trajectory.
- Data Snapshots: Captures specific slices of the data at critical checkpoints (e.g.,
log_spysplit_data,log_augmen_negatives) to verify the correctness of the PU split logic post-execution.
Central logging utility for the PAYN framework.
Handles the logging of: - Configuration parameters - Dataframes (as CSV artifacts) - Model hyperparameters and attributes (CatBoost) - Optimization studies (Optuna) - Evaluation metrics and thresholds
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Dict[str, Any]
|
The global configuration dictionary. |
Source code in payn\Logging\logging.py
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 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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
__init__(config)
Initialize the Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Configuration dictionary. |
required |
Source code in payn\Logging\logging.py
25 26 27 28 29 30 31 32 | |
log_augmen_negatives(augmen_real_negatives, fold_index)
Log augmented reliable negatives as an artifact and count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
augmen_real_negatives
|
DataFrame
|
Identified negative samples. |
required |
fold_index
|
int
|
Current fold index. |
required |
Source code in payn\Logging\logging.py
292 293 294 295 296 297 298 299 300 301 302 303 304 | |
log_config_to_mlflow(print_config=True)
Log all configuration parameters to MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
print_config
|
bool
|
If True, prints parameters to stdout. |
True
|
Source code in payn\Logging\logging.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
log_evaluation_metrics(eval_result)
Log evaluation metrics of the model to MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eval_result
|
dict
|
Evaluation results from test set. |
required |
Source code in payn\Logging\logging.py
192 193 194 195 196 197 198 199 200 | |
log_evaluation_summary(evaluation_results, artifact_name='evaluation_summary.json')
Log the evaluation summary as a formatted JSON artifact in MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluation_results
|
Dict[str, Any]
|
The dictionary of evaluation results. |
required |
artifact_name
|
Optional[str]
|
The artifact file name. Defaults to "evaluation_summary.json". |
'evaluation_summary.json'
|
Source code in payn\Logging\logging.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
log_fold_data(train_data, val_data, test_data, fold_index=None)
Log train, validation, and test splits as artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
DataFrame
|
Training dataset. |
required |
val_data
|
DataFrame
|
Validation dataset. |
required |
test_data
|
DataFrame
|
Test dataset. |
required |
fold_index
|
int
|
The index of the K-Fold split. |
None
|
Source code in payn\Logging\logging.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
log_image_to_mlflow(image_path, artifact_name=None)
Log an image to MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
Path to the image file. |
required |
artifact_name
|
Optional[str]
|
Name for the artifact in MLflow. If None, uses the image file name. |
None
|
Source code in payn\Logging\logging.py
268 269 270 271 272 273 274 275 276 277 278 279 280 | |
log_message(message)
Log a generic message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to log. |
required |
Source code in payn\Logging\logging.py
318 319 320 321 322 323 324 325 326 327 328 329 330 | |
log_metric_individual(metrics, prefix='')
Log individual metrics using mlflow.log_metric for easy viewing in the MLflow UI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
Dict[str, float]
|
Dictionary of metric names and values. |
required |
prefix
|
Optional[str]
|
Optional prefix to add to metric names. |
''
|
Source code in payn\Logging\logging.py
348 349 350 351 352 353 354 355 356 357 358 | |
log_model(model, artifact_name)
Save and log a CatBoost model artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Union[CatBoostClassifier, CatBoostRegressor]
|
The trained model. |
required |
artifact_name
|
str
|
Filename for the saved model. |
required |
Source code in payn\Logging\logging.py
136 137 138 139 140 141 142 143 144 145 | |
log_model_attributes(model)
Log internal attributes (best iteration, feature importance) of a trained model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Union[CatBoostClassifier, CatBoostRegressor]
|
The trained model. |
required |
Source code in payn\Logging\logging.py
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 | |
log_model_hyperparameters(model, **kwargs)
Log the hyperparameters of the model to MLflow.
Logs both user-provided hyperparameters and the config hyperparameters of the CatBoost model. User-specified parameters are logged as-is, while non-overridden defaults are prefixed with 'config_'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CatBoostClassifier
|
CatBoost model instance. |
required |
**kwargs
|
Any
|
Additional keyword arguments for user-specified hyperparameters. |
{}
|
Source code in payn\Logging\logging.py
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 | |
log_optuna_study(study)
Log Optuna study details to MLflow, including parameters, metrics, and a summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
The Optuna study object. |
required |
Source code in payn\Logging\logging.py
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 | |
log_probabilities(spy_inf_data, fold_index)
Log predicted probabilities for spy-infused data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spy_inf_data
|
DataFrame
|
Data with probabilities. |
required |
fold_index
|
int
|
Current fold index. |
required |
Source code in payn\Logging\logging.py
306 307 308 309 310 311 312 313 314 315 316 | |
log_spy_infiltrated_data(spy_inf_train_data, spies)
Log spy-infiltrated training set as an artifact to MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spy_inf_train_data
|
DataFrame
|
The combined training set (Positives + Unlabeled/Spies). |
required |
spies
|
DataFrame
|
The subset of Positives used as Spies. |
required |
Source code in payn\Logging\logging.py
95 96 97 98 99 100 101 102 103 104 | |
log_spysplit_data(train_data, unlabeled_data)
Log the initial PU split (Labeled Train vs. Unlabeled) as artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_data
|
DataFrame
|
Labeled positive training data. |
required |
unlabeled_data
|
DataFrame
|
Unlabeled data pool. |
required |
Source code in payn\Logging\logging.py
83 84 85 86 87 88 89 90 91 92 93 | |
log_study_visualizations(study, visualizer)
Log visualization plots generated from an Optuna study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
The study object. |
required |
visualizer
|
Any
|
Instance of the Visualisation class. |
required |
Source code in payn\Logging\logging.py
254 255 256 257 258 259 260 261 262 263 264 265 | |
log_threshold(threshold)
Log the determined threshold for identifying augmented reliable negatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
The calculated threshold. |
required |
Source code in payn\Logging\logging.py
282 283 284 285 286 287 288 289 290 | |