File size: 1,782 Bytes
3f30783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Load a block-sweep checkpoint and classify a table with TabLoop's scikit-learn wrapper.

    git clone https://github.com/tejasvaidhyadev/Tabloop && git -C Tabloop checkout 8830f27
    PYTHONPATH=Tabloop python example.py --run loop_4x3 --loops 3
    PYTHONPATH=Tabloop python example.py --run base_12x1                    # untied models: loops = 1
    PYTHONPATH=Tabloop python example.py --run loop_4x6 --loops 8 --step 100000

Looped n x k models can be read at any depth k (applications = n * k); untied models run once (k = 1).
"""
import argparse
from huggingface_hub import hf_hub_download
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import accuracy_score, roc_auc_score
from sklearn.model_selection import train_test_split
from tabloop.evaluation.classifier import TabLoopClassifier

FINAL = {"ctrl_1x1": 311100, "ctrl_2x1": 296200, "ctrl_3x1": 282600, "ctrl_4x1": 270200, "ctrl_6x1": 248400}
ap = argparse.ArgumentParser()
ap.add_argument("--run", default="loop_4x3")
ap.add_argument("--step", type=int, default=None, help="default: the run's final step")
ap.add_argument("--loops", type=int, default=None, help="test-time depth k (default: the run's training-mean k)")
ap.add_argument("--repo", default="tejasvaidhya/tabloop-block-sweep-small")
a = ap.parse_args()
step = a.step or FINAL.get(a.run, 200000)
path = hf_hub_download(a.repo, f"checkpoints/{a.run}/step-{step:06d}.ckpt")
clf = TabLoopClassifier.from_checkpoint(path, loops=a.loops)
X, y = load_breast_cancer(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.3, random_state=0, stratify=y)
p = clf.fit(Xtr, ytr).predict_proba(Xte)[:, 1]
print(f"{a.run} step {step} k={clf.loops}: accuracy {accuracy_score(yte, p > 0.5):.4f}  AUC {roc_auc_score(yte, p):.4f}")