pelinker.plotting¶
build_fit_cluster_viz_plot_df(report, *, exclude_noise=True, hdbscan_fit_scope=True)
¶
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(composition_df, *, save_dir, basename='fit_cluster_entity_sankey', max_clusters=None, max_entities=None, 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 entity→cluster Sankey from a long composition table (cluster, entity, count).
pySankey sizes bands by weight only (no per-label height knob). inches_per_label
sets figure height from the larger of the two label columns; min_band_height
uniformly scales weights so the thinnest band is readable without changing ratios.
Source code in pelinker/plotting.py
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
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 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 | |
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
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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | |
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
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 727 728 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 846 847 848 849 850 851 | |
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
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 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | |
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
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 | |
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
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
resolve_chosen_min_cluster_size_by_combo_from_grid(df_grid, optimization_config=None, *, grid_cluster_count_reward=None, grid_n_entities=None, grid_objective=None, optimization_method=None)
¶
Re-solve chosen_min_cluster_size per (model, layer) from a grid export CSV frame.
Source code in pelinker/plotting.py
solve_pooled_grid_by_combo_from_grid(df_grid, optimization_config=None, *, grid_cluster_count_reward=None, grid_n_entities=None, grid_objective=None, optimization_method=None)
¶
Pooled grid solve per (model, layer) from a grid export CSV frame.
Source code in pelinker/plotting.py
solve_pooled_grid_from_metrics_list(metrics_list, optimization_config=None, *, grid_cluster_count_reward=None, grid_n_entities=None, grid_objective=None, optimization_method=None)
¶
Pooled grid solve on per-sample metric tables; returns full diagnostics.