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 tests/test_api_datasets.py from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_api_datasets.py
- Command line
-
hf download hf://Zipeng365/WISP/tests/test_api_datasets.py
-
curl -L -o test_api_datasets.py https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_api_datasets.py
2.82 kB
| """wisp.datasets: make_windows rules and reading exported folds.""" | |
| import os | |
| import numpy as np | |
| import pytest | |
| from numpy.testing import assert_array_equal | |
| from conftest import frozen_root, requires_frozen | |
| from wisp.datasets import load_exported_fold, load_wristharbench, make_windows | |
| def test_window_count_and_time_index(): | |
| sig = np.arange(1000, dtype=float).reshape(-1, 2) # 500 samples, 2 channels | |
| X, y, g, t = make_windows(sig, fs=50, window_s=2.0, step_s=1.0) | |
| assert X.shape == (9, 100, 2) and y is None | |
| assert_array_equal(t, np.arange(9) * 1.0) | |
| assert_array_equal(X[1, 0], sig[50]) | |
| with pytest.raises(ValueError): | |
| make_windows(sig, fs=50, window_s=None, step_s=1.0) | |
| def test_majority_rule_and_fraction(): | |
| labels = np.array(["a"] * 90 + ["b"] * 10 + ["b"] * 100) | |
| X, y, g, t = make_windows(np.zeros(200), fs=10, window_s=10, step_s=10, labels=labels) | |
| assert list(y) == ["a", "b"] | |
| X, y, g, t = make_windows(np.zeros(200), fs=10, window_s=10, step_s=10, labels=labels, min_label_fraction=0.95) | |
| assert list(y) == ["b"] and list(t) == [10.0] | |
| lab = np.r_[np.full(50, np.nan), np.ones(50)] | |
| _, y, _, _ = make_windows(np.zeros(100), fs=10, window_s=10, step_s=10, labels=lab) | |
| assert list(y) == [1.0] # missing annotations do not count against the fraction | |
| def test_constant_rule_and_group_boundaries(): | |
| labels = np.r_[np.zeros(60), np.ones(60)] | |
| groups = np.r_[np.full(50, 7), np.full(70, 8)] | |
| X, y, g, t = make_windows(np.zeros(120), fs=1, window_s=20, step_s=10, labels=labels, group=groups, | |
| label_rule="constant") | |
| # windows never cross the group change at 50 or mix labels across 60 | |
| for start, gid, lab in zip(t.astype(int), g, y): | |
| assert (groups[start:start + 20] == gid).all() and (labels[start:start + 20] == lab).all() | |
| assert set(g) == {7, 8} and len(y) == 9 | |
| def test_load_exported_fold_adl(): | |
| data = load_exported_fold(frozen_root(), "adl", 0) | |
| assert (len(data.train), len(data.val), len(data.test)) == (3035, 446, 861) | |
| assert len(data.label_names) == 14 and data.train.X.shape[1:] == (160, 3) | |
| assert not set(data.train.groups) & set(data.test.groups) | |
| def test_load_wristharbench_adl(tmp_path): | |
| data = load_wristharbench("adl", fold=0, cache_dir=os.environ.get("WISP_TEST_HUB_CACHE", tmp_path)) | |
| assert (len(data.train), len(data.val), len(data.test)) == (3035, 446, 861) | |
| assert len(data.label_names) == 14 | |
| root = frozen_root() | |
| if root is not None: | |
| frozen = load_exported_fold(root, "adl", 0) | |
| assert_array_equal(data.test.X, frozen.test.X) | |
| assert_array_equal(data.test.y, frozen.test.y) | |