pelinker.plotting¶
build_fit_cluster_viz_plot_df(report, *, exclude_noise=True, hdbscan_fit_scope=True, cluster_labels=None)
¶
Build a :func:plot_cluster_viz frame from a :class:~pelinker.reporting.ModelSelectionReport.
Source code in pelinker/plotting.py
diagnostics_to_pairgrid_dataframe(diag)
¶
Build a DataFrame for :func:plot_pca_quality_pairgrid from linker fit diagnostics.
class_label is negative / positive from oov_label (1 / 0).
Source code in pelinker/plotting.py
enrich_fit_cluster_viz_plot_df_with_context(plot_df, pmid_text_table_path, *, words_before=5, words_after=5)
¶
Add a context column: five words before/after each mention (from a_abs/b_abs).
Source code in pelinker/plotting.py
filter_assignments_for_cluster_viz(assign, *, exclude_noise=True, hdbscan_fit_scope=True)
¶
Restrict cluster viz rows to HDBSCAN-fit + screener/OOV-pass mentions when flagged.
Source code in pelinker/plotting.py
load_pmid_texts(table_path, pmids, *, chunk_size=10000)
¶
Stream a PMID/text table and return rows for the requested pmids only.
Source code in pelinker/plotting.py
mention_context_window(text, a_abs, b_abs, *, words_before=5, words_after=5)
¶
Return a short phrase around [a_abs, b_abs) with the mention marked «…».
Source code in pelinker/plotting.py
plot_cluster_entity_sankey(flow_df, *, save_dir, basename='fit_cluster_entity_sankey', max_clusters=None, max_entities=None, min_within_cluster_fraction=0.0, cluster_labels=None, cluster_label_include_id=False, inches_per_label=_SANKEY_DEFAULT_INCHES_PER_LABEL, min_fig_height=_SANKEY_DEFAULT_MIN_FIG_HEIGHT, min_band_height=_SANKEY_DEFAULT_MIN_BAND_HEIGHT)
¶
Bipartite KB-in entity→cluster Sankey from a long flow table (cluster, entity, count).
Expects unbundled entity mass (no pie/bar Other (...) rows). Caps by dropping
the long tail. pySankey sizes bands by weight only; inches_per_label sets
figure height; min_band_height uniformly scales weights for readability.
Source code in pelinker/plotting.py
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | |
plot_dbcv_vs_ari_from_grid(df_grid, output_path, *, optimization_config=None, grid_cluster_count_reward=None, grid_n_entities=None, grid_objective=None, optimization_method=None)
¶
Scatter of mean DBCV vs mean ARI per (model, layer); shape = arity (△/□/○),
fill colors = base encoder model(s); text = layer spec only (e.g. fusion 2+3).
95% covariance ellipses when n_sample ≥ 2.
Uses (dbcv, ari) at chosen_min_cluster_size for each bootstrap sample_idx
(same hyperparameter as the vertical line on per-combination error-bar plots).
Both axes are fixed to [0, _AXIS_MAX].
When any solver argument is set (optimization_config or grid override kwargs),
chosen_min_cluster_size is re-computed per (model, layer) from the grid metrics
instead of using values stored in df_grid.
Returns:
| Type | Description |
|---|---|
bool
|
True if a figure was written, False if required data were absent. |
Source code in pelinker/plotting.py
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 | |
plot_heatmap(df_results, output_path, metric='best_score', metric_label=None, *, secondary_metric='best_size')
¶
Create a heatmap with model (rows) and layer (columns).
Color represents the specified metric; text overlays secondary_metric and metric value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_results
|
DataFrame
|
DataFrame with columns: model, layer, … |
required |
output_path
|
Path
|
Path to save the heatmap figure |
required |
metric
|
str
|
Column name for the metric to display as color (default: "best_score") |
'best_score'
|
metric_label
|
str | None
|
Label for the metric (default: uses metric column name) |
None
|
secondary_metric
|
str | None
|
Column for text annotation besides the metric cell (default:
|
'best_size'
|
Source code in pelinker/plotting.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | |
plot_metrics_with_error_bars(metrics_list, output_path, *, chosen_min_cluster_size=None, grid_solve=None, optimization_config=None, grid_cluster_count_reward=None, grid_n_entities=None, grid_objective=None, optimization_method=None)
¶
Plot metrics across multiple runs with error bars using seaborn lineplot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics_list
|
list[DataFrame]
|
List of DataFrames, each with columns: min_cluster_size, icm, n_clusters, dbcv, ari |
required |
output_path
|
Path
|
Path to save the figure |
required |
chosen_min_cluster_size
|
float | None
|
Optional vertical marker for the selected grid value (e.g. from smoother / argmax). |
None
|
grid_solve
|
SmoothedGridOptimumResult | None
|
Precomputed pooled grid diagnostics (avoids a second solve; drives objective panel). |
None
|
optimization_config
|
ClusteringOptimizationConfig | None
|
When set (or when any grid override kwarg is set and |
None
|
grid_cluster_count_reward
|
float | None
|
Override :attr: |
None
|
grid_n_entities
|
int | None
|
Override :attr: |
None
|
grid_objective
|
GridObjectiveSpec | None
|
Override :attr: |
None
|
optimization_method
|
str | None
|
Override :attr: |
None
|
Source code in pelinker/plotting.py
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 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |
plot_pca_quality_pairgrid(df, output_path, *, class_col='class_label', subtitle=None, max_scatter_points=4000, max_kde_points=20000)
¶
PairGrid of PCA quality features (pca_residual, pca_spectral_entropy, pca_mahalanobis) with hue for class (negative / positive).
Upper triangle: balanced class subsample (equal cap per class) with distinct markers.
Lower triangle & diagonal: KDE per hue with common_norm=False so each class is
normalized on its own scale (not pooled against the majority class).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with feature columns and class_col. |
required |
output_path
|
Path
|
PNG path (PDF sibling also written). |
required |
class_col
|
str
|
Column used for hue. |
'class_label'
|
subtitle
|
str | None
|
Combo label for the figure suptitle (e.g. model/layer/sample). |
None
|
max_scatter_points
|
int
|
Cap for upper-triangle scatter layer (split evenly by class). |
4000
|
max_kde_points
|
int
|
Cap for lower-triangle KDE and diagonal KDE layers. |
20000
|
Source code in pelinker/plotting.py
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 | |
plot_roc_comparison(scores_df, output_path, *, combo_keys)
¶
ROC curves for screener_best_score, oov_score, and combined_score
pooled over samples per combo_key.
Source code in pelinker/plotting.py
plot_scale_curve(curve, output_path, *, formats=('png', 'pdf'))
¶
Log-log plot of chosen min_cluster_size vs realized N, with the fitted law.
Rungs whose chosen value sat on a grid bound are drawn hollow and red: on those points the grid, not the sample size, decided the answer, and the slope through them is not evidence.
Source code in pelinker/plotting.py
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 | |
plot_screener_oov_bar(summary_df, output_path)
¶
Grouped bar chart per (model, layer): mean AUC for screener / OOV / combined.
Requires screener_auc_mean, oov_auc_mean, combined_auc_mean.
Single-embedding rows only (excludes fusion* model labels).
Source code in pelinker/plotting.py
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 | |