oversampleqa.plotting¶
oversampleqa.plotting
¶
Plotting helpers for oversampleqa.
plot_sample_distribution(majority, minority, synthetic, hidden_majority=None, method='pca', save_path=None)
¶
Visualize sample distribution using PCA or UMAP.
Parameters¶
majority, minority, synthetic : ndarray Arrays of majority, minority and synthetic samples. hidden_majority : ndarray, optional Hidden majority samples for reference. method : {{"pca", "umap"}}, default="pca" Dimensionality reduction method to use. save_path : str, optional If given, path to save the resulting plot. Otherwise the figure is closed and not displayed.
Source code in src/oversampleqa/plotting.py
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 | |
plot_error_comparison(benchmark_results, save_path=None)
¶
Bar plot showing mean error rates for each oversampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark_results
|
DataFrame
|
Benchmark results dataframe. |
required |
save_path
|
str | None
|
Optional output image path. |
None
|
Source code in src/oversampleqa/plotting.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
plot_error_boxplot(benchmark_results, save_path=None)
¶
Boxplot of error rates for each oversampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark_results
|
DataFrame
|
Benchmark results dataframe. |
required |
save_path
|
str | None
|
Optional output image path. |
None
|
Source code in src/oversampleqa/plotting.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
plot_error_heatmap(error_matrix, class_labels=None, save_path=None)
¶
Plot heatmap of a multi-class error attribution matrix.
Parameters¶
error_matrix : ndarray
Matrix where matrix[i, j] counts synthetic samples generated for
class i that are closest to hidden samples from class j.
class_labels : list of int, optional
Labels for the classes corresponding to the rows/columns of the matrix.
If not provided, integer indices are used.
save_path : str, optional
If given, path to save the resulting plot. Otherwise the figure is
closed and not displayed.
Source code in src/oversampleqa/plotting.py
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 | |
plot_error_ranking(benchmark_results, save_path=None)
¶
Line chart of mean error rate ranked by oversampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark_results
|
DataFrame
|
Benchmark results dataframe. |
required |
save_path
|
str | None
|
Optional output image path. |
None
|
Source code in src/oversampleqa/plotting.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
plot_noise_sensitivity(results, save_path=None)
¶
Line plot showing error rate as label noise increases.
Parameters¶
results : DataFrame
Output of :func:oversampleqa.metrics.noise_sensitivity_diagnostic,
expected to contain noise and error_rate columns.
save_path : str, optional
If given, path to save the resulting plot. Otherwise the figure is
closed and not displayed.
Source code in src/oversampleqa/plotting.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
plot_distance_histogram(dist_hidden, dist_minority, save_path=None)
¶
Histogram of nearest distances to hidden majority and real minority samples.
Parameters¶
dist_hidden, dist_minority : ndarray Distance matrices where rows correspond to synthetic samples and columns to hidden majority or real minority samples respectively. save_path : str, optional If given, path to save the resulting plot. Otherwise the figure is closed and not displayed.
Source code in src/oversampleqa/plotting.py
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 | |
plot_class_balance(labels_before, labels_after, save_path=None)
¶
Bar chart comparing class counts before and after oversampling.
Parameters¶
labels_before, labels_after : ndarray Class labels prior to oversampling and after applying an oversampler. save_path : str, optional If given, path to save the resulting plot. Otherwise the figure is closed and not displayed.
Source code in src/oversampleqa/plotting.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 | |
plot_critical_difference(result, save_path=None)
¶
Draw a critical-difference diagram (Demsar 2006).
Methods are placed on an axis by mean rank, best on the left. Methods whose ranks differ by less than the critical difference are joined by a bar, meaning the data does not separate them. The bar is the point of the diagram: it shows how much of the apparent ordering is noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FriedmanNemenyiResult
|
Outcome of :func: |
required |
save_path
|
str | None
|
Where to write the figure. Closed without saving if omitted. |
None
|
Source code in src/oversampleqa/plotting.py
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 | |
plot_fidelity_radar(reports, save_path=None, metrics=None)
¶
Compare oversamplers across the fidelity suite on one radar chart.
Outward is better on every axis. boundary safety is the complement of
the strict violation rate for that reason; the raw rate is better when
small, and mixing directions on one chart makes the area meaningless.
The validation error rate is deliberately absent. It answers a different
question -- whether synthetic points are confusable with held-out majority
-- and putting it on the same polygon invites reading it as commensurable
with the manifold metrics, which is the confusion
:doc:/fidelity exists to prevent.
Metrics that are nan because nothing could be measured are left as
nan, which draws a gap in the polygon. They are not coerced to zero: a
zero here would be indistinguishable from a genuine measurement of total
failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reports
|
Mapping[str, Any]
|
Mapping of oversampler name to a
:class: |
required |
save_path
|
str | None
|
Where to write the figure. Closed without saving if omitted. |
None
|
metrics
|
Sequence[str] | None
|
Subset of axis labels to draw, in order. Defaults to all six. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/oversampleqa/plotting.py
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 | |