BaseEvaluatorWrapper
Bases: ModelExtractor
, ABC
Base class for wrappers handling model evaluation processes.
This class serves as a foundational structure for evaluator wrappers, offering methods to initialize, prepare, and evaluate models according to specified parameters. It provides core functionality to streamline evaluation, feature importance analysis, patient inference, and jackknife resampling.
Inherits
BaseModelExtractor
: Loads configuration parameters and model extraction.ABC
: Specifies abstract methods that must be implemented by subclasses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learners_dict
|
Dict
|
Dictionary containing models and their metadata. |
required |
criterion
|
str
|
Criterion for selecting models (e.g., 'f1', 'brier_score'). |
required |
aggregate
|
bool
|
Whether to aggregate metrics. |
required |
verbose
|
bool
|
Controls verbose in the evaluation process. |
required |
random_state
|
int
|
Random state for resampling. |
required |
path
|
Path
|
Path to the directory containing processed data files. |
required |
Attributes:
Name | Type | Description |
---|---|---|
learners_dict |
Dict
|
Holds learners and metadata. |
criterion |
str
|
Evaluation criterion to select the optimal model. |
aggregate |
bool
|
Indicates if metrics should be aggregated. |
verbose |
bool
|
Flag for controlling logging verbose. |
random_state |
int
|
Random state for resampling. |
model |
object
|
Best-ranked model for the given criterion. |
encoding |
str
|
Encoding type, either 'one_hot' or 'target'. |
learner |
str
|
The learner associated with the best model. |
task |
str
|
Task associated with the model ('pocketclosure', 'improve', etc.). |
factor |
Optional[float]
|
Resampling factor if applicable. |
sampling |
Optional[str]
|
Resampling strategy used (e.g., 'smote'). |
classification |
str
|
Classification type ('binary' or 'multiclass'). |
dataloader |
ProcessedDataLoader
|
Data loader and transformer. |
resampler |
Resampler
|
Resampling strategy for training and testing. |
df |
DataFrame
|
Loaded dataset. |
df_processed |
DataFrame
|
Processed dataset. |
train_df |
DataFrame
|
Training data after splitting. |
test_df |
DataFrame
|
Test data after splitting. |
X_train |
DataFrame
|
Training features. |
y_train |
Series
|
Training labels. |
X_test |
DataFrame
|
Test features. |
y_test |
Series
|
Test labels. |
base_target |
Optional[ndarray]
|
Baseline target for evaluations. |
baseline |
Baseline
|
Basline class for model analysis. |
evaluator |
ModelEvaluator
|
Evaluator for model metrics and feature importance. |
inference_engine |
ModelInference
|
Model inference manager. |
trainer |
Trainer
|
Trainer for model evaluation and optimization. |
Inherited Properties
criterion (str)
: Retrieves or sets current evaluation criterion for model selection. Supports 'f1', 'brier_score', and 'macro_f1'.model (object)
: Retrieves best-ranked model dynamically based on the current criterion. Recalculates when criterion is updated.
Abstract Methods
wrapped_evaluation
: Performs model evaluation and generates specified plots.evaluate_cluster
: Performs clustering and calculates Brier scores.evaluate_feature_importance
: Computes feature importance using specified methods.average_over_splits
: Aggregates metrics over multiple splits for model robustness.wrapped_patient_inference
: Runs inference on individual patient data.wrapped_jackknife
: Executes jackknife resampling on patient data for confidence interval estimation.
Source code in periomod/wrapper/_basewrapper.py
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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
__init__(learners_dict, criterion, aggregate, verbose, random_state, path)
¶
Base class for EvaluatorWrapper, initializing common parameters.
Source code in periomod/wrapper/_basewrapper.py
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 |
|
average_over_splits(num_splits, n_jobs)
abstractmethod
¶
Trains the final model over multiple splits with different seeds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_splits
|
int
|
Number of random seeds/splits to train the model on. |
required |
n_jobs
|
int
|
Number of parallel jobs. |
required |
Source code in periomod/wrapper/_basewrapper.py
541 542 543 544 545 546 547 548 |
|
evaluate_cluster(n_cluster, base, revaluation, true_preds, brier_threshold, tight_layout)
abstractmethod
¶
Performs cluster analysis with Brier scores, with optional subsetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_cluster
|
int
|
Number of clusters for Brier score clustering analysis. |
required |
base
|
Optional[str]
|
Baseline variable for comparison. |
required |
revaluation
|
Optional[str]
|
Revaluation variable for comparison. |
required |
true_preds
|
bool
|
If True, further subsets to cases where model predictions match the true labels. |
required |
brier_threshold
|
Optional[float]
|
Threshold for Brier score filtering. |
required |
tight_layout
|
bool
|
If True, applies tight layout to the plot. |
required |
Source code in periomod/wrapper/_basewrapper.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
evaluate_feature_importance(fi_types, base, revaluation, true_preds, brier_threshold)
abstractmethod
¶
Evaluates feature importance using specified types, with optional subsetting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fi_types
|
List[str]
|
List of feature importance types to evaluate. |
required |
base
|
Optional[str]
|
Baseline variable for comparison. |
required |
revaluation
|
Optional[str]
|
Revaluation variable for comparison. |
required |
true_preds
|
bool
|
If True, further subsets to cases where model predictions match the true labels. |
required |
brier_threshold
|
Optional[float]
|
Threshold for Brier score filtering. |
required |
Source code in periomod/wrapper/_basewrapper.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
|
wrapped_evaluation(cm, cm_base, brier_groups, calibration, tight_layout)
abstractmethod
¶
Runs evaluation on the best-ranked model based on specified criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cm
|
bool
|
If True, plots the confusion matrix. |
required |
cm_base
|
bool
|
If True, plots the confusion matrix against the value before treatment. Only applicable for specific tasks. |
required |
brier_groups
|
bool
|
If True, calculates Brier score groups. |
required |
calibration
|
bool
|
If True, plots model calibration. |
required |
tight_layout
|
bool
|
If True, applies tight layout to the plot. |
required |
Source code in periomod/wrapper/_basewrapper.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
wrapped_jackknife(patient, results, sample_fraction, n_jobs, max_plots)
abstractmethod
¶
Runs jackknife resampling for inference on a given patient's data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient
|
Patient
|
|
required |
results
|
DataFrame
|
DataFrame to store results from jackknife inference. |
required |
sample_fraction
|
float
|
The fraction of patient data to use for jackknife resampling. |
required |
n_jobs
|
int
|
The number of parallel jobs to run. |
required |
max_plots
|
int
|
Maximum number of plots for jackknife intervals. |
required |
Source code in periomod/wrapper/_basewrapper.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
wrapped_patient_inference(patient)
abstractmethod
¶
Runs inference on the patient's data using the best-ranked model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patient
|
Patient
|
A |
required |
Source code in periomod/wrapper/_basewrapper.py
550 551 552 553 554 555 556 557 558 559 560 |
|