File size: 40,104 Bytes
0f332f8 b5567db 3ac33b9 b5567db 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 b5567db 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 7363a4a 3ac33b9 7363a4a 3ac33b9 7363a4a 3ac33b9 7363a4a 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 0f332f8 3ac33b9 5e91884 3ac33b9 5e91884 3ac33b9 5e91884 3ac33b9 5e91884 3ac33b9 5e91884 3ac33b9 0f332f8 b5567db 3ac33b9 b5567db 3ac33b9 b5567db 3ac33b9 b5567db 3ac33b9 b5567db 0f332f8 01f067b 3ac33b9 cc5b175 | 1 2 3 4 5 6 7 8 9 10 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 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 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 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 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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 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 1074 1075 1076 1077 1078 | import os
import sys
import json
import datetime
import math
try:
import scipy.io
except ImportError:
scipy = None
try:
import numpy as np
except ImportError:
np = None
try:
import pandas as pd
except ImportError:
pd = None
from flask import Flask, jsonify, request, render_template, send_from_directory
from dash import Dash, html, dcc, dash_table, Input, Output, State, callback_context
import dash_mantine_components as dmc
import plotly.graph_objects as go
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from leaderboard import rank_results
try:
from complex_com import algorithms as ALGO_COMPLEXITY
except ImportError:
ALGO_COMPLEXITY = {}
base_dir = os.getcwd()
if not os.path.isdir(os.path.join(base_dir, "results")):
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
PROJECT_ROOT = base_dir
RESULT_DIR = os.path.join(PROJECT_ROOT, "results")
DATA_DIR = os.path.join(PROJECT_ROOT, "data")
PDF_DIR = os.path.join(PROJECT_ROOT, "pdf")
os.makedirs(RESULT_DIR, exist_ok=True)
server = Flask(__name__)
RESULT_CACHE = {}
def save_result_json(dataset, results):
path = os.path.join(RESULT_DIR, f"{dataset}.json")
with open(path, "w", encoding="utf-8") as f:
json.dump(results, f, indent=4)
def load_result_json(dataset):
path = os.path.join(RESULT_DIR, f"{dataset}.json")
if not os.path.exists(path):
return None
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
def list_available_datasets():
datasets = set()
for f in os.listdir(RESULT_DIR):
if f.endswith(".json"):
datasets.add(f.replace(".json", ""))
datasets.add("Authorship")
return sorted(datasets)
def run_agent_for_dataset(dataset):
return []
def build_dataset_metadata():
datasets = {}
for name in list_available_datasets():
last_updated = datetime.datetime.fromtimestamp(1707382400).strftime("%Y-%m-%d")
num_samples = None
total_features = None
if scipy:
mat_path = os.path.join(DATA_DIR, f"{name}.mat")
if os.path.exists(mat_path):
try:
mat = scipy.io.loadmat(mat_path)
if "X" in mat:
X = mat["X"]
num_samples, total_features = X.shape
except Exception:
num_samples = None
total_features = None
datasets[name] = {
"name": name,
"last_updated": last_updated,
"num_samples": num_samples,
"total_features": total_features,
}
return datasets
DATASET_METADATA = build_dataset_metadata()
def build_complexity_display():
display_complexity = {}
for algo, comp in ALGO_COMPLEXITY.items():
t = comp.get("time", "")
s = comp.get("space", "")
t_disp = t.replace("**", "^").replace(" * ", "")
if "O(" not in t_disp:
t_disp = f"O({t_disp})" if t_disp else ""
s_disp = s.replace("**", "^").replace(" * ", "")
if "O(" not in s_disp:
s_disp = f"O({s_disp})" if s_disp else ""
display_complexity[algo] = {"time": t_disp, "space": s_disp}
return display_complexity
DISPLAY_COMPLEXITY = build_complexity_display()
VIEW_CONFIG = {
"overall": [
{"key": "mean_f1", "label": "Mean F1"},
{"key": "mean_auc", "label": "Mean AUC"},
],
"classifiers-f1": [
{"key": "metrics.nb.f1", "label": "NB F1"},
{"key": "metrics.svm.f1", "label": "SVM F1"},
{"key": "metrics.rf.f1", "label": "RF F1"},
],
"classifiers-auc": [
{"key": "metrics.nb.auc", "label": "NB AUC"},
{"key": "metrics.svm.auc", "label": "SVM AUC"},
{"key": "metrics.rf.auc", "label": "RF AUC"},
],
}
def get_results_for_dataset(dataset):
if dataset in RESULT_CACHE:
leaderboard = rank_results(RESULT_CACHE[dataset])
else:
results = load_result_json(dataset)
if results is None:
results = run_agent_for_dataset(dataset)
if results:
save_result_json(dataset, results)
RESULT_CACHE[dataset] = results or []
leaderboard = rank_results(results or [])
if not isinstance(leaderboard, list):
if hasattr(leaderboard, "to_dict"):
leaderboard = leaderboard.to_dict(orient="records")
else:
leaderboard = list(leaderboard)
return leaderboard
def get_metric_value(row, key):
value = row
for part in key.split("."):
if isinstance(value, dict):
value = value.get(part)
else:
return None
return value
def get_feature_count(row):
num_features = row.get("num_features")
if isinstance(num_features, (int, float)):
return int(num_features)
selected = row.get("selected_features")
if isinstance(selected, list):
return len(selected)
return 0
def apply_filters(results, dataset_meta, min_f1, max_features, del_range, complexity, selected_algos):
total_features = dataset_meta.get("total_features") if dataset_meta else None
filtered = []
min_del = (del_range[0] if del_range else 0) / 100
max_del = (del_range[1] if del_range else 100) / 100
min_f1 = min_f1 if min_f1 is not None else 0
max_features = max_features if max_features is not None else float("inf")
selected_algos = selected_algos if selected_algos else None
for r in results:
algo = r.get("algorithm")
if selected_algos and algo not in selected_algos:
continue
raw_f1 = r.get("mean_f1")
try:
f1 = float(raw_f1) if raw_f1 is not None else 0
except (TypeError, ValueError):
f1 = 0
if f1 < min_f1:
continue
feats = get_feature_count(r)
if feats > max_features:
continue
if isinstance(total_features, (int, float)) and total_features > 0:
del_rate = 1 - (feats / total_features)
if del_rate < min_del or del_rate > max_del:
continue
if complexity and complexity != "all":
comp = DISPLAY_COMPLEXITY.get(algo, {}).get("time")
if comp != complexity:
continue
filtered.append(r)
return filtered
def build_score_figure(results, view_mode):
if not results:
fig = go.Figure()
fig.add_annotation(
text="No Data Available",
x=0.5,
y=0.5,
xref="paper",
yref="paper",
showarrow=False,
font=dict(size=16, color="#999"),
)
fig.update_layout(
xaxis=dict(visible=False),
yaxis=dict(visible=False),
margin=dict(l=20, r=20, t=20, b=20),
)
return fig
top = results[:20]
labels = [r.get("algorithm") for r in top]
fig = go.Figure()
if view_mode == "overall":
fig.add_trace(go.Bar(
name="Mean F1",
y=labels,
x=[r.get("mean_f1") for r in top],
orientation="h",
marker_color="rgba(52, 152, 219, 0.7)",
))
fig.add_trace(go.Bar(
name="Mean AUC",
y=labels,
x=[r.get("mean_auc") for r in top],
orientation="h",
marker_color="rgba(46, 204, 113, 0.7)",
))
elif view_mode == "classifiers-f1":
for idx, clf in enumerate(["nb", "svm", "rf"]):
fig.add_trace(go.Bar(
name=clf.upper(),
y=labels,
x=[get_metric_value(r, f"metrics.{clf}.f1") for r in top],
orientation="h",
marker_color=f"hsla({200 + idx * 40}, 70%, 60%, 0.7)",
))
else:
for idx, clf in enumerate(["nb", "svm", "rf"]):
fig.add_trace(go.Bar(
name=clf.upper(),
y=labels,
x=[get_metric_value(r, f"metrics.{clf}.auc") for r in top],
orientation="h",
marker_color=f"hsla({100 + idx * 40}, 70%, 60%, 0.7)",
))
fig.update_layout(
barmode="group",
margin=dict(l=20, r=20, t=20, b=20),
legend=dict(orientation="h"),
yaxis=dict(autorange="reversed"),
)
return fig
def build_pareto_figure(results):
x_vals = [get_feature_count(r) for r in results]
y_vals = [r.get("mean_f1") for r in results]
labels = [r.get("algorithm") for r in results]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=x_vals,
y=y_vals,
mode="markers",
text=labels,
marker=dict(color="rgba(230, 126, 34, 0.7)", size=10),
))
fig.update_layout(
margin=dict(l=20, r=20, t=20, b=20),
xaxis_title="Num Features",
yaxis_title="Mean F1",
)
return fig
def build_table(results, view_mode):
config = VIEW_CONFIG[view_mode]
headers = ["Rank", "Algorithm"] + [c["label"] for c in config] + ["Selected Features"]
col_keys = [c["key"] for c in config]
max_map = {}
for key in col_keys:
vals = []
for r in results:
v = get_metric_value(r, key)
try:
v = float(v) if v is not None else None
except Exception:
v = None
if v is not None:
vals.append(v)
max_map[key] = max(vals) if vals else 0
thead = html.Thead(
html.Tr([html.Th(h, className="cth") for h in headers], className="chead")
)
rows = []
if not results:
empty_cells = [html.Td("", className="ctd")] * (len(headers) - 2)
rows.append(
html.Tr(
[html.Td("", className="ctd"), html.Td("No Data Available", className="ctd")]+empty_cells,
className="crow"
)
)
else:
for idx, r in enumerate(results):
rank = idx + 1
medal = {1: "π₯", 2: "π₯", 3: "π₯"}.get(rank, str(rank))
row_class = (
"crow crow-gold" if rank == 1 else
"crow crow-silver" if rank == 2 else
"crow crow-bronze" if rank == 3 else
"crow"
)
algo = r.get("algorithm") or "Unknown"
metric_tds = []
for c in config:
key = c["key"]
raw = get_metric_value(r, key)
try:
val = float(raw) if raw is not None else 0.0
except Exception:
val = 0.0
m = max_map.get(key) or 0.0
pct = (val / m * 100.0) if m > 0 else 0
is_max = (m > 0 and abs(val - m) < 1e-12)
bar = html.Div(
[
html.Div(className="bar-track", children=html.Div(className="bar-fill", style={"width": f"{pct:.2f}%"})),
html.Span(f"{val:.4f}", className=("bar-text is-max" if is_max else "bar-text")),
],
className="bar-cell",
title=f"max={m:.4f}" if is_max else None,
)
cell = html.Td(bar, className="ctd cnum")
metric_tds.append(cell)
selected = r.get("selected_features")
feat_count = get_feature_count(r)
if isinstance(selected, list):
features_title = ", ".join(str(s) for s in selected)
else:
features_title = "N/A"
feature_td = html.Td(
f"{feat_count} features",
className="ctd cfeat",
title=features_title,
style={"whiteSpace": "nowrap"},
)
row = html.Tr(
[html.Td(medal, className="ctd crank"), html.Td(algo, className="ctd calgo")] + metric_tds + [feature_td],
className=row_class,
)
rows.append(row)
tbody = html.Tbody(rows)
table = html.Table([thead, tbody], className="custom-table")
return html.Div(className="table-container", children=table)
dataset_options = [{"label": name, "value": name} for name in sorted(DATASET_METADATA.keys())]
default_dataset = "Authorship" if "Authorship" in DATASET_METADATA else (dataset_options[0]["value"] if dataset_options else "Authorship")
complexity_options = sorted({v.get("time") for v in DISPLAY_COMPLEXITY.values() if v.get("time")})
complexity_data = [{"label": "All Complexities", "value": "all"}] + [
{"label": c, "value": c} for c in complexity_options
]
dash_app = Dash(__name__, server=server, url_base_pathname="/")
app = dash_app
css = """
:root {
--primary-color: #3498db;
--secondary-color: #2c3e50;
--background-color: #f8f9fa;
--text-color: #333;
--border-color: #dee2e6;
--hover-color: #f1f1f1;
--accent-color: #e67e22;
--sidebar-width: 280px;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: var(--background-color);
color: var(--text-color);
}
.app-shell {
display: flex;
min-height: 100vh;
}
.sidebar {
width: var(--sidebar-width);
background-color: var(--secondary-color);
color: white;
position: fixed;
height: 100vh;
overflow-y: auto;
padding: 20px;
box-sizing: border-box;
left: 0;
top: 0;
z-index: 100;
display: flex;
flex-direction: column;
gap: 20px;
}
.sidebar h2 {
font-size: 1.1em;
margin-bottom: 10px;
color: #ecf0f1;
border-bottom: 1px solid #34495e;
padding-bottom: 5px;
}
.main-content {
margin-left: var(--sidebar-width);
padding: 24px;
width: calc(100% - var(--sidebar-width));
box-sizing: border-box;
}
.stats-grid {
display: grid;
grid-template-columns: 1fr;
gap: 10px;
}
.stat-card {
background: rgba(255,255,255,0.1);
padding: 10px;
border-radius: 6px;
text-align: center;
}
.stat-value {
font-size: 1.2em;
font-weight: 600;
color: var(--accent-color);
}
.stat-label {
font-size: 0.8em;
color: #bdc3c7;
}
.card {
background: white;
padding: 16px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.chart-card {
background: white;
padding: 16px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
height: 420px;
display: flex;
flex-direction: column;
}
.chart-card .dash-graph {
flex: 1;
}
.table-container {
background: white;
padding: 12px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.nav-links {
list-style: none;
padding: 0;
margin: 0;
}
.nav-links li a {
display: block;
padding: 8px;
color: #bdc3c7;
text-decoration: none;
border-radius: 4px;
}
.nav-links li a:hover {
background: rgba(255,255,255,0.1);
color: white;
}
/* Custom Table Styles */
.custom-table-wrapper {
overflow-x: auto;
overflow-y: auto;
max-height: 520px;
background: #fff;
border: 1px solid #eee;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.custom-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed;
}
.custom-table thead th {
text-align: left;
border-bottom: 2px solid var(--border-color);
padding: 10px;
}
.custom-table tbody td {
padding: 8px 10px;
border-bottom: 1px solid #eee;
vertical-align: middle;
}
.custom-table tbody tr:hover {
background: #fafafa;
transition: background 0.2s ease;
}
.custom-table tbody tr:nth-child(even) { background: #fcfcfc; }
.custom-table thead th {
position: sticky;
top: 0;
background: #fff;
z-index: 1;
}
.cnum { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; text-align: right; }
.is-max { font-weight: 600; color: var(--accent-color); }
.crow-gold { background: rgba(255,215,0,0.12); }
.crow-silver { background: rgba(192,192,192,0.12); }
.crow-bronze { background: rgba(205,127,50,0.12); }
.crank { width: 56px; text-align: center; }
.calgo { font-weight: 500; }
.cth { background: var(--background-color); }
.cfeat { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* In-cell Data Bars */
.bar-cell {
position: relative;
height: 26px;
display: flex;
align-items: center;
justify-content: flex-end;
}
.bar-track {
position: absolute;
left: 6px;
right: 6px;
height: 60%;
background: #f4f7fb;
border: 1px solid #e6eef7;
border-radius: 6px;
overflow: hidden;
}
.bar-fill {
height: 100%;
background: linear-gradient(90deg, #7db9e8 0%, #3498db 100%);
opacity: 0.35;
transition: width 200ms ease;
}
.bar-text {
position: relative;
z-index: 1;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
padding: 0 6px;
line-height: 1;
}
"""
dash_app.index_string = f"""
<!DOCTYPE html>
<html>
<head>
{{%metas%}}
<title>AutoFS Leaderboard</title>
{{%favicon%}}
{{%css%}}
<style>{css}</style>
</head>
<body>
{{%app_entry%}}
<footer>
{{%config%}}
{{%scripts%}}
{{%renderer%}}
</footer>
</body>
</html>
"""
dash_app.layout = dmc.MantineProvider(
children=html.Div(
className="app-shell",
children=[
html.Aside(
className="sidebar",
children=[
html.Div(
[
html.H1("AutoFS", style={"fontSize": "1.5em", "margin": 0, "color": "white"}),
html.Div("Feature Selection Leaderboard", style={"fontSize": "0.8em", "color": "#bdc3c7"}),
],
style={"textAlign": "center", "marginBottom": "10px"},
),
html.Div(
className="stats-grid",
children=[
html.Div([html.Div("-", id="stat-count", className="stat-value"), html.Div("Methods", className="stat-label")], className="stat-card"),
html.Div([html.Div("-", id="stat-best", className="stat-value"), html.Div("Best F1", className="stat-label")], className="stat-card"),
html.Div([html.Div("-", id="stat-updated", className="stat-value"), html.Div("Updated", className="stat-label")], className="stat-card"),
],
),
html.Div(
[
html.H2("Navigation"),
html.Ul(
className="nav-links",
children=[
html.Li(html.A("π Overview", href="#overview")),
html.Li(html.A("π Leaderboard", href="#main-table")),
html.Li(html.A("π Charts", href="#charts")),
html.Li(html.A("βΉοΈ Details", href="#details")),
html.Li(html.A("π Global Rankings", href="/global")),
html.Li(html.A("π€ Submit Data/Method", href="/submit")),
],
),
]
),
html.Div(
[
html.H2("Global Controls"),
dmc.Select(
id="view-mode",
data=[
{"label": "Overall (Mean)", "value": "overall"},
{"label": "F1 by Classifier", "value": "classifiers-f1"},
{"label": "AUC by Classifier", "value": "classifiers-auc"},
],
value="overall",
clearable=False,
style={"marginBottom": "10px"},
),
]
),
html.Div(
[
html.H2("Filters"),
dmc.Select(
id="dataset-select",
data=dataset_options,
value="Authorship",
clearable=False,
style={"marginBottom": "10px"},
),
html.Div(
[
html.Div(
[
html.Span("Min F1 Score: "),
html.Span("0.0000", id="val-f1", style={"color": "var(--accent-color)"}),
],
style={"marginBottom": "6px", "color": "#bdc3c7"},
),
dmc.Slider(id="filter-f1", min=0, max=1, step=0.0001, value=0),
],
style={"marginBottom": "12px"},
),
html.Div(
[
html.Div(
[
html.Span("Del. Rate: "),
html.Span("0% - 100%", id="val-del-rate", style={"color": "var(--accent-color)"}),
],
style={"marginBottom": "6px", "color": "#bdc3c7"},
),
dmc.RangeSlider(id="filter-del-rate", min=0, max=100, value=[0, 100], step=1),
],
style={"marginBottom": "12px"},
),
html.Div(
[
html.Div(
[
html.Span("Max Features: "),
html.Span("All", id="val-feats", style={"color": "var(--accent-color)"}),
],
style={"marginBottom": "6px", "color": "#bdc3c7"},
),
dmc.Slider(id="filter-feats", min=1, max=100, step=1, value=100),
],
style={"marginBottom": "12px"},
),
dmc.Select(
id="filter-complexity",
data=complexity_data,
value="all",
clearable=False,
style={"marginBottom": "12px"},
),
dmc.CheckboxGroup(id="filter-algos", children=[], value=[], orientation="vertical"),
]
),
],
),
html.Main(
className="main-content",
children=[
html.Header(
[
html.H1("π Leaderboard Dashboard", style={"color": "var(--secondary-color)", "margin": 0}),
html.Div("Comprehensive benchmark of feature selection algorithms across diverse datasets.", className="subtitle"),
]
),
html.Div(
className="card",
children=[
html.P([
"Feature selection is a critical step in machine learning and data analysis, aimed at ",
html.Strong("identifying the most relevant subset of features"),
" from a high-dimensional dataset. By eliminating irrelevant or redundant features, feature selection not only ",
html.Strong("improves model interpretability"),
" but also ",
html.Strong("enhances predictive performance"),
" and ",
html.Strong("reduces computational cost"),
".",
]),
html.P([
"This leaderboard presents a comprehensive comparison of various feature selection algorithms across multiple benchmark datasets. It includes several ",
html.Strong("information-theoretic and mutual information-based methods"),
", which quantify the statistical dependency between features and the target variable to rank feature relevance. Mutual information approaches are particularly effective in ",
html.Strong("capturing both linear and non-linear relationships"),
", making them suitable for complex datasets where classical correlation-based methods may fail.",
]),
html.P([
"The leaderboard is structured to reflect algorithm performance across different datasets, allowing for an objective assessment of each methodβs ability to select informative features. For each method and dataset combination, metrics such as ",
html.Strong("classification accuracy, F1-score, and area under the ROC curve (AUC)"),
" are reported, providing insights into how the selected features contribute to predictive modeling.",
]),
html.P([
"By examining this feature selection leaderboard, researchers and practitioners can gain a better understanding of which methods perform consistently well across diverse domains, helping to guide the choice of feature selection strategies in real-world applications. This serves as a valuable resource for both benchmarking and method development in the field of feature selection.",
]),
],
style={"marginTop": "16px"},
),
dmc.Grid(
id="overview",
gutter="md",
style={"marginTop": "16px"},
children=[
dmc.Col(
span=12,
md=6,
children=html.Div(
className="card",
children=[
html.H3("About This Dataset"),
html.P(["Analyzing performance on ", html.Strong(html.Span("Selected", id="desc-dataset-name")), "."]),
],
),
),
dmc.Col(
span=12,
md=6,
children=html.Div(
className="card",
children=[
html.H3("Dataset Metadata"),
html.Div(["Name: ", html.Span("-", id="meta-name")]),
html.Div(["Samples: ", html.Span("-", id="meta-samples"), " | Features: ", html.Span("-", id="meta-features")]),
html.Div(["Last Updated: ", html.Span("-", id="meta-updated")]),
],
),
),
],
),
html.Div(
id="main-table",
style={"marginTop": "24px"},
children=[
html.H3("π Detailed Rankings"),
html.Div(id="custom-table-container", className="custom-table-wrapper"),
],
),
html.Div(
id="charts",
style={"marginTop": "24px"},
children=[
dmc.Grid(
gutter="md",
children=[
dmc.Col(
span=12,
md=6,
children=html.Div(
className="chart-card",
children=[
html.H3("π Performance Comparison"),
dcc.Graph(id="score-graph", config={"responsive": True}, style={"height": "100%"}),
],
),
),
dmc.Col(
span=12,
md=6,
children=html.Div(
className="chart-card",
children=[
html.H3("π Pareto Frontier (Trade-off)"),
html.Div("X: Selected Features vs Y: F1 Score (Top-Left is better)", style={"fontSize": "0.9em", "color": "#666"}),
dcc.Graph(id="pareto-graph", config={"responsive": True}, style={"height": "100%"}),
],
),
),
],
)
],
),
html.Div(
id="details",
style={"marginTop": "50px", "color": "#999", "textAlign": "center", "borderTop": "1px solid #eee", "paddingTop": "20px"},
children="AutoFS Benchmark Platform Β© 2026",
),
],
),
],
)
)
@dash_app.callback(
Output("filter-feats", "max"),
Output("filter-feats", "value"),
Output("filter-f1", "min"),
Output("filter-f1", "max"),
Output("filter-f1", "value"),
Output("filter-algos", "children"),
Output("filter-algos", "value"),
Output("meta-name", "children"),
Output("meta-samples", "children"),
Output("meta-features", "children"),
Output("meta-updated", "children"),
Output("desc-dataset-name", "children"),
Output("stat-updated", "children"),
Output("stat-count", "children"),
Output("stat-best", "children"),
Output("score-graph", "figure"),
Output("pareto-graph", "figure"),
Output("custom-table-container", "children"),
Output("val-f1", "children"),
Output("val-feats", "children"),
Output("val-del-rate", "children"),
Input("dataset-select", "value"),
Input("view-mode", "value"),
Input("filter-f1", "value"),
Input("filter-feats", "value"),
Input("filter-del-rate", "value"),
Input("filter-complexity", "value"),
Input("filter-algos", "value"),
State("filter-f1", "min"),
State("filter-f1", "max"),
State("filter-feats", "max"),
State("filter-algos", "children"),
State("filter-algos", "value"),
)
def update_dashboard_all(
dataset,
view_mode,
min_f1_value,
max_features_value,
del_range,
complexity,
selected_algos,
f1_min_state,
f1_max_state,
feats_max_state,
algo_children_state,
algo_value_state,
):
triggered_id = callback_context.triggered_id if callback_context.triggered else None
dataset_changed = triggered_id == "dataset-select" or triggered_id is None
selected = dataset or "Authorship"
meta = DATASET_METADATA.get(selected, {"name": selected, "last_updated": "-", "num_samples": None, "total_features": None})
results = get_results_for_dataset(selected)
algo_list = sorted({r.get("algorithm") for r in results if r.get("algorithm")})
if dataset_changed:
f1_scores = [r.get("mean_f1") for r in results if r.get("mean_f1") is not None]
if f1_scores:
min_f1 = min(f1_scores)
safe_min = max(0, math.floor((min_f1 - 0.1) * 10) / 10)
else:
safe_min = 0
max_feats = meta.get("total_features") or 100
f1_min = safe_min
f1_max = 1
f1_value = safe_min
feats_max = max_feats
feats_value = max_feats
algo_children = [dmc.Checkbox(label=a, value=a) for a in algo_list]
algo_value = algo_list
else:
f1_min = f1_min_state if f1_min_state is not None else 0
f1_max = f1_max_state if f1_max_state is not None else 1
f1_value = min_f1_value if min_f1_value is not None else f1_min
feats_max = feats_max_state if feats_max_state is not None else (meta.get("total_features") or 100)
feats_value = max_features_value if max_features_value is not None else feats_max
if algo_children_state:
algo_children = algo_children_state
else:
algo_children = [dmc.Checkbox(label=a, value=a) for a in algo_list]
if selected_algos is not None:
algo_value = selected_algos
else:
algo_value = algo_value_state if algo_value_state is not None else algo_list
filtered = apply_filters(results, meta, f1_value or 0, feats_value, del_range, complexity, algo_value or [])
count = len(filtered)
if filtered:
best = max(filtered, key=lambda r: r.get("mean_f1") or 0)
best_text = f"{best.get('algorithm')} ({(best.get('mean_f1') or 0):.3f})"
else:
best_text = "-"
score_fig = build_score_figure(filtered, view_mode or "overall")
pareto_fig = build_pareto_figure(filtered)
table_component = build_table(filtered, view_mode or "overall")
val_f1 = f"{(f1_value or 0):.4f}"
val_feats = str(int(feats_value)) if isinstance(feats_value, (int, float)) else "All"
del_min = del_range[0] if del_range else 0
del_max = del_range[1] if del_range else 100
val_del = f"{del_min:.0f}% - {del_max:.0f}%"
meta_samples = meta.get("num_samples") if meta.get("num_samples") is not None else "Unavailable"
meta_features = meta.get("total_features") if meta.get("total_features") is not None else "Unavailable"
return (
feats_max,
feats_value,
f1_min,
f1_max,
f1_value,
algo_children,
algo_value,
meta.get("name", "-"),
meta_samples,
meta_features,
meta.get("last_updated", "-"),
meta.get("name", "-"),
meta.get("last_updated", "-"),
count,
best_text,
score_fig,
pareto_fig,
table_component,
val_f1,
val_feats,
val_del,
)
def sanitize_json(value):
if value is None or isinstance(value, (str, int, float, bool)):
return value
if np and isinstance(value, np.generic):
return value.item()
if np and isinstance(value, np.ndarray):
return value.tolist()
if pd and isinstance(value, (pd.DataFrame, pd.Series)):
if isinstance(value, pd.DataFrame):
return value.to_dict(orient="records")
return value.to_dict()
if isinstance(value, (datetime.datetime, datetime.date)):
return value.isoformat()
if isinstance(value, dict):
return {str(k): sanitize_json(v) for k, v in value.items()}
if isinstance(value, (list, tuple, set)):
return [sanitize_json(v) for v in value]
if hasattr(value, "to_dict"):
return sanitize_json(value.to_dict())
return str(value)
@server.route("/global")
def global_view():
return render_template("global.html")
@server.route("/submit")
def submit_view():
return render_template("submit.html")
@server.route("/api/results")
def get_results_api():
try:
dataset = request.args.get("dataset") or "Authorship"
leaderboard = get_results_for_dataset(dataset)
return jsonify(sanitize_json(leaderboard))
except Exception as e:
print(e)
return jsonify({"error": str(e)})
@server.route("/api/datasets")
def api_datasets():
try:
datasets = []
for name, meta in DATASET_METADATA.items():
datasets.append({
"name": name,
"last_updated": meta.get("last_updated"),
"num_samples": meta.get("num_samples") if meta.get("num_samples") is not None else "Unavailable",
"total_features": meta.get("total_features") if meta.get("total_features") is not None else "Unavailable",
})
return jsonify(sanitize_json(datasets))
except Exception as e:
print(e)
return jsonify({"error": str(e)})
@server.route("/api/global_stats")
def api_global_stats():
try:
algo_totals = {}
algo_counts = {}
for dataset in DATASET_METADATA.keys():
results = get_results_for_dataset(dataset) or []
for row in results:
algo = row.get("algorithm") or "Unknown"
mean_f1 = row.get("mean_f1")
mean_auc = row.get("mean_auc")
if mean_f1 is None and mean_auc is None:
continue
totals = algo_totals.get(algo, {"f1": 0.0, "auc": 0.0})
counts = algo_counts.get(algo, {"f1": 0, "auc": 0})
if mean_f1 is not None:
totals["f1"] += float(mean_f1)
counts["f1"] += 1
if mean_auc is not None:
totals["auc"] += float(mean_auc)
counts["auc"] += 1
algo_totals[algo] = totals
algo_counts[algo] = counts
global_stats = []
for algo, totals in algo_totals.items():
counts = algo_counts.get(algo, {"f1": 0, "auc": 0})
mean_f1_global = totals["f1"] / counts["f1"] if counts["f1"] else None
mean_auc_global = totals["auc"] / counts["auc"] if counts["auc"] else None
global_stats.append({
"algorithm": algo,
"mean_f1_global": mean_f1_global,
"mean_auc_global": mean_auc_global,
})
return jsonify(sanitize_json(global_stats))
except Exception as e:
print(e)
return jsonify({"error": str(e)})
@server.route("/api/algos")
def api_algorithms():
return jsonify(DISPLAY_COMPLEXITY)
@server.route("/pdfs/<path:filename>")
def serve_pdf(filename):
return send_from_directory(PDF_DIR, filename)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 7860))
print(f"Loaded {len(DATASET_METADATA)} datasets from {RESULT_DIR}")
app.run(host="0.0.0.0", port=port, debug=False)
|