Instructions to use Zipeng365/WISP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Zipeng365/WISP with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Zipeng365/WISP", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download examples/01_benchmark_quickstart.py from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/examples/01_benchmark_quickstart.py
- Command line
-
hf download hf://Zipeng365/WISP/examples/01_benchmark_quickstart.py
-
curl -L -o 01_benchmark_quickstart.py https://huggingface.co/Zipeng365/WISP/resolve/main/examples/01_benchmark_quickstart.py
2.44 kB
| """Fit WISP-CIS on one WristHARBench fold and score the test split (paper protocol). | |
| pip install "wisp-har[hub]" # once, for the dataset download | |
| python examples/01_benchmark_quickstart.py [--dataset adl] [--fold 0] [--seed 42] | |
| [--exported <root of exported folds>] | |
| The first call exports the fold from the Hugging Face dataset into a local cache. | |
| With --exported, an already exported fold (<root>/<dataset_id>/fold<k>/*.npz) is read. | |
| With speed="exact" (default) and decoder="recipe" (the recipe's own decoder, as in the | |
| paper) the decoded labels equal the paper code, so for a catalog recipe and one of the paper | |
| seeds (42, 43, 44) the printed metrics can be compared with results/run_results.csv (see the | |
| last lines of the output). | |
| """ | |
| import argparse | |
| import csv | |
| from pathlib import Path | |
| import wisp | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--dataset", default="adl") | |
| ap.add_argument("--fold", type=int, default=0) | |
| ap.add_argument("--seed", type=int, default=42) | |
| ap.add_argument("--recipe", default="cis") | |
| ap.add_argument("--exported", default=None) | |
| a = ap.parse_args() | |
| d = (wisp.datasets.load_exported_fold(a.exported, a.dataset, a.fold) if a.exported | |
| else wisp.datasets.load_wristharbench(a.dataset, fold=a.fold)) | |
| fit = d.train_val # fit on train+validation | |
| clf = wisp.WISPClassifier(a.recipe, decoder="recipe", classes=d.classes, random_state=a.seed) # paper decoder | |
| clf.fit(fit.X, fit.y, groups=fit.groups, time_index=fit.time_index) | |
| pred = clf.predict(d.test.X, groups=d.test.groups, time_index=d.test.time_index) | |
| scores = wisp.metrics.score(d.test.y, pred, len(d.label_names)) | |
| print({k: round(scores[k], 6) for k in ("macro_f1", "accuracy", "balanced_accuracy", "worst_class_f1")}) | |
| print(f"fit {clf.fit_seconds_:.1f} s, paper-backed configuration: {clf.has_paper_results_}") | |
| saved = Path(__file__).resolve().parents[1] / "results" / "run_results.csv" | |
| method = clf.recipe_.provenance.get("method_id") | |
| if saved.exists() and method: | |
| for row in csv.DictReader(saved.open()): | |
| if (row["dataset_id"], row["method_id"], int(row["fold"]), int(row["model_seed"])) == \ | |
| (d.dataset_id, method, a.fold, a.seed): | |
| print("saved result (results/run_results.csv):", | |
| {k: round(float(row[k]), 6) for k in ("macro_f1", "accuracy", "balanced_accuracy", "worst_class_f1")}) | |