Scikit-learn
human-activity-recognition
wearable
wrist
time-series
cpu
scikit-learn
WISP / src /wisp_fast /funnel /selection.py
Zipeng365's picture
wisp-har 0.4.0: WISP-Funnel search and the adaptive HMM switch (default decoder)
93a9282 verified
Raw History Blame Contribute Delete
1.21 kB
"""Split checks and the fit call shared by verification and refits."""
import numpy as np
def check_splits(*parts):
"""Require sequence metadata, one global vocabulary and disjoint group IDs."""
first = parts[0]
if not first.label_names:
raise ValueError("Supply the ordered global label_names")
seen = set()
for data in parts:
if data.label_names != first.label_names or data.X.shape[1:] != first.X.shape[1:]:
raise ValueError("Split vocabularies and time/channel shapes must match")
if data.subject is None or data.time_index is None or not len(data.y):
raise ValueError("Every split needs nonempty windows, subject and time_index")
if np.min(data.y) < 0 or np.max(data.y) >= len(first.label_names):
raise ValueError("Class ID outside supplied global vocabulary")
groups = set(np.asarray(data.subject).astype(str))
if groups & seen:
raise ValueError("Participant/sequence groups overlap between splits")
seen |= groups
def fit_on(model, data):
return model.fit(data.X, data.y, groups=data.subject, time_index=data.time_index,
n_classes=data.n_classes)